<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Fsegredo on Medium]]></title>
        <description><![CDATA[Stories by Fsegredo on Medium]]></description>
        <link>https://medium.com/@fsegredo2000?source=rss-7116e92c10a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qa3wBZO7og7tNMSZgs-bbQ.jpeg</url>
            <title>Stories by Fsegredo on Medium</title>
            <link>https://medium.com/@fsegredo2000?source=rss-7116e92c10a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 07:03:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fsegredo2000/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Leverage OCI Registry with Helm]]></title>
            <link>https://medium.com/@fsegredo2000/leverage-oci-registry-with-helm-5eea92fab0a1?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5eea92fab0a1</guid>
            <category><![CDATA[helm-chart]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[registry]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Fri, 05 Jan 2024 23:30:17 GMT</pubDate>
            <atom:updated>2024-01-05T23:32:32.360Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*tRhvZ6zYsYWKT9swjUPAgQ.jpeg" /></figure><p><strong>Agenda</strong></p><ul><li>OCI registry to publish Helms</li><li>BONUS: ArgoCD + Oci Registry</li></ul><p>In this article, we will learn about how to use OCI-Based Registries in Helm versions ≥ 3.8.0.</p><blockquote>The <strong>Open Container Initiative (OCI) </strong>is an open governance structure for the express purpose of creating open industry standards around container formats and runtimes. — The Linux Foundation</blockquote><p>Combining Helm with an OCI registry offers several advantages for handling and deploying containerized applications in Kubernetes environments;</p><ul><li>The first aspect is <strong>standardization</strong>, as it implicitly establishes a standard for helm packing and distribution.</li><li><strong>Versioning </strong>and <strong>Rollbacks </strong>— By combining both, you can easily manage and keep track of different versions of charts. You can also rollback to previous versions, audit changes, and have a clear record of your releases.</li><li><strong>Centralization </strong>— Keeping both images and helms in the same registry</li></ul><p>Here are some places where you can share your helm charts that have OCI support.</p><ul><li>AWS ECR</li><li>Azure Container Registry</li><li><strong>Docker Hub</strong></li><li>Google Artifact Registry</li><li>Harbor</li><li>Artifactory</li></ul><p>To simplify this article, we will be using DockerHub as our main registry.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/24/1*5g-xiBLbwN3IlRDV4n_Lxw.png" /></figure><p><strong>A few things to keep in mind when using OCI base registries…</strong></p><ul><li>If your registry has authentication in place, it will follow the same logic as the Docker registry.</li></ul><pre>helm registry login -u YOURUSER REGISTRYADDRESS<br><br>helm registry logout REGISTRYADDRESS</pre><ul><li>When utilizing the helm push command the registry address must be prefixed with <strong>oci://</strong>, registry address only (without including chart names nor versions ):</li></ul><pre>helm push YOURCHART-VERSION.tgz oci//registry-1.docker.io/yourHubspace</pre><ul><li>The Command helm repo add is not compatible with OCI registries, therefore, in order to install/upgrade it is necessary to specify the registry address.</li></ul><pre>helm install CHARTNAME oci://registry-1.docker.io/yourHubSpace/CHARTNAME - version 1.0.0</pre><p><strong>Practical Example</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*MhI01lYVIHiZs9vrT_L72Q.png" /></figure><p>We’re going to start with the usual procedure, and pack the helm folder strucure</p><pre>helm package /home/opc/mychart/</pre><pre>mychart/<br>├─ templates/<br>values.yaml<br>Chart.yaml<br>.helmignore</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*n5c-LrflE0LUM73Nqj_U5A.png" /></figure><p>Login into your registry</p><pre>helm registry login -u youruser registry-1.docker.io</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*TKoVZsMGpkjNyV6Kt4bMAw.png" /></figure><p>Next step is to push the helm we just packed to the oci registry</p><pre>helm push example-app-1.0.0.tgz oci://registry-1.docker.io/fabiosegredo</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*gsCrAy_xn8c31OFCVua92w.png" /></figure><p>Now listing my dockerHub registry, we can verify that he helm was pushed sucessfully, comparing with a container image the only visible difference would be the the type/contains showing Helm instead of image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*ZEsTgk78zbudftXxbRdCCg.png" /></figure><p>Helm chart was pushed and is now available to install or upgrade, let’s do that</p><pre>helm install example oci://registry-1.docker.io/fabiosegredo/example-app - version 1.0.0</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*NXLLcGJ0vdzM_HWTKUnHwA.png" /></figure><p>Let’s verify if everything is ok by listing the helms installed and the resources installed by the it.</p><pre>helm list<br><br>k get all -n teste</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gMpPR0GN1NSx7_7heviRTw.png" /><figcaption>helm list</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*mJtap2BJu3nLlxvvr9mX5g.png" /><figcaption>kubectl get all -n teste</figcaption></figure><p>Verifing the OCI chart Manifest with skopeo</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*wHJGugpcSBki1mMH3YDnBg.png" /></figure><pre>skopeo inspect  --raw docker://docker.io/fabiosegredo/example-app:1.0.0 | jq -r</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/887/1*zQaRHAEj40HAagBFnukCKg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/1*ecqYxMx51yYfcsXGwBj90A.png" /></figure><p>As a Bonus we’ll use ArgoCD and OCI registry and see how it goes.</p><p>First, we will create a secret containing all the necessary information about the registry.</p><pre>apiVersion: v1<br>kind: Secret<br>metadata:<br>  name: my-oci-repo-creds<br>  namespace: argocd<br>  labels:<br>    argocd.argoproj.io/secret-type: repository<br>data:<br>  enableOCI: true<br>  name: teste<br>  password: (Registry password)<br>  project: Default<br>  type: Helm<br>  url: (REGISTRY URL) #example:registry-1.docker.io/fabiosegredo<br>  username: (Registry User)</pre><p>After ensuring that all necessary settings are made (Keep in mind it’s a Secret you’ll need to base64 the values). Once the manifest is applied, we can verify the connection status via ArgoCD UI or CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*htlPo8M8hW6VoN_UO2BUIg.png" /></figure><p>and finally we apply the application for the previously pushed helm (example-app version 1.0.0)</p><p>The Application is then applied with the Helm we previously created!</p><pre>apiVersion: argoproj.io/v1alpha1<br>metadata:<br>  name: my-helm-chart<br>  namespace: argocd<br>kind: Application<br>spec:<br>  project: default<br>  source:<br>    repoURL: registry-1.docker.io/fabiosegredo<br>    targetRevision: 1.0.0<br>    chart: example-app<br>    helm:<br>      passCredentials: false<br>  destination:<br>    server: https://kubernetes.default.svc<br>    namespace: argo-testing<br>  syncPolicy:<br>    automated:<br>      selfHeal: true<br>      prune: true<br>      allowEmpty: true<br>    syncOptions:<br>    - CreateNamespace=true</pre><p>Back to the UI to check the status of the application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vJib_Q85Cd9rDsTWcEdA8w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*ySpMdgvR2_ozijERoCNdNQ.png" /></figure><p>And there you have it, a simple and basic demonstration of how to use OCI registries for your chats.</p><p>Happy Helming!!</p><p>If this post was helpful, please click the clap 👏 button below a few times👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eea92fab0a1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K8s — PVC|PV Terminating State]]></title>
            <link>https://medium.com/@fsegredo2000/k8s-pvc-pv-terminating-state-9f88915ef93f?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f88915ef93f</guid>
            <category><![CDATA[kubernetes-storage]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[persistent-volume]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Thu, 19 Oct 2023 19:16:58 GMT</pubDate>
            <atom:updated>2023-10-19T19:16:58.123Z</atom:updated>
            <content:encoded><![CDATA[<h3>K8s — PVC|PV Terminating State</h3><p>In this article, we will discuss the never-ending terminating state in persistent volumes and persistent volume claims, which at some point we encounter or manage to put ourselves in that situation at least once.</p><blockquote><em>How does this happen</em>?</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*1v5KK3bK_OOcJTBQ6JsFFg.png" /></figure><p>The resource will be in a terminating state in the following scenarios.</p><ul><li>PV Stuck in Terminating state after deletion, when you delete the PV before deleting the Bounded PVC</li><li>PVC Stuck in Terminating state after deletion, when you delete the PVC and you still have pods running (pods attached to the pvc)</li></ul><p>Essentially, Kubernetes employs a protection feature to ensure that PVCs that are currently in active use and PVs that are bound to PVCs are not removed from the system, as it is possible to experience data loss.</p><p>This safeguarding feature is accomplished by Finalizers, which are namespaced keys that instruct Kubernetes to wait until specific conditions are met before fully deleting resources marked for deletion.</p><p>In our case, a Finalizer is attached to our resource every time we create a PVC or PV.</p><ul><li>Finalizer [kubernetes.io/pv-protection] -&gt; when creating a PV</li><li>Finalizer [kubernetes.io/pvc-protection] -&gt; when creating a PVC</li></ul><p><strong>Terminating State</strong></p><p>Terminating State in this cases means that the deletion of the PVC and or PV will be postponed untill they are not being used by a pod or bound to a Pvc.</p><p>We’re going to create a PVC and a simple application, so we can verify the finalizers and how can we simulate the Terminating state and how to fix it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0e18328f4cfcdb9601452cbaead7d0c2/href">https://medium.com/media/0e18328f4cfcdb9601452cbaead7d0c2/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bb54ab97b05e33b7cfc86cf7fce6e7c3/href">https://medium.com/media/bb54ab97b05e33b7cfc86cf7fce6e7c3/href</a></iframe><p>Let’s verify we have everything up and running:</p><pre> kubectl get pvc --field-selector metadata.name=example-claim</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*03eyhwyCwB87aU_EwRqtHQ.png" /></figure><pre>kubectl get pv | grep -w &quot;default/example-claim&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hptGaIK9Ln63gk6RO-3Zaw.png" /></figure><pre># claims associated with pod<br>kubectl get pods -o custom-columns=POD:.metadata.name,PVC:.spec.volumes[*].persistentVolumeClaim.claimName</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouvORcSxYbrbkSU6jHDdbg.png" /></figure><p>We have all the information to connect the resources</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*TRVUhDW9wbRbC0Sj-VI0VQ.png" /></figure><p>Before we simulate the terminating state, let’s verify that out PVC and PV have the annotation Finalizer, that we’ve mentioned earlier.</p><pre>#Looking for finalizer pv-protection<br>kubectl get pv pvc-b05c6e74-89b4-4669-8e00-5036f109a487 -o json | jq .metadata.finalizers</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*Gqn5pOEuriqTyjYfGaEV6Q.png" /></figure><pre>#Looking for finalizer pv-protection<br> kubectl get pvc example-claim -o json | jq .metadata.finalizers</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*in5gRGKQS83_StwM_1f_vg.png" /></figure><p>The finalizers protections are in place!</p><p>Let’s simulate the Terminating states:</p><p>As we mentioned before we’ll get our PV in Terminating mode if we delete it while it’s bounded to a pvc. let’s do that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*kNWonaJiVTg5OQYhCaiFww.png" /></figure><pre>kubectl delete pv pvc-b05c6e74-89b4-4669-8e00-5036f109a487</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/799/1*Dc1kjh0-t9hDE-DfCV0Xsw.png" /></figure><p>Let’s now verify the resource state:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*foZ-GkVbn1VwM8v6ITd3vA.png" /></figure><p>As we can see it’s already in Terminating status because we tried to delete a PV that is still bounded to a PVC.</p><p>Solution here would be to delete the PVC aswell, let’s do that:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*cpaqNKsJGBZ07OUI1z0q7A.png" /></figure><pre>kubectl delete pvc example-claim</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*9IzVMoWVFU5AdSkXDRPwUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_Sy-IVCXT6JDG0-vENr5gA.png" /></figure><p>Annndd, you we got ourselves in a Terminating status again, this time with the pvc. Why so?</p><p>Because we still have active pods using the PVC so the PVC won’t be deleted either.</p><p>What now?</p><p>We need to delete the Pods using the PVC, and we’ve seen before that we have one pod name ‘example-deploy-75bcc94c6d-fftq2’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/821/1*Ow8XEKam9fFvsrRTOleoxw.png" /></figure><pre>kubectl delete pod example-deploy-75bcc94c6d-fftq2<br>or<br>kubectl delete deployment example-deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*EXZuuZBCzOU977RuYaS9tA.png" /></figure><p>We’ve removed the dependency from this link, let’s list again the pvcs and pv, if they are still in Terminating state.</p><pre> kubectl get pvc<br> kubectl get pv</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k0ITIIS4d-d7Z9qP4H6DqQ.png" /></figure><p>And they are gone!</p><p>So remember, if you are doing a persistant volume clean up check if:</p><ul><li>No pvc is attached to Pod</li><li>PV is not bounded to any PVC</li></ul><p><strong>Few Notes:</strong></p><ul><li>When you delete a statefulset that have a retention policy whenDeleted:delete it will also remove the pods and the PVC.</li></ul><pre>apiVersion: apps/v1<br>kind: StatefulSet<br>...<br>spec:<br>  persistentVolumeClaimRetentionPolicy:<br>    whenDeleted: Delete<br>...</pre><ul><li>If you persistant volume have a retain policy Delete, when deleting the pvc the bound pv and underlying storage volume will be also deleted.</li><li>If your PV retain policy is not Delete, you’ll have to remove the PV and storage manually.</li></ul><p>This is the most “gracious” way to get out of the terminating state, you can also remove the terminating resource without removing the dependencies first. We simply need to remove the finalizer protection from the PV or pvc.</p><pre>kubectl patch pvc pvc_name -p &#39;{&quot;metadata&quot;:{&quot;finalizers&quot;:null}}&#39;<br>or<br>kubectl patch pv pv_name -p &#39;{&quot;metadata&quot;:{&quot;finalizers&quot;:null}}&#39;</pre><p>and the resource will be removed, just keep in mind this might not be the best solution, because your resource was bounded or attached.</p><p>If you remove the finalizer of a terminating pv, the pvc will lose the Bound, staying in the state Lost and you might loose your data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2x-SueL9DQOH2XnMO-5Ikw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*udwJ01nivgLCOb3rZGiRLw.png" /></figure><p>If this post was helpful, please click the clap 👏 button below a few times👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f88915ef93f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[K8s Storage Class: Intro Longhorn Csi for Reliable Data Management.]]></title>
            <link>https://medium.com/@fsegredo2000/k8s-storage-class-intro-longhorn-csi-for-reliable-data-management-b6529aed2848?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b6529aed2848</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes-storage]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Wed, 18 Oct 2023 19:58:13 GMT</pubDate>
            <atom:updated>2023-10-18T19:58:13.595Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QZ31LClcvJqgQFQB.png" /></figure><p>Kubernetes has become the standard for container orchestration, offering scalable and resilient application deployment. However, managing stateful workloads, especially storage, has been a significant challenge (Top 5 user challenges in Kubernetes). These concerns have been alleviated by the Kubernetes Storage Classes, which allow dynamic provisioning of storage volumes. Longhorn is a robust and user-friendly choice among the many storage solutions available. In this article, we’ll look at Kubernetes Storage Classes and Longhorn’s features and benefits.</p><p>Before we begin, lets review what the Kubernetes Storage classes are.</p><p>Kubernetes Storage Classes make it easier to manage persistent storage in a cluster. They abstract the underlying storage infrastructure, allowing developers and administrators to define storage requirements in a more declarative manner, without needing to interact directly with storage systems. Storage Classes facilitate dynamic provisioning of storage volumes, enabling scalability, failover, and data redundancy for stateful applications.</p><p><strong>Longhorn: A Brief Overview</strong></p><p>Longhorn (CNCF Incubating Project) is a lightweight, reliable and easy-to-use distributed block storage system for kubernetes.</p><p>Longhorn Features:</p><ul><li><strong>Replication and Data Resilience:</strong> Employs a distributed block storage system that replicates data across multiple nodes, thereby ensuring data resilience and high availability. It uses a mechanism called replicas to maintain data consistency and is able to recover from node failures or data corruption</li><li><strong>Snapshots and Backups:</strong> It is easy to create backups of your data by taking snapshots of your volumes at any point in time. These snapshots can be used for disaster recovery or as a basis for new volumes.</li><li><strong>Dynamic Volume Provisioning:</strong> Integrates seamlessly with Kubernetes Storage Classes, enabling dynamic provisioning of volumes. You can specify the desired storage class in your PersistentVolumeClaim (PVC), and Longhorn will create the volume for you.</li><li><strong>Built-in UI:</strong> Provides a user-friendly web-based UI for managing volumes, snapshots, and backups.</li><li><strong>Cross-Cluster Replication:</strong> Feature for cross-cluster replication, enabling data synchronization and disaster recovery across multiple Kubernetes clusters.</li><li><strong>Community Support:</strong> Active community and regular updates, ensuring that it remains up-to-date with the latest Kubernetes features and best practices. It also offers commercial support for enterprises.</li></ul><p><strong>Longhorn Upper hand</strong></p><ul><li><strong>Open Source:</strong> Open-source project, which means you can use, change, and contribute to it. This promotes transparency and collaboration in the community.</li><li><strong>Kubernetes-Native:</strong> It aligns closely with Kubernetes, which makes it an ideal choice for containerized environments. It’s designed to leverage Kubernetes’ strengths and functionality.</li><li><strong>Simplicity</strong>: Longhorn’s straightforward installation and management, along with its user-friendly UI.</li><li><strong>Data Protection:</strong> The ability to take snapshots, backups, and perform cross-cluster replication ensures the safety of your data.</li></ul><p>Let’s get our hands dirty, and install longhorn.</p><p><strong>Longhorn install</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb0c024bac603aa89095ccae6468cc72/href">https://medium.com/media/eb0c024bac603aa89095ccae6468cc72/href</a></iframe><p>Follow the installation process by listing the pods on the longhorn namespace with the flag watch.</p><pre>kubectl -n longhorn-system get pod --watch</pre><p>Now that you have all the pods running, you’re ready to go. Let’s make sure you have the longhorn storage class:</p><pre>kubectl -n get sc</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3BHHIT-lVpwzsG8ctCsOpA.png" /></figure><p>The storage class is created with the reclaim policy delete, indicating that upon the deletion of the PVC, both the bounded PVand the underlying storage volume will be deleted.</p><p>We can now create a PVCbased on the storage class longhorn, (we’re using lke, which means we don’t need to create the pv it will be created for us automatically).</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: example-claim<br>spec:<br>  storageClassName: longhorn<br>  accessModes:<br>  - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 100Mi</pre><p>After applying the manifest, we’ll see that a pv and a pvc were created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jtfqxo7iJeWROeUEuuNlNA.png" /></figure><p>Longhorn is now our block storage solution and manager.</p><p>Let’s now look at the good things about longhorn, starting with the dashboard. We’re going to port-forward the dashboard for demonstration purposes.</p><pre>kubectl port-forward service/longhorn-frontend:80 -n lonhorn-system</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*X0nGi48xHAKLusI5PeZm3w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1RyhXUPw02u0ZD9BCOPasA.png" /></figure><p>In the dashboard we can:</p><ul><li>Vew event logs about pv and pvcs.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1QrQ1838ZlmMnbKfN2NHtw.png" /></figure><ul><li>View information about the cluster Nodes.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vMRFIS-qiQmV17fYGBX7GQ.png" /></figure><ul><li>View and create new pvc.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7uREKIOTrNCkaGvPMRULUw.png" /></figure><ul><li>Create and manage volumes backups.</li><li>Define recurring jobs that can performe backups and snapshots.</li></ul><p>This is a quick look at longhorn. In the next article, we’ll look at the Microservices architecture design of longhorn, Auto Balance Replicas, Store backups in S3 Buckets, and Monitor volumes with Grafana.</p><p>If this post was helpful, please click the clap 👏 button below a few times👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b6529aed2848" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Adaptable vs. Fixed Technology Stacks: Choosing the Right Approach for Project Success]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@fsegredo2000/adaptable-vs-fixed-technology-stacks-choosing-the-right-approach-for-project-success-3f2fff589733?source=rss-7116e92c10a1------2"><img src="https://cdn-images-1.medium.com/max/1313/1*b9csvM9DLC-_lQ2eQdi2ZQ.png" width="1313"></a></p><p class="medium-feed-snippet">The ever-changing technological landscape today presents companies with the constant challenge of selecting the most suitable technology&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@fsegredo2000/adaptable-vs-fixed-technology-stacks-choosing-the-right-approach-for-project-success-3f2fff589733?source=rss-7116e92c10a1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@fsegredo2000/adaptable-vs-fixed-technology-stacks-choosing-the-right-approach-for-project-success-3f2fff589733?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/3f2fff589733</guid>
            <category><![CDATA[development-stack]]></category>
            <category><![CDATA[tech-stack]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[project-management]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 19:38:15 GMT</pubDate>
            <atom:updated>2023-09-05T19:38:15.133Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Docker compose — Include]]></title>
            <link>https://medium.com/@fsegredo2000/docker-compose-include-df9ff53bf840?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/df9ff53bf840</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 16:04:40 GMT</pubDate>
            <atom:updated>2023-09-05T16:04:40.512Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker compose — Include</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*co3moT1FsF05wWSajGVxfg.png" /></figure><p>In Docker Compose 2.20 (available on docker desktop v.4.22), there’s a new include attribute that’s quite useful. Let’s begin.</p><p>Essentially, it is now possible to explicitly declare dependencies to other composes by incorporating the flag include and specifying the location of the other composes. We will see some examples, but let’s start with the advantages.</p><ul><li>Possibility to reuse composes easily.</li><li>If your compose gets too big or complex to read and manage, you can use include as a way to refractor.</li><li>Separation of concerns, for example different services handled by different teams.</li></ul><p>Let’s say I have two APIs and a Database, but each should have its own separate structure, but the deployment should be together.</p><p>One may immediately consider the subsequent command line, which is valid if all the composes follow a consistent path and are simple. However, if one of the composes employs relatives paths, it may not work as aspected.</p><pre>docker compose -f database-compose.yaml -f serviceA-compose.yaml -f ...</pre><p>Given the structure, let’s see an example of this approach failing.</p><pre><br><br>docker-playground/<br>├─ Apps/<br>│  ├─ service/<br>│  │  ├─ Dockerfile<br>│  │  ├─ docker-compose.yaml<br>│  │  ├─ index.html<br>│  │  ├─ package.json<br>│  │  ├─ .env<br>│  ├─ webserver/<br>│  │  ├─ docker-compose.yaml</pre><pre># ../service/docker-compose.yaml<br>services:<br>  api:<br>    build: . <br>    env_file:<br>      - ./.env</pre><pre># docker-compose.yaml<br>services:<br>  webapp:<br>    image: httpd<br>    depends_on:<br>    - api </pre><pre>docker compose -f docker-compose.yaml -f ../service/docker-compose.yaml up -d</pre><p>Doing compose up from the webserver directory will fail because it assumes the webserver as the base folder for all the composes loaded, so it will not be able, for example, to find the Dockerfile of /service/docker-compose.yaml and all the other files to build the image successfully.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bVzrMh13xvn731jenr9mtA.png" /><figcaption>Error location components to build service api</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gxDfokfpRUIWAq7793JMdg.png" /><figcaption>Erro locating service api components</figcaption></figure><p>In addition to the advantages listed above, the include attribute also aids in resolving this issue.</p><blockquote><strong>“How can we use the atribute?”</strong></blockquote><p>According to the compose specification:</p><pre>&quot;include&quot;: {<br>      &quot;type&quot;: &quot;array&quot;,<br>      &quot;items&quot;: {<br>        &quot;type&quot;: &quot;object&quot;,<br>        &quot;$ref&quot;: &quot;#/definitions/include&quot;<br>      },<br>      &quot;description&quot;: &quot;compose sub-projects to be included.&quot;<br>    },</pre><p>The simpliest format (<strong>Short Syntax</strong>):</p><pre>include:<br>  - extra-compose.yaml<br>services:<br>  ...</pre><p>Since is a list of items, you can load mode than one compose</p><pre>include:<br>  - ../shared/compose-share.yaml<br>  - ../extra/compose-extra.yaml<br>services:<br>  ...</pre><blockquote>Each path listed in the <em>include</em> section is loaded as an individual Compose application model, with it&#39;s own project directory, in order to resolve relative paths.<strong> </strong>— docs.docker.com</blockquote><p>If you would like to have more control over your parsing, you can use the <strong>Long Syntax</strong>, which will allow you to define the project directory and associated environments.</p><pre>include:<br>  - path: ../shared/compose-share.yaml<br>    env_file: ../vars/.env<br>    <br>services:<br>  ..</pre><p><strong>In Action:</strong></p><p>Using the same directory structure as before, we will use the include atribute instead of loading multiple composes with the flag -f.</p><p>Now let’s change the main compose webapp and add an include to load the service api from another compose file.</p><pre># BEFORE<br>services:<br>  webapp:<br>    image: httpd<br>    depends_on:<br>    - api</pre><pre># AFTER<br>include:<br>  - path: ../service/docker-compose.yaml<br>    env_file: ../webserver/.env<br>services:<br>  webapp:<br>    image: httpd<br>    depends_on:<br>    - api # api service is declared the include compose</pre><p>Subsequently, we only need to execute the standard docker compose up -d, and no more -f required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*1wNRosWSFpWDeiVROoiRbA.png" /></figure><p>We can see that the include compose was successfully loaded.</p><p>Also with the env_file you can override values for interpolation variables defined on the include composes.</p><p>Lets take the api service for example.</p><pre>services:<br>  api:<br>    build: . <br>    ports:<br>      - ${API_PORT}:8080</pre><pre>API_PORT = &quot;8888&quot;</pre><p>If we were to execute directly, the container would be published to the port 8888. However, as we have defined the env_file in the webserver directory, it will be overridden.</p><pre>env_file: ../webserver/.env</pre><pre>API_PORT = &quot;7070&quot;</pre><p>It will actually be publish on port 7070</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bjjm8LFLJ1HwUbY2BbwNqw.png" /></figure><p>and that’s it, a simple overview for the atribute include.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*culpkVVpG6xFtSdPReRjoA.png" /></figure><p><strong>Few pointers:</strong></p><ul><li>The composes defined in the include are loaded recursively, which means your composes in the include section can also have includes.</li></ul><p>example:</p><pre>#commons/compose.yaml<br>services:<br>  apibase:<br>    build: . <br>    ports:<br>      - ${API_BASE}:1234</pre><pre>#../service/docker-compose.yaml<br>include:<br>  - ../commons/compose.yaml<br>  <br>services:<br>  api:<br>    build: . <br>    ports:<br>      - ${API_PORT}:8080<br>    depends_on:<br>      - apibase # api service is declared the include commons compose</pre><pre>../webserver/docker-compose.yaml<br>include:<br>  - path: ../service/docker-compose.yaml<br>    env_file: ../webserver/.env<br>services:<br>  webapp:<br>    image: httpd<br>    depends_on:<br>    - api # api service is declared the include compose</pre><ul><li>All the composes defined are merged together, you can verify by using the docker compose config it will give you the final compose , that you can use to debug before actually creating your containers:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*0hX0xxNMTzqNwRj1x0SsNA.png" /></figure><ul><li>As we mentioned earlier, every include compose uses its parent folder as the base folder, avoiding issues with relative paths.</li></ul><p>If this post was helpful, please click the clap 👏 button below a few times👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df9ff53bf840" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Docker — Linux security technologies (cGroups)]]></title>
            <link>https://medium.com/@fsegredo2000/docker-linux-security-technologies-cgroups-979002f28c7d?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/979002f28c7d</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[cgroup]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[denial-of-service]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 18:12:16 GMT</pubDate>
            <atom:updated>2023-08-31T18:12:16.373Z</atom:updated>
            <content:encoded><![CDATA[<h3>Docker — Linux security technologies (cGroups)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/392/1*8GaUfxHhjZehwhfCEg_zPw.png" /></figure><p>In the latest article, we discussed the Linux kernel feature namespace and its different types of isolation. Today, we will explore cGroups.</p><p><a href="https://medium.com/@fsegredo2000/docker-linux-security-technologies-namespaces-c1d82908127e">Docker — Linux security technologies (Namespaces)</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*nPjGCk-TxEym-TsxHSMhwg.png" /></figure><p><strong>CGroups</strong></p><p>Control Groups(cGroups), are a Linux kernel feature that allow you to allocate and manage system resources among processes.</p><p>They provide a means to restrict, account for, and isolate the utilization of resources (such as CPU, memory, disk I/O, and network) of a group of processes, facilitating effective resource management and preventing resource exhaustion and denial-of-service attacks (DoS).</p><p>As we’ve seen before, containers are isolated from each other, but the OS resources are still shared between them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*fh3lCkweYMIdbMjldk_alg.png" /><figcaption>Resources share</figcaption></figure><p>You are probably familiar with the docker flags — memory and — cpu when creating or updating a container. This is what cgroups does, limits the amount of resources that the container can use (by default has no limits, which can be a challenge, we’ll look into it later)</p><p>We are going to deploy two web servers, one with memory limits and one without, and then compare them.</p><pre>docker run -itd --name withlimit --memory=314572800 httpd<br>docker run -itd --name nolimit httpd</pre><p>Inspecting the container and looking into the memory value for each container</p><pre>docker inspect nolimit -f &quot;{{.HostConfig.Memory}}&quot;</pre><pre>docker inspect withlimit -f &quot;{{.HostConfig.Memory}}&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/557/1*LoVr2sdYfEf2TSYp0nDPuQ.png" /><figcaption>No memory limit set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*DrGcuFRhvXr_IsKyg5EeKA.png" /><figcaption>Limit of 300 MB that was defined with — memory</figcaption></figure><p>another way to verify this value inside the container:</p><pre>cat /sys/fs/cgroup/memory/memory.limit_in_bytes</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/598/1*4D4T7pbssvClY5fuvhJyKg.png" /><figcaption>Limit by the -m value we’ve set</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*lpHvh6Pqdvrj-rEHELdEWg.png" /><figcaption>No limit, defines a LONG_MAX on a 64 bit platform</figcaption></figure><p>The PID of the containers can be used to verify this directly in the host.</p><p>Usually the path of the cgroups associated to containers is always the same /sys/fs/cgroup/(type)/docker/containerID but to make sure let’s use proc to tell us the cgroups associated with a PID.</p><p>Let’s start by getting the containers PID</p><pre>#SYNTAX docker inspect --format=&#39;{{.State.Pid}}&#39; ContainerName<br><br> docker inspect --format=&#39;{{.State.Pid}}&#39; withlimit #28352<br> docker inspect --format=&#39;{{.State.Pid}}&#39; no limit #27744<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*J3KOdW5qYc-g3YJttLIBGg.png" /><figcaption>Retrieve container PID</figcaption></figure><p>Now that we have the PID of the containers, it’s easy the get the cgroup folder location in the host</p><pre>#SYNTAX cat /proc/{PID}/cgroup</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*t59r3XVDR30UivkMR0uwlw.png" /><figcaption>List of cgroup path in host</figcaption></figure><p>Since we are doing a Memory limit test, we’ll only focus on the memory cgroup/folder.</p><pre>#SYNTAX cd/sys/fs/cgroup/memory/docker/ContainerID<br>cd /sys/fs/cgroup/memory/docker/702677...<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*_5-UXrtbGTLZa54jAoWZUA.png" /><figcaption>list of group</figcaption></figure><p>In this case the docker flag — memoryequals the folder memory.limit_in_bytes.</p><p>For the container without limit we’ll get a LONG_MAX/PAGE_SIZE in a 64-bit platform that basically says unlimited resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/878/1*3hxByaa4P0sE8Y6O7VHGOw.png" /><figcaption>Memory with no limit</figcaption></figure><p>Doing the same for the container with a memory limit, we’ll get the value we defined while creating the container</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*viFeSUTzIsRwgi3G0IENIw.png" /><figcaption>Memory with limit</figcaption></figure><p>This is only one of the resources that can be restricted, as explained in a superficial manner. Additionally, we can restrict the CPU utilization and device access by the container.</p><p>Fork bomb is a common DoS attack on Linux systems that involves flooding your system with shallow processes, which depletes the system resources. By default, Linux processes and subsequently containers do not impose any limitations on the number of processes that can be generated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*kRExqT7zlM0uqjsRyMVfwg.png" /><figcaption>Image by imperva</figcaption></figure><p>cGroups can be used to limit this by adding the flag pids-limit to your docker run command.</p><p>Let’s see how this works.</p><p>The easiest way to simulate this is to use a Bash script, which is an infinite loop that repeatedly launches new copies of itself. This will eventually crash your system by consuming CPU time and saturating the systems process table.</p><p>We’re only going to show the result with the pid limitating set (Be ready for a crash and to reboot your system inc ase you try it without the pid limit).</p><pre>docker run -it --name pidlimit --pids-limit 10 ubuntu bash</pre><p>We’re running a ubuntu container with a bash process and the limit of processes 10 and run the following:</p><pre>:(){ :|: &amp; };:</pre><p><a href="https://www.geeksforgeeks.org/fork-bomb/">Explanation of the script</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/412/1*fz8Fi0UFqoGhl0ypK4NkyQ.png" /><figcaption>Pid limit result</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/621/1*2zYTrVkkimtlI7mOJpE1FQ.png" /></figure><p>The container will reach the maximum of pids defined and will start throwing erros, but the host will remain responsive, preventing DoS</p><p>If this post was helpful, please click the clap 👏 button below a few times👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=979002f28c7d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Bandwagon Effect: Adopting Technology with care]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@fsegredo2000/the-bandwagon-effect-adopting-technology-with-care-92e784cb8f76?source=rss-7116e92c10a1------2"><img src="https://cdn-images-1.medium.com/max/602/1*dTG7SVTkV1uyhhgZprYXfQ.png" width="602"></a></p><p class="medium-feed-snippet">In the current technological landscape, which is undergoing rapid advancements, it is not uncommon to observe the emergence of new tools&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@fsegredo2000/the-bandwagon-effect-adopting-technology-with-care-92e784cb8f76?source=rss-7116e92c10a1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@fsegredo2000/the-bandwagon-effect-adopting-technology-with-care-92e784cb8f76?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/92e784cb8f76</guid>
            <category><![CDATA[digital-transformation]]></category>
            <category><![CDATA[it-planning]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 15:05:32 GMT</pubDate>
            <atom:updated>2023-08-21T15:05:32.995Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Docker with gVisor]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@fsegredo2000/docker-with-gvisor-9841f271dd85?source=rss-7116e92c10a1------2"><img src="https://cdn-images-1.medium.com/max/661/1*WpcTEwnrPNkHb2QE_7bslA.png" width="661"></a></p><p class="medium-feed-snippet">gVisor is an application kernel(that includes an OCI runtime called runsc) developed by Google that provides an additional layer of&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@fsegredo2000/docker-with-gvisor-9841f271dd85?source=rss-7116e92c10a1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@fsegredo2000/docker-with-gvisor-9841f271dd85?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/9841f271dd85</guid>
            <category><![CDATA[gvisor]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[container-runtime]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-daemon]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Sun, 20 Aug 2023 19:20:02 GMT</pubDate>
            <atom:updated>2023-08-20T19:20:02.878Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Docker — Linux security technologies (Namespaces)]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@fsegredo2000/docker-linux-security-technologies-namespaces-c1d82908127e?source=rss-7116e92c10a1------2"><img src="https://cdn-images-1.medium.com/max/600/1*bHvG5aAngYjOAx-EUPyJwQ.png" width="600"></a></p><p class="medium-feed-snippet">In this article, we will discuss some of the Linux security technologies used by Docker.</p><p class="medium-feed-link"><a href="https://medium.com/@fsegredo2000/docker-linux-security-technologies-namespaces-c1d82908127e?source=rss-7116e92c10a1------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@fsegredo2000/docker-linux-security-technologies-namespaces-c1d82908127e?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c1d82908127e</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[linux-namespace]]></category>
            <category><![CDATA[containerization]]></category>
            <category><![CDATA[docker-security]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Tue, 15 Aug 2023 17:13:31 GMT</pubDate>
            <atom:updated>2023-08-15T17:16:00.554Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Terraform Refresh]]></title>
            <link>https://medium.com/@fsegredo2000/terraform-refresh-b2bc9a6ffe49?source=rss-7116e92c10a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2bc9a6ffe49</guid>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[iac]]></category>
            <category><![CDATA[terraform-refresh]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[terraform-state]]></category>
            <dc:creator><![CDATA[Fsegredo]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 14:05:06 GMT</pubDate>
            <atom:updated>2023-08-03T11:39:32.458Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*gk2qgVB1UoGKxSyQAmcN6Q.png" /></figure><p>Terraform stores the state of the resources that it manages in a state file called by default terraform.tfstate, and this file is used <strong>mainly </strong>to map real world resources to your configuration and keep track of metadata, with that being said, making sure the state file is always updated (matches the infreastructure) should be one of our priorities.</p><blockquote><strong>In what cases the state file is different that the real world insfrastructure?</strong></blockquote><p>We call this a drift state when the state file differs from the real world infrastructure, and you’ll have a drift state when you have a resource managed by Terraform and a change is made manually, say via a cloud provider’s UI or cloud provider Cli.</p><p>Let’s make sure we understand what a terraform refresh state is before we see it in action.</p><p>As per the Terraform workflow, the steps <strong>Plan </strong>and <strong>Apply </strong>are the sole ones that by default refresh the state file prior to performing any operation and will alert you of any potential discrepancies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*z6GaicJZj8b6sb68F_8MvA.png" /><figcaption>Terraform workflow</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*pkwJP0vyPYMBXq_XySo2QA.png" /><figcaption>Terraform plan</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/542/1*Bs9nHBQfWAWkwfPLT6tISg.png" /><figcaption>Terraform apply</figcaption></figure><p>We can see from the images that we have an instance called linode_instance.web managed by Terraform, and to simplify things, the resource block was cut.</p><pre>resource &quot;linode_instance&quot; &quot;web&quot; {<br>  image = var.image[&quot;MIN&quot;]<br>  label = &quot;simple_instance&quot;<br>  ...<br>  tags = [ &quot;foo&quot; ]<br>  region = var.region<br>  ..<br>  private_ip = true<br>  ..<br><br>  depends_on = [<br>    ...<br>  ]<br>}</pre><p>The cloud provider used for this example is Linode, so I’ll log into my Linode dashboard and add a new tag to the instance, beside the one that terraform knows about.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*1wyqH_CmCwbkTx-c8fXaGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*5VT-6Ym3UvTy9IwchEchvQ.png" /></figure><p>Now let’s go back to terraform and refresh the state file</p><pre>terraform plan --refresh-only</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_br5ztppnB6pKzY1sFYDVg.png" /></figure><p>Terraform planwill alert us to the fact that our state file does not match the real work resources, and that something was modified outside of Terraform scope.</p><p>We checked if the change was needed and we want to put it under Terraform management. Then, we need to update our file and add the new tag.</p><pre>terraform apply --refresh-only --auto-approve</pre><p>After apply is done we can query the state file again and we’ll see the tag created manually is now on the state file</p><pre>terraform state show linode_instance.web</pre><pre>...<br>    status             = &quot;running&quot;<br>    swap_size          = 512<br>    tags               = [<br>        &quot;foo&quot;,<br>        &quot;foo2&quot;,<br>    ]<br>...</pre><p>We’ve updated the state file, but <strong>we’re not done yet!</strong> If you try to do a Plan <strong>as is</strong>, we’ll get a notification that an update in-place will be performed (remove the foo2 tag) if we apply!</p><blockquote>Why is that?</blockquote><p>We have updated our state file to align with the actual world resources. However, we have not updated our resource block configuration, as it still indicates that the resource only has one tag name, foo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*xVHR5jB4c0KGiE42j9i_bw.png" /></figure><p>Let’s update the resource to include the new tag and PLAN again.</p><pre>resource &quot;linode_instance&quot; &quot;web&quot; {<br>  image = var.image[&quot;MIN&quot;]<br>  label = &quot;simple_instance&quot;<br>  ..<br>  tags = [ &quot;foo&quot;,&quot;foo2&quot; ]<br>  ..<br>}</pre><pre>terraform plan</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*norH9NUgdoOfdqRps9yOlg.png" /></figure><p>And now we’re done, for simplicity we’ve made just a simple change to understand how the — refresh-only works.</p><h3><strong>Precautions</strong></h3><p>Most might say terraform refresh and terraform plan/apply --refresh-only are the same, technically yes! but there’s a risk associated because with terraform refresh you won’t receive a preview of what changes going to happen and you’re not going to be asked to approve the changes as it happens when you apply . So always consider using the — refresh-only!!</p><p>Let’s see a “disaster” case:</p><p>For this example I switched from <strong>Linode </strong>to <strong>AWS</strong>, where I have two <strong>EC2 </strong>instances running.</p><pre>terraform show</pre><pre># aws_instance.ec2_instance[0]:<br>resource &quot;aws_instance&quot; &quot;ec2_instance&quot; {<br>   ...<br>}<br><br># aws_instance.ec2_instance[1]:<br>resource &quot;aws_instance&quot; &quot;ec2_instance&quot; {<br>   ...<br>}</pre><pre>provider &quot;aws&quot; {<br>    access_key = &quot;${var.access_key}&quot;<br>    secret_key = &quot;${var.secret_key}&quot;<br>    region = &quot;us-east-1&quot;<br>}</pre><p>Let’s say we mistakenly move to a different region, ap-south-1 .</p><pre>provider &quot;aws&quot; {<br>    access_key = &quot;${var.access_key}&quot;<br>    secret_key = &quot;${var.secret_key}&quot;<br>    region = &quot;ap-south-1&quot;<br>}</pre><pre>terraform refresh</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*Vl3DT4sNAPWxhAIROKKY5g.png" /></figure><p>3..2..1…your state is gone :) and the output doesn’t tell you much about it, this happened because we changed the region, so the api for AWS will now be filtered for another region where we don’t have any instance running, so terraform receiving no information assumes the instances were deleted outside of terraform scope.</p><p>There’s ways to recover from this with tfstates backups, terraform imports, state versioning, etc but.. point is.. use --refresh-only instead!! :)</p><p>Always use it with caution, nevertheless..</p><p>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2bc9a6ffe49" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>