<?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 Jigar R on Medium]]></title>
        <description><![CDATA[Stories by Jigar R on Medium]]></description>
        <link>https://medium.com/@jigarr?source=rss-a6fb2ddfac5e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*59k9nj_tKwNK8F71</url>
            <title>Stories by Jigar R on Medium</title>
            <link>https://medium.com/@jigarr?source=rss-a6fb2ddfac5e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 11:56:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jigarr/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[Networking in Kubernetes]]></title>
            <link>https://jigarr.medium.com/networking-in-kubernetes-31ec6c3c0246?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/31ec6c3c0246</guid>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Mon, 23 Nov 2026 12:09:35 GMT</pubDate>
            <atom:updated>2026-11-25T10:17:31.090Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CqCJ6TikjbgvTpqR0TBNyg.jpeg" /></figure><p>Networking in Kubernetes has been a bit complicated concept. This post will highlight few fundamentals ideas. You can follow <a href="https://jigarr.medium.com/list/kubernetes-f5d0178b859a">Kubernetes</a> series to know more K8s.</p><p>Let’s take a nginx based web-app. Prior to kubernetes, we would run nginx process on a machine. Nginx would bind on port 8080 of the machine. Going onwards, any traffic to port 8080 would be handled by Nginx. Now, let’s see how this would work in Kubernetes.</p><p>Consider that the machine from which we are running kubectl commands is not part of the Kubernetes cluster. We can run nginx by creating a deployment in Kubernetes as following.</p><pre>$ cat frontend-demo.yaml<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: frontend<br>  labels:<br>    app: frontend                 # Label attached to the Deployment object<br>spec:<br>  replicas: 2<br>  selector:<br>    matchLabels:<br>      app: frontend               # Deployment manages Pods with this label<br>  template:<br>    metadata:<br>      labels:<br>        app: frontend             # Label attached to every Pod created<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:1.28.0<br><br>$kubectl apply -f frontend-demo.yaml<br><br>$kubectl get pods --output=wide<br><br>NAME                        READY   STATUS    RESTARTS   AGE   IP            NODE<br>frontend-66b7c9dd4b-abcde   1/1     Running   0          45s   10.244.0.18   worker2<br>frontend-66b7c9dd4b-fghij   1/1     Running   0          45s   10.244.1.31   worker3<br><br><br>$curl http://10.244.0.18<br>curl: (28) Failed to connect to 10.244.0.18 port 80 after 75000 ms: Couldn&#39;t connect to server<br><br>$kubectl get nodes worker2 -o wide<br>NAME      STATUS   ROLES    AGE   VERSION   INTERNAL-IP   EXTERNAL-IP   OS-IMAGE               KERNEL-VERSION   CONTAINER-RUNTIME<br>worker2   Ready    worker   5d    v1.31.1   10.0.1.25     &lt;none&gt;        Amazon Linux 2023      X.X.X            XXXX<br><br></pre><p>We see that deployment created 2 pods. Each pod has an IP address. When we tried to connect to web-app using pod’s IP address, we got an error. As frontend pod has not occupied port 8080 on worker2/worker3; running curl on worker2/worker3 would be of no use.</p><p><strong>Question 1: The curl didn’t work on the machine outside of Kubernetes cluster but what would happen if I run curl command from inside.</strong></p><p>You will get a response. This is because when you are running commands outside of Kubernetes cluster, your machine has no way to reach to frontend pod.</p><pre>$ ssh worker2<br><br># running curl on pod&#39;s IP address<br>$ curl http://10.244.0.18        <br>....<br>     &lt;h1&gt;Welcome to nginx!&lt;/h1&gt;<br>....</pre><p><strong>Question 2: What if I don’t want developers to SSH to worker nodes? Is there any other solution?</strong></p><p>What if developer can run kubectl command to bind localhost’s port with pod? This is what we can do using port-forwarding. In following example, we bind localhost’s port 18080 with one of the frontend pod.</p><pre>$ kubectl get pods --output=wide<br><br>NAME                        READY   STATUS    RESTARTS   AGE   IP            NODE<br>frontend-66b7c9dd4b-abcde   1/1     Running   0          45s   10.244.0.18   worker2<br>frontend-66b7c9dd4b-fghij   1/1     Running   0          45s   10.244.1.31   worker3<br><br>$ kubectl port-forward pod/frontend-66b7c9dd4b-abcde 18080:80<br><br><br>$ curl http://localhost:18080<br>....<br>     &lt;h1&gt;Welcome to nginx!&lt;/h1&gt;<br>....<br></pre><p><strong>Question 3: What about other pods? Can they talk to each other?</strong></p><p>This is usually referred as pod-to-pod communication. In following example, I have created a pod named curl-test which just runs curl command.</p><pre>$ kubectl run curl-test \<br>  --rm -it \<br>  --image=curlimages/curl:8.11.1 \<br>  --restart=Never \<br>  -- curl http://10.244.0.18                     # running curl on pod&#39;s IP<br><br>.....<br>      &lt;h1&gt;Welcome to nginx!&lt;/h1&gt;<br>.....</pre><p><strong>Question 5: what if worker2 node is out for any reason or if the pod is deleted or fails?</strong></p><p>In such cases, pod might get scheduled on another node. On top of it, the pod will have a new IP address. We can simulate this scenario by deleting one of the frontend pods. As we created a deployment, another pod got created to replace earlier pod (by <a href="https://medium.com/@jigarr/kubernetes-101-part-2-7ba444d8ae2f?sharedUserId=jigarr">ReplicaSet</a>)</p><pre>$ kubectl delete pod frontend-66b7c9dd4b-abcde<br><br>$ kubectl get pods --output=wide<br>NAME                        READY   STATUS    RESTARTS   AGE   IP            NODE<br>frontend-66b7c9dd4b-fghij   1/1     Running   0          5m    10.244.1.31   worker3<br>frontend-66b7c9dd4b-x7k2p   1/1     Running   0          45s   10.244.0.45   worker4<br></pre><p>If IP addresses keep on changing then how can we enable pod-to-pod communication reliably?</p><p>Prior to Kubernetes, applications were strictly bound to a node. We can do the same by creating a <strong>Service (that ties Node’s port with pod/NodePort type service)</strong>. However, this is not an ideal solution. If you keep binding apps to a node then you will end up with uneven load distribution. Kubernetes community offers a better solution.</p><p>For a reliable communication, you just need a stable IP address. What if we can have a cluster wide IP address? Whenever request is sent to this IP address, it would be forwarded to pods with specific labels. This is exactly what we can get by creating a ClusterIP as following:</p><pre>$ cat frontend-cluster-svc.yaml<br>apiVersion: v1<br>kind: Service<br>metadata:<br>  name: frontend-svc<br>spec:<br>  type: ClusterIP              # Cluster wide IP address<br>  selector:<br>    app: frontend              # Send traffic to Pods labeled app=frontend<br>  ports:<br>  - name: http<br>    protocol: TCP<br>    port: 10080                <br>    targetPort: 80             # forward traffic to port 80<br><br>$ kubectl apply -f frontend-cluster-svc.yaml<br><br>$ kubectl get svc<br>NAME             TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)     AGE<br>frontend-svc     ClusterIP   10.244.1.120   &lt;none&gt;        10080/TCP   2m</pre><p>In this example, we created a Kubernetes service named frontend-svc. Within cluster any traffic sent to 10.244.1.120 will be sent to frontend-svc which will forward it to pods with the label “app = frontend”.</p><p><strong>Question 6: What if someone deleted service accidentally?</strong></p><p>In this case, we can create the service again but it will have different IP address. Wouldn’t it better if pods just query <a href="http://frontend-svc/">http://frontend-svc</a> and traffic is forwarded to our frontend-svc?</p><p>This problem has been solved by DNS (Domain Name Service) ages ago. So all you need to do now ask admin to setup a DNS in your Kubernetes cluster?</p><p>I am kidding, it’s been already handled. Kubernetes typically uses CoreDNS which add/update/delete DNS entries.</p><pre><br>$ kubectl run curl-test \<br>  --rm -it \<br>  --image=curlimages/curl:8.11.1 \<br>  --restart=Never \<br>  -- curl http://frontend-svc:10080<br>.....<br>      &lt;h1&gt;Welcome to nginx!&lt;/h1&gt;<br>.....</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yr2Re-6DXMOQIzTiudswFA.png" /></figure><p><strong>Question 7: Who gave the IP address to pods?</strong></p><p>Just like how, network interface gives IP address to a machine; Kubernetes has <strong>CNI</strong> (Container Network Interface).</p><blockquote>CNI is a specification which creates a network interface inside a pod, assigns an IP address to the pod, and keeps routes up-to-date. These specification is implemented by plugins like Calico, Cilium and Flannel. As all the plugins are following the standard specification, a Kubernetes cluster administrator can literally switch from one plugin to another plugin. Of course, such migrations would require careful planning and coordination.</blockquote><p><strong>Question 8: How to expose our web app to the world?</strong></p><p>We need to allow outside traffic to our web app securely. We will cover security aspect in another post. From networking point of view, we need a network interface that is exposed to the world and whenever this network interface receives the request, it should forward it to related services. This is exactly what <strong>Ingress</strong> does. The traffic flow can be visualized as following diagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-pEypkUAXJclooLCOlyqg.png" /></figure><p><strong>Question 8a: Ingress sounds a lot like a normal Kubernetes service. How is it different?</strong></p><p>To understand the key difference, we need to think about how the traffic hits the pod. I mean in terms of <a href="https://en.wikipedia.org/wiki/OSI_model">OSI (Open System Interconnection) model</a>. There are primarily two places where traffic can be routed in OSI model: Layer-4 (Transport layer using protocols like TCP/UDP etc) &amp; Layer-7 (Application layer using protocols like HTTP/HTTPS/MQTT etc).</p><p>Kubernetes service routes traffic at layer-4 whereas ingress routes traffic at layer-7. How routing is done depends on the <strong>controller</strong>. There are various <a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/#third-party-ingress-controllers">ingress controllers</a> such as</p><ul><li>HAProxy ingress controller</li><li>AWS-load-balancer-controller for AWS-managed Kubernetes service</li><li>ingress-gce for Google-managed Kubeneres service</li><li>Cilium ingress controller</li><li>Istio ingress controller</li></ul><p>Kubernetes administrator would setup ingressclass and guide devs on how to write appropriate ingress. In big enterprises, you can have two ingress for each service: one for internal traffic (for example: AWS S3 might call internal-ingress) and one for external traffic (for example: website might call external-ingress). In such a structure, internal-ingress does not need a public IP address.</p><p>The YAML file to specify ingress would vary slightly. Here is an example of ingress from Kubernetes documentation:</p><pre>$ cat frontend-ingress.yaml<br><br>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: frontend-ingress<br>spec:<br>  ingressClassName: nginx-example &lt;-- specify the type of ingressclass<br>  rules:<br>  - http:<br>      paths:<br>      - path: /frontend       &lt;-- whenever user hits YOUR_DOMAIN.com/frontend<br>        pathType: Prefix<br>        backend:<br>          service:<br>            name: frontend-svc &lt;-- forward traffic to frontend-svc service<br>            port:<br>              number: 80<br><br>$ kubectl apply -f frontend-ingress.yaml<br><br>$ kubectl get ingress<br>NAME               CLASS           HOSTS              ADDRESS         PORTS   AGE<br>frontend-ingress   nginx-example   YOUR_DOMAIN.com    203.0.113.10    80      5m</pre><p>When you tried http://YOUR_DOMAIN.com/frontend and got 404. Let’s see why:</p><pre>$ kubectl logs deploy/frontend --tail=50<br>....<br>GET /frontend 404</pre><p>Ingress correctly routed traffic to frontend-svc service but it didn’t remove /frontend from URL. We can fix this by adding an annotation as following</p><pre>$ cat frontend-ingress.yaml<br><br>apiVersion: networking.k8s.io/v1<br>kind: Ingress<br>metadata:<br>  name: frontend-ingress<br>metadata:<br>  annotations:<br>    nginx.ingress.kubernetes.io/rewrite-target: / &lt;--- the missing piece</pre><p>In this post, we introduced some key concepts</p><ul><li>Using Port-forwarding to connect to pods</li><li>pod-to-pod communication using Kubernetes Service (of type NodePort/Cluster IP)</li><li>DNS</li><li>CNI — Container Network Interface</li><li>Ingress</li></ul><p>Reference</p><ul><li>Image attribution — <a href="https://commons.wikimedia.org/wiki/File:19-inch_rackmount_Ethernet_switches_and_patch_panels.jpg">Dsimic</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>, via Wikimedia Commons</li><li><a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">https://kubernetes.io/docs/concepts/services-networking/ingress/</a></li><li>OSI model — <a href="https://en.wikipedia.org/wiki/OSI_model">https://en.wikipedia.org/wiki/OSI_model</a></li><li><a href="https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/#third-party-ingress-controllers">https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/#third-party-ingress-controllers</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31ec6c3c0246" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes 101 : Storage]]></title>
            <link>https://jigarr.medium.com/kubernetes-101-772f2bc8a5f6?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/772f2bc8a5f6</guid>
            <category><![CDATA[storage]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Wed, 04 Nov 2026 11:01:57 GMT</pubDate>
            <atom:updated>2026-12-02T16:52:20.091Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vAlVgsX4kWxTX9A8s9-pgw.jpeg" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:IBM_System_Storage_DCS3700_(17203388288).jpg">j_cadmus</a>, <a href="https://creativecommons.org/licenses/by/2.0">CC BY 2.0</a>, via Wikimedia Commons</figcaption></figure><p>This post is about Storage options in Kubernetes.</p><p>In past, we have discussed</p><ul><li><a href="https://jigarr.medium.com/kubernetes-101-d51030a56959?sharedUserId=jigarr"><em>part 1</em></a> — API Server, scheduler, etcd database and kubelet at high level</li><li><a href="https://jigarr.medium.com/kubernetes-101-part-2-7ba444d8ae2f?sharedUserId=jigarr"><em>part 2</em></a> — resource limits on pod, replicaset and deployment</li></ul><p>In part-2, we looked into how to rollout updates. But <strong>what happens to the data</strong>? In this post, we will focus on storage.</p><p>In previous posts, I mentioned that pods get scheduled on one of the node. So far we haven’t specified any storage information; but our pods would still read/write data.</p><p><strong>Where is the data?</strong></p><p>Kubelet and container-runtime allocates an isolated area on the node for a pod. Any data written to it is deleted whenever pod terminates or moves to another node. This is why it’s also called <strong>ephemeral storage</strong>. We can also utilize node’s memory using following <a href="https://kubernetes.io/docs/concepts/storage/volumes/#emptydir">YAML file</a>:</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: test-pd<br>spec:<br>  containers:<br>  - image: registry.k8s.io/test-webserver<br>    name: test-container<br>    volumeMounts:<br>    - mountPath: /cache<br>      name: cache-volume<br>  volumes:<br>  - name: cache-volume<br>    emptyDir:                     &lt;-- emptyDir is the type of the volume<br>      sizeLimit: 500Mi<br>      medium: Memory              &lt;-- without this we will write on disk </pre><p><strong>What are my options if I want to persist data?</strong></p><p>If we need to keep the data, then we have several options. In the following section, I will present some solutions along with their limitations to set the stage for better solution.</p><p><strong><em>Writing data on specific folder (on a specific host):</em></strong></p><p>We can also provide a dedicated disk drive to the pod. For example, we can specify that <em>/data/foo</em> should be used for <em>pod-a. </em>We can do so using <strong>hostPath</strong> volume. Let’s say <em>pod-a</em> got scheduled on <em>node-B</em>; kubelet and runtime will try to bind <em>/data/foo</em> for <em>pod-a</em> but if it does not find it then the container would not start. We might be tempted to use nodeSelector and always schedule <em>pod-a</em> on <em>node-a</em>. But this is not an ideal solution.</p><p><em>Writing data on external drive</em></p><p>Instead, Imagine storing data outside of the node — on an external drive. Whenever a new pod gets created, you assign a dedicated disk to the pod. And this disk can be attached to whatever node the pod is scheduled. Now, we don’t depend on a specific host. This is exactly what we can get using a <strong>Persistent Volume</strong>.</p><h3>Claiming storage for a pod</h3><p>Different applications need different types of storage options. For example, a write-heavy database application needs a completely different type of storage than a web application. Therefore, depending on the use case, pod may require different types of persistent storage. These storages are either static or dynamic (created-on-demand).</p><p>Kubernetes administrators create</p><ul><li><strong>Storage classes</strong> — to enable creation of Persistent Volumes dynamically</li><li>Static Persistent Volume — for applications that require specific configuration (for example, NFS server, EBS volume that was created prior to adopting Kubernetes)</li></ul><p>On the other hand, typical Kubernetes users don’t need to worry about the background details. They would specify</p><ul><li>create claim persistent volume by creating <strong>PVC (Persistent Volume Claim)</strong></li><li>linking claim to the Pod</li></ul><p>In the following case, we have a storage class <em>ebs-gp3</em>. A PVC <em>app-data-pvc</em> is created and later linked to <em>demo-pod</em>.</p><pre># see storage classes <br>$ kubectl get storageclass<br><br>NAME       PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE<br>ebs-gp3    ebs.csi.aws.com         Delete          WaitForFirstConsumer   true                   5m<br><br># create pvc specific to a storage class <br>$ cat demo-pvc.yaml<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: app-data-pvc<br>spec:<br>  # storageClassName: ebs-gp3 &lt;-- one can specify specific storage class<br>  #                              when unspecified default storage class is used<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 5Gi<br>      <br><br># linking claim to the pod<br># cat demo-pod.yaml<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: demo-pod<br>spec:<br>  containers:<br>  - name: app<br>    image: busybox:1.36<br>    command: [&quot;sh&quot;, &quot;-c&quot;, &quot;echo &#39;hello from persistent storage&#39; &gt; /data/hello.txt; sleep 3600&quot;]<br>    volumeMounts:<br>    - name: app-data           # &lt;-- container needs app-data volume<br>      mountPath: /data<br>  volumes:<br>  - name: app-data             # &lt;-- app-data volume is linked to <br>    persistentVolumeClaim:<br>      claimName: app-data-pvc  #     the pvc that we created earlier<br><br># a persistent volume would be created<br>$ kubectl get pv<br>NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                  STORAGECLASS   AGE<br>pvc-1axxxx   5Gi        RWO            Delete           Bound    default/app-data-pvc   ebs-gp3        35s<br><br>## To view storage class related information use <br>$ kubectl describe storageclass ebs-gp3<br>$ kubectl get storageclass ebs-gp3 -o yaml</pre><p><strong>Scenario 1 : The pod ran into error and got scheduled on a new pod, will my data survive?</strong></p><p>Yes, the data will survive. Even if the user deletes the pod! But if someone deletes the pvc then we will be in trouble. This is because we have “Delete” reclaim policy on the Persistent-Volume (PV).</p><p><strong>Scenario 2: The pod filled up the disk and it can not write any more data</strong></p><p>In this case, if our storage is expandable then we just need to update related pvc.</p><pre># see storage classs<br>$ kubectl get storageclass<br><br>NAME       PROVISIONER             RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE<br>ebs-gp3    ebs.csi.aws.com         Delete          WaitForFirstConsumer   true                   5m<br><br># in our case ALLOWVOLUMEEXPANSION is true</pre><p><strong>Scenario 3: The pod runs two containers; can they share the volume?</strong></p><p>Yes they can; see following sample YAML file</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: two-container-app<br>spec:<br>  containers:<br>  - name: app<br>    image: my-app:1.0<br>    volumeMounts:<br>    - name: app-data<br>      mountPath: /var/lib/app<br><br>  - name: log-shipper<br>    image: busybox:1.36<br>    command: [&quot;sh&quot;, &quot;-c&quot;, &quot;tail -F /logs/app.log&quot;]<br>    volumeMounts:<br>    - name: app-data<br>      mountPath: /logs<br>      readOnly: true<br><br>  volumes:<br>  - name: app-data<br>    persistentVolumeClaim:<br>      claimName: app-data-pvc</pre><p><strong>Scenario 4: Instead of creating pods, I am using deployment with 3 replicas. What would happen?</strong></p><p>Our PVC specifies “ReadWriteOnce” meaning only one node can mount the volume. So if nodeA mounted volume first then replicas scheduled on nodeA would be able to use the volume. Other replicas would stay in waiting state.</p><pre># create pvc specific to a storage class <br>$ cat demo-pvc.yaml<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: app-data-pvc<br>spec:<br>  accessModes:<br>    - ReadWriteOnce             &lt;-- see access mode<br>  resources:<br>    requests:<br>      storage: 5Gi</pre><p>There are 4 access modes</p><ul><li>ReadWriteOnce</li><li>ReadOnlyMany — many nodes can mount volume as read-only</li><li>ReadWriteMany</li><li>ReadWriteOncePod</li></ul><p>We might be tempted to switch to “ReadWriteMany” mode, but it can create conflicts if both replicas open and write the same file. Most apps can work without having a persistent-volume. In case if we need one then we would have to make sure that each pod write in a different file/directory.</p><p>The problem gets even for mission critical applications like databases. This is where “<strong>Statefulsets</strong>” are useful.</p><p><strong>Scenario 4: As it’s tricky to scale application and bind volume; how can I configure my application? Can we configure an application without writing data on a volume?</strong></p><p>There are two ways to solve this problem:</p><ul><li>Using environment variables</li></ul><p>For this, we create a map of variables and values in ConfigMap and fetch values from the configmap.</p><ul><li>Loading configuration in a file</li></ul><p>We utilize ConfigMap again where key is the name of the file and value is the content of the file.</p><p>Note that ConfigMap must not contain confidental information.</p><p>======</p><p>In this post, we covered following key concepts</p><ul><li>ephemeral storage</li><li>hostpath volume type</li><li>Persistent Volume Claim, Persistent Volume and Storage Class</li><li>Loading configuration using <strong>ConfigMap</strong></li></ul><p>References:</p><ul><li><a href="https://kubernetes.io/docs/concepts/storage/volumes/">https://kubernetes.io/docs/concepts/storage/volumes/</a></li><li><a href="https://kubernetes.io/docs/concepts/storage/persistent-volumes/">https://kubernetes.io/docs/concepts/storage/persistent-volumes/</a></li><li><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-volume-storage/">https://kubernetes.io/docs/tasks/configure-pod-container/configure-volume-storage/</a></li><li><a href="https://kubernetes.io/docs/tutorials/configuration/configure-persistent-volume-storage/">https://kubernetes.io/docs/tutorials/configuration/configure-persistent-volume-storage/</a></li><li><a href="https://commons.wikimedia.org/wiki/File:IBM_System_Storage_DCS3700_(17203388288).jpg">j_cadmus</a>, <a href="https://creativecommons.org/licenses/by/2.0">CC BY 2.0</a>, via Wikimedia Commons</li></ul><p>Other related posts</p><ul><li><a href="https://jigarr.medium.com/list/kubernetes-f5d0178b859a">https://jigarr.medium.com/list/kubernetes-f5d0178b859a</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=772f2bc8a5f6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes 101 — part 2]]></title>
            <link>https://jigarr.medium.com/kubernetes-101-part-2-7ba444d8ae2f?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ba444d8ae2f</guid>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Wed, 21 Jan 2026 22:32:10 GMT</pubDate>
            <atom:updated>2026-11-04T11:24:25.149Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes 101 : Pods, ReplicaSet and Deployment</h3><p>Pods is one of the most frequently used term in Kubernetes ecosystem. In this post, we will look into it.</p><p><strong>What are pods?</strong></p><p>Kubernetes document, describes a pod as “smallest deployable unit of computing”. Essentially, Every process needs CPU, memory and disk to perform tasks. A pod runs processes, which also require these resources. You can define the minimum and maximum <strong>resource limits</strong> a pod can use. These resource limits help the scheduler find an appropriate node. Here’s an example of a pod running two containers: nginx and process2. Notice that we have specified resource limit for the pod and a single container.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: frontend<br>spec:<br>  resources:<br>    limits:<br>      cpu: &quot;1&quot;<br>      memory: &quot;200Mi&quot;<br>    requests:<br>      cpu: &quot;1&quot;<br>      memory: &quot;100Mi&quot;<br>  containers:<br>  - name: nginx<br>    image: nginx:1.28.0<br>    resources:<br>      limits:<br>        cpu: &quot;0.5&quot;<br>        memory: &quot;100Mi&quot;<br>      requests:<br>        cpu: &quot;0.5&quot;<br>        memory: &quot;50Mi&quot;<br>  - name: process2<br>    image: fedora<br>    command:<br>      - sleep<br>      - inf</pre><p>When we run, kubectl apply command; the above pod will be scheduled on one of the nodes. We can see how many nodes our cluster has and on which node our pod got scheduled using following commands:</p><pre>$ kubectl get nodes --show-labels<br>NAME      STATUS    ROLES    AGE     VERSION        LABELS<br>worker0   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker0<br>worker1   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker1<br>worker2   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker2<br><br>$ kubectl get pods --output=wide<br>NAME          READY     STATUS    RESTARTS   AGE    IP           NODE<br>frontend    2/2       Running   0          1m    XX.XX.XX.XX   worker2</pre><p><strong>What are the advantages of running processes inside a pod?</strong></p><p>Software engineers deal with many processes daily. When an app crashes, the go to fix is to restart it. Kubernetes applies the same principle. Whenever a container runs into a problem, Kubelet will restart the pod.</p><pre>$ kubectl get pods --output=wide<br>NAME              READY    STATUS    RESTARTS   AGE   IP           NODE<br>frontend-1        2/2      Running   1          1m.   XX.XX.XX.XX   worker2</pre><p>But in certain scenarios, pod needs to be recreated. One of such scenario is when worker2 node is shutdown. The new pod will be scheduled on a different node than the previous one.</p><p>In our little lab scenario, this may not be a big problem but in workplace you would have big Kubernetes clusters. A single cluster would consist of several different types of nodes running different types of workloads. For example, AI related apps would run on expensive nodes with GPUs, other apps might need more memory/cpu/disk. In such scenario, we would need more control on where our pod will get scheduled. This is achieved by using labels and selectors. Basically, we label the nodes and specify selectors on the pod.</p><pre>$ kubectl get nodes --show-labels<br>NAME      STATUS    ROLES    AGE     VERSION        LABELS<br>worker0   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker0<br>worker1   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker1<br>worker2   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker2<br><br>$ kubectl label nodes worker0 disktype=ssd<br><br>$ kubectl get nodes --show-labels<br>NAME      STATUS    ROLES    AGE     VERSION        LABELS<br>worker0   Ready     &lt;none&gt;   1d      v1.13.0        ...,disktype=ssd,kubernetes.io/hostname=worker0<br>worker1   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker1<br>worker2   Ready     &lt;none&gt;   1d      v1.13.0        ...,kubernetes.io/hostname=worker2<br><br>$ cat frontend.yaml<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: frontend<br><br>spec:<br>  nodeSelector:<br>    disktype: ssd<br>  resources:<br>    .....<br><br><br>$ kubectl apply -f frontend.yaml<br><br>$ kubectl get pods --output=wide<br>NAME          READY     STATUS    RESTARTS   AGE    IP           NODE<br>frontend    2/2       Running   0          1m    XX.XX.XX.XX   worker0</pre><p>As our frontend is handling more traffic, eventually we would hit a threshold. Let’s say our frontend pod can not handle more than 1000 connections. We can obviously increase resource limits and even schedule our pod on a bigger node. But at some point, we would have to scale-up. Instead of starting one-more pod manually, we can leverage ReplicaSet.</p><p><strong>What is a ReplicaSet?</strong></p><p>ReplicaSet ensures that a specified number of pod replicas are running at all times. If a pod is deleted for any reason, the ReplicaSet automatically creates a replacement. For example, the following YAML file defines a ReplicaSet that maintains three pod replicas:</p><pre>apiVersion: apps/v1<br>kind: ReplicaSet<br>metadata:<br>  name: frontend<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      tier: frontend<br>  template:<br>    metadata:<br>      labels:<br>        tier: frontend<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:1.28.0<br>        resources:<br>          limits:<br>            cpu: &quot;0.5&quot;<br>            memory: &quot;100Mi&quot;<br>          requests:<br>            cpu: &quot;0.5&quot;<br>            memory: &quot;50Mi&quot;<br>      - name: process2<br>        image: fedora<br>        command:<br>          - sleep<br>          - inf<br>      resources:<br>        limits:<br>          cpu: &quot;1&quot;<br>          memory: &quot;200Mi&quot;<br>        requests:<br>          cpu: &quot;1&quot;<br>          memory: &quot;100Mi&quot;<br><br>$ kubectl get pods<br>NAME                   READY     STATUS    RESTARTS   AGE       <br>frontend-97677-7ci7o   2/2       Running   0          1m       <br>frontend-97677-kzszj   2/2       Running   0          1m       <br>frontend-97677-qqcnn   2/2       Running   0          1m<br><br>$ kubectl get rs<br>NAME       DESIRED   CURRENT   READY   AGE<br>frontend   3         3         3       2m</pre><blockquote>On a side note: Kubernetes supports several resource types, Each resource type has a purpose. ReplicaSet is one of them. You can also define your own custom resources via CRDs (Custom Resource Definitions).</blockquote><p>Now, let’s say you are assigned a task to use newer version of nginx. In terms of YAML file, we would be replacing nginx:1.28.0 with nginx:1.29.0 and run kubectl command. We would notice a brief interruption. However, we can smoothen such interruption in Kubernetes with following approach:</p><ol><li>Create a new replica set with 0 replicas running nginx:1.29.0</li><li>On old replicaset, reduce 1 replica, on new replicaset increase 1 replica</li><li>Repeat until all pods are running the latest version.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lPduo53AGIS3JDOBZancrA.png" /></figure><p>We can achieve this by using <strong>Deployments</strong>. In addition to rollout, we can also rollback with ease. In the following, I will cover how to rollout changes using deployment.</p><pre># cat deployment.yaml<br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: frontend-deployment<br>  labels:<br>    app: nginx<br>spec:<br>  replicas: 3<br>  selector:<br>    matchLabels:<br>      tier: frontend<br>  template:<br>    metadata:<br>      labels:<br>        tier: frontend<br>    spec:<br>      containers:<br>      - name: nginx<br>        image: nginx:1.28.0            &lt;-- Single line change to update version<br>        resources:<br>          limits:<br>            cpu: &quot;0.5&quot;<br>            memory: &quot;100Mi&quot;<br>          requests:<br>            cpu: &quot;0.5&quot;<br>            memory: &quot;50Mi&quot;<br>      - name: process2<br>        image: fedora<br>        command:<br>          - sleep<br>          - inf<br>      resources:<br>        limits:<br>          cpu: &quot;1&quot;<br>          memory: &quot;200Mi&quot;<br>        requests:<br>          cpu: &quot;1&quot;<br>          memory: &quot;100Mi&quot;<br><br>$ kubectl apply -f ./deployment.yaml<br><br>$ kubectl get deployments<br>NAME                  READY   UP-TO-DATE   AVAILABLE   AGE<br>frontend-deployment   3/3     0            0           1m<br><br># update deployment.yaml file with nginx:1.29.0<br><br>$ kubectl apply -f ./deployment.yaml<br><br>$ kubectl rollout status deployment/frontend-deployment<br>Waiting for rollout to finish: 1 out of 3 new replicas have been updated...<br><br><br>## you can also see the rollout history and rollback if you want<br>$ kubectl rollout history deployment/nginx-deployment<br><br>$ kubectl rollout undo deployment/nginx-deployment</pre><p>You can learn more about deployments in the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#creating-a-deployment">Kubernetes documentation</a>. When we rollout changes, old pods would be deleted. But what would happen to the data on them? We will explore this in our next post.</p><p>In this blog, we covered</p><ul><li>Resource limits</li><li>ReplicaSet</li><li>Deployment</li></ul><p><strong>References</strong>:</p><ul><li><a href="https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/">https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/</a></li><li><a href="https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/">https://kubernetes.io/docs/concepts/workloads/controllers/replicaset/</a></li><li><a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">https://kubernetes.io/docs/concepts/workloads/controllers/deployment/</a></li><li><a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#-strong-api-groups-strong-">https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.35/#-strong-api-groups-strong-</a> API documentation for v1.35</li><li><a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/">https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/</a></li></ul><p>Other related posts can be found at</p><ul><li><a href="https://jigarr.medium.com/list/kubernetes-f5d0178b859a">Kubernetes series</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ba444d8ae2f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes 101 : Key Concepts]]></title>
            <link>https://jigarr.medium.com/kubernetes-101-d51030a56959?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d51030a56959</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Tue, 13 Jan 2026 14:53:35 GMT</pubDate>
            <atom:updated>2026-11-04T11:05:06.187Z</atom:updated>
            <content:encoded><![CDATA[<p>The best way to leverage any tool is to understand the fundamentals. This blog covers the following key concepts:</p><ul><li>Nodes: control plane and data plane</li><li>Key components of Kubernetes</li><li>Pods</li></ul><p>A Kubernetes cluster consists of multiple nodes. Consider a cluster with five nodes. These nodes are either part of (i) control plane or (ii) data plane. Control plane are essential internal services such as etcd database, API server etc. Data plane consists of nodes which would run your applications.</p><p>Every node run key process called kubelet and kube-proxy. Kubelet does serveral things like</p><ul><li>gather information about machine such as Operating System, Architecture, CPU/memory etc</li><li>creates pods on node</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OgWrdwxA7reZk31jrkLMFg.png" /><figcaption>A sample Kubernetes cluster with 3 nodes</figcaption></figure><p>Now, consider a scenario where user-a wants to run a web server.</p><p>Traditionally, user would pick a machine, and install a web server like Apache or Nginx directly. In Kubernetes, the web server runs inside a pod, defined via a YAML file.</p><pre># YAML file to specify a pod<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: user-a-web-server<br>spec:<br>  containers:<br>  - name: web-server<br>    image: nginx</pre><ol><li>The request goes to the <strong>API server,</strong> which authenticates the user and checks permissions.</li><li>API server records this in the <strong>etcd database</strong> (key-value store)</li><li>API server has list of <strong>controllers</strong> who want to get notified whenever some changes occur in database. <br>In this sense, controllers (such as ReplicaSet controller, Cronjob controller, schedulers, kubelet) are watching for relevant changes to database. Controllers are running event loop. As soon as any relevant event occurs, they check the difference and act accordingly.</li><li>Upon notification, <strong>Schedulers</strong> assign pods to node-A and writes to etcd database via API server. API server informs watchers. In this case, kubelet on node-A would get notified about the change.</li><li>The <strong>kubelet</strong> on node-A starts web-server container using container-runtime.</li></ol><p>Finally, we have a web-server pod running on node-A.</p><p>In this blog, I covered basic idea of nodes, pods and 3 components of the Kubernetes control plane. Checkout <a href="https://medium.com/@jigarr/kubernetes-101-part-2-7ba444d8ae2f">part-2 </a>to learn more about pods.</p><p>References:</p><ul><li><a href="https://kubernetes.io/docs/concepts/architecture/nodes/">https://kubernetes.io/docs/concepts/architecture/nodes/</a></li><li><a href="https://kubernetes.io/docs/concepts/workloads/pods/">https://kubernetes.io/docs/concepts/workloads/pods/</a></li><li><a href="https://kubernetes.io/docs/concepts/overview/components/">https://kubernetes.io/docs/concepts/overview/components/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d51030a56959" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Terraform Terminology]]></title>
            <link>https://awstip.com/terraform-terminology-e67341ed7deb?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/e67341ed7deb</guid>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Tue, 28 Jan 2025 19:31:15 GMT</pubDate>
            <atom:updated>2025-03-03T16:06:21.204Z</atom:updated>
            <content:encoded><![CDATA[<h3>Planning projects with Terraform</h3><p>Terraform Cloud allows one to Manage multiple <strong>organizations’</strong> cloud infrastructure. The following image demonstrates various important terminologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5wl2p6MC-M_Vpny9Ea6mSw.png" /></figure><p>The cloud infrastructure can be sorted into multiple projects. For example, ProjectA needs 5 virtual machines in production but 1 for the staging environment. In this case, consider creating 2 <strong>workspace</strong>s: Prod-A and Dev-A. The number of virtual machines can be specified as a variable specific to a workspace.</p><p>Terraform needs permission to access your cloud infrastructure to create resources. One can store authentication-related data as Environment Variables or hard-code them in a file. What if you can store these tokens and allow different workspaces to access them? This is where <strong>Variable Sets</strong> are extremely helpful.</p><p>Using Terraform, one can define the infrastructure needed to support projectA. The specifications for the Production and Staging environment would be slightly different. The variable part of the infrastructure can be defined as variables. By doing this, we avoid unnecessary repetition and reuse the code. In the following section, I will cover Terraform’s Inputs and Outputs.</p><h3>Inputs to Terraform</h3><h4>using Variables</h4><p>We can define variables in a dedicated file “variables.tf” file as follows</p><pre>### In variables.tf file<br>variable &quot;instance_name&quot; {<br>  description = &quot;Value of the Name tag for the EC2 instance&quot;<br>  type        = string<br>}<br><br>### To use variable; use following synatax<br>Name = var.instance_name<br><br><br>## if the default value is not specified then Terraform will ask for one<br> ➜  terraform plan<br>var.instance_name<br>  instance_name<br><br>  Enter a value: <br><br>### Use -var flag to specify values</pre><p>Overriding Variable Sets (Terraform Cloud)</p><h4>using Data source</h4><p>Data Source allows one to find</p><p>Terraform to use information defined outside of Terraform</p><pre>### Example from AWS provider<br>###  https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#example-usage<br>data &quot;aws_ami&quot; &quot;ubuntu&quot; {<br>  most_recent = true<br><br>  filter {<br>    name   = &quot;name&quot;<br>    values = [&quot;ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*&quot;]<br>  }<br><br>  filter {<br>    name   = &quot;virtualization-type&quot;<br>    values = [&quot;hvm&quot;]<br>  }<br><br>  owners = [&quot;099720109477&quot;]<br>}</pre><h3>Outputs from Terraform</h3><p>Once you run, the “terraform apply” command, it would create infrastructure resources. Sometimes, you want to save information like</p><ul><li>IP addresses of virtual machines</li><li>IDs of certain resources</li></ul><p>By using the “output” block, the information gets stored in the <a href="https://medium.com/@jigarr/terraform-state-file-938473d73f0a">Terraform state</a> file. Use the “terraform output” command to view saved information.</p><pre>### Defining output in outputs.tf file<br>output &quot;route_table_ID&quot; {<br>  value = aws_route_table.AppRouteTable.route_table_ID<br>}<br><br><br>### To see outputs<br>➜  terraform output<br>route_table_ID = &quot;XXXXXX&quot;</pre><p>Reference</p><ul><li><a href="https://developer.hashicorp.com/terraform/cloud-docs/projects">terraform projects</a></li><li><a href="https://developer.hashicorp.com/terraform/cloud-docs/workspaces">terraform workspaces</a></li><li><a href="https://developer.hashicorp.com/terraform/language/data-sources">terraform data-sources</a></li><li><a href="https://developer.hashicorp.com/terraform/tutorials/cloud-get-started/cloud-change">terraform modify infrastructure</a></li><li><a href="https://developer.hashicorp.com/terraform/tutorials/aws-get-started/aws-variables">terraform aws-variables</a></li><li><a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#example-usage">terraform providers instance#example-usage</a></li><li><a href="https://developer.hashicorp.com/terraform/language/data-sources">terraform data-sources</a></li><li><a href="https://learn.kodekloud.com/user/courses/learn-by-doing-aws-workshop-with-terraform">kodekloud.com course aws-workshop-with-terraform</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e67341ed7deb" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/terraform-terminology-e67341ed7deb">Terraform Terminology</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Infra using Terraform State files]]></title>
            <link>https://jigarr.medium.com/terraform-state-file-938473d73f0a?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/938473d73f0a</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Thu, 23 Jan 2025 00:52:23 GMT</pubDate>
            <atom:updated>2025-01-26T23:27:24.025Z</atom:updated>
            <content:encoded><![CDATA[<p>In the post <a href="https://medium.com/@jigarr/1-managing-infra-with-terraform-9423e877f0c6">managing-infra-with-terraform</a>, I mentioned that Terraform state file keeps an inventory of resources managed by Terraform. <a href="https://www.terraform.io/">Terraform</a> helps to automate infrastructure on various cloud providers.</p><h3><strong>Securely store the State file</strong></h3><p>By default, Terraform generates “terraform.tfstate” file. This is fine for small personal projects. However, for big organizations it would make sense to put terraform.tfstate file in a central location.</p><p><strong>How about Github/Gitlab?</strong></p><p>The terraform state has password/token etc in plaintext. Therefore, one needs to store it securely. This is why, It is recommended to use encrypted place to store the state file. Additionally, Terraform uses locking mechanism to prevent multiple people from making changes to the state file at the same time. In the case of AWS, the combination of S3 and DynamoDB can be used to store the state file. Alternatively, one can also use Terraform cloud.</p><h3>Fetch information from the State file</h3><p>Assume, project-A has been setup and user has ran “terraform init; terraform apply” command. You can use terraform command to get the full list of resources that are managed by terraform.</p><pre> ➜  terraform state list<br>aws_instance.test_vm_1<br>aws_s3_bucket.test_bucket<br>....</pre><p>What if someone created resources by other means?</p><p>On one hand, Project-A consists of various resources. On the other hand, we have cloud-infrastructure.</p><ul><li>If a new resource was added to our cloud-infrastructure using other methods then Terraform would not know about those changes. Terraform can only manage resources that are specified in the Project.</li><li>If a new resource is added to Project-A then upon running “terraform apply”, it would get created.</li></ul><p>When a resource is created, ID gets generated which can be different in each run. Terraform stores ID information in terraform.tf file. Using ID, Terraform can find if the resource has been generated or not.</p><p>Assume we created a virtual-machine using Terraform. If we delete it using website and run “terraform apply” command; it would create a new virtual-machine.</p><h3>Add resource to the State file</h3><p>If a resource was created on the cloud-infrastructure by command-line or website directly then Terraform State file would not have any information about such resources. But we can add them to state file in 2 steps:</p><ol><li>Add resource in the project</li><li>Run “terraform import ” command</li></ol><p><strong>References</strong></p><ul><li><a href="https://medium.com/@ojranjankr/terraform-state-locking-using-s3-and-dynamodb-01f57fa7b9d3">https://medium.com/@ojranjankr/terraform-state-locking-using-s3-and-dynamodb-01f57fa7b9d3</a></li><li><a href="https://developer.hashicorp.com/terraform/language/state/locking">Terraform Documentation on — state locking</a></li><li><a href="https://learn.kodekloud.com/user/courses/terraform-associate-certification-hashicorp-certified">kodekloud course for terraform</a> certification</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=938473d73f0a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing Infra with Terraform]]></title>
            <link>https://awstip.com/1-managing-infra-with-terraform-9423e877f0c6?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/9423e877f0c6</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[terraform]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Mon, 20 Jan 2025 18:00:53 GMT</pubDate>
            <atom:updated>2025-03-03T15:53:31.996Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*q8-zyj-_O9c2MFnifZz8iw.png" /></figure><p>Every IT company needs a place to run its website, internal projects, client-facing websites, database, and many other things.<br>To support this, networks need to be created, machines need to be started up with certain memory, CPU, and software, and so on. These individual components lay the foundation for an IT company’s software infrastructure.</p><p>In the case of the Cloud, all of these resources can be specified in a text file (Checkout my earlier post <a href="https://jigarr.medium.com/save-your-private-cloud-setup-intro-to-infrastructure-as-code-4fa89a23ecec">intro-to-infrastructure-as-code</a>). This text file is processed by tools like Terraform to create various infrastructure components.</p><p>Let’s take an example: you want to create a bucket to store data on different cloud platforms like AWS, GCP, and, Azure. Assuming, Terraform has been installed locally, We can do this with Terraform in 3 steps:</p><ol><li>Download the Terraform plugin for AWS, GCP, and, Azure</li><li>Add text file to create a bucket on AWS, GCP, and, Azure</li><li>Run “terraform apply” to create buckets</li></ol><p>The plugins are also called Terraform provider. A full list of various providers at <a href="https://registry.terraform.io/browse/providers">Terraform Regsitry</a>. Using “AWS” terraform <strong>providers</strong>, one can create various resources like S3, RDS, EC2 and so on.</p><pre><br><br><br>## From https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket<br>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br>  bucket = &quot;my-tf-test-bucket&quot;<br><br>  tags = {<br>    Name        = &quot;My bucket&quot;<br>    Environment = &quot;Dev&quot;<br>  }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5cSLXb33wiwmiZeimwZOOA.png" /><figcaption>A Terraform provider consists of several resources</figcaption></figure><h3>Step 1: Download plugins</h3><p>Create a blank folder for our little project. Specify plugins/providers that we want to use in provider.tf file. To get started, we can specify credentials to use with AWS, GCP and Azure as environment variables and configure <strong>provider.tf</strong> file appropriately.</p><pre>## provider.tf<br>## From https://registry.terraform.io/providers/hashicorp/aws/latest/docs<br>provider &quot;aws&quot; {<br>  region     = &quot;us-west-2&quot;<br>  access_key = &quot;my-access-key&quot;<br>  secret_key = &quot;my-secret-key&quot;<br>}</pre><p>In the following screenshot, all the providers used by Project A are listed in provider.tf. Upon running the “terraform init” command, Terraform would download providers in the “.terraform” folder. Terraform can download providers from Registry or it can get it from local-file-system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*t-1u-5-Eym816dzu5qU0mg.png" /><figcaption>State of ProjectA after running “Terraform init”</figcaption></figure><h3>Step 2: Specify resources to create</h3><p>For a small project like this, we can provide the names of the data bucket for AWS, GCP, and Azure in the “main.tf”. It can also be in separate files like “aws.tf”, “gcp.tf” and so on.</p><h3>Step 3: run “terraform apply” command</h3><p>To create resources, run “terraform apply”. Terraform keeps track of resources in a state file named “terraform.tfstate”. It’s a good idea to store the “terraform.tfstate” file on the cloud service like Terraform Cloud or AWS S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*brRR-rkz2rGwO8TgEK7N2Q.png" /></figure><p>The upcoming medium blog will provide more information on the state file.</p><h3>Reference</h3><ul><li><a href="https://developer.hashicorp.com/terraform/language/providers">Terraform — providers</a></li><li><a href="https://github.com/kodekloudhub/terraform-for-beginners-course">kodekloud terraform-for-beginners-course</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9423e877f0c6" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/1-managing-infra-with-terraform-9423e877f0c6">Managing Infra with Terraform</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Managing permissions to your Cloud | Intro to Identity and Access Management | IAM]]></title>
            <link>https://jigarr.medium.com/managing-permissions-to-your-cloud-intro-to-identity-and-access-management-iam-d6f905a078e0?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/d6f905a078e0</guid>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[aws-cloud]]></category>
            <category><![CDATA[access-management]]></category>
            <category><![CDATA[iam-roles]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Thu, 22 Sep 2022 04:05:51 GMT</pubDate>
            <atom:updated>2022-09-22T04:08:53.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gQChKgGE87-ebg48S1Z2ew.png" /></figure><p>Lots of companies run their applications &amp; store data in Cloud. Employees and customers of a company would also interact with the Cloud. Setting up rules and regulations around who can do what is critical.</p><p>The question</p><ul><li>Who — deals with identifying the person. The username/password combination is one of the most popular ways to identify a person. Smartphones have taken it up a notch by using fingerprints and scanning faces. To call a REST endpoint, one can use an <strong>Access Key</strong> or API Key. All of these different solutions are part of an <strong>Authentication</strong> framework or Identity Management.</li><li>What — deals with ensuring that person-A has visibility to only allowed Cloud resources. For example, a developer may not need access to billing information. A salesperson does not need access to create a Virtual Machine. The above statements can be mapped to a rule or <strong>permission</strong> file, which can be parsed and enforced by a Cloud provider. Management and enforcement of permissions are part of an <strong>Authorization</strong> framework or Access Management.</li></ul><p>Combine both of the concepts together, and you get <strong>Authentication and Authorization</strong> or <strong>Identity and Access Management (IAM)</strong>. Here is a list of some of the popular IAM tools (from <a href="https://www.gartner.com/reviews/market/access-management">Gartner’s market review</a>)</p><ul><li>Okta SSO — Auth0</li><li>Microsoft Azure Active Directory</li><li>PingOne Cloud Platform</li><li>Cisco Duo Access</li></ul><p><strong>Important Terminologies</strong></p><p>Assume that person-X is trying to create/delete/access a Virtual Machine. Cloud Provider would check the permissions using the IAM component to find out, “Should person-X create/delete/access a Virtual Machine?”. In this example,</p><ul><li>Person-X is known as a <strong>Principal</strong></li><li>Virtual Machine is a <strong>resource</strong> in the Cloud</li><li>Create/delete/access is an <strong>action</strong> or operation</li></ul><p>In the case of IAM, <strong>permissions</strong> are created. Example of permissions:</p><ul><li>Create/delete/access a VM with specific configuration</li><li>Allow read-only access to database-A</li><li>Deny access to the super-secret database</li></ul><p>These permissions can be grouped into a <strong>policy </strong>which can be attached to a user.</p><p>What if person-X needs ten people to work on a project? Instead of attaching a policy for each user, one can</p><ul><li>create a <strong>user-group</strong> for person-X’s team</li><li>attach policy to the user-group</li><li>add users to the user-group</li></ul><p><em>Side-note</em></p><p><em>It is essential to take time while defining permissions. One should ideally follow </em><strong><em>the principle of least privilege</em></strong><em>, which states that a user should be given the least amount of permissions. Add more permissions later on if needed.</em></p><p><strong>Identity and Access Management in AWS</strong></p><p>In the case of AWS, IAM is a dedicated module. One can define policies and permissions using IAM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*DJAxMm5rAaLOb5fOHB__Gw.png" /><figcaption>A screenshot of sample permissions from AWS Console</figcaption></figure><p>IAM can also assist with</p><ul><li>Onboarding a user</li><li>Add user to a group</li><li>Attach permissions to the group or user or both</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*s4Dpml5F4i22Z8tYmaZc1w.png" /><figcaption>A screenshot of the user creation screen from the AWS console</figcaption></figure><p>Consider the following scenario: user-X is part of group-A and group-B.</p><ul><li>Group-A has a policy that allows create a VM action &amp; access a database</li><li>Group-B has a policy that denies create a VM action</li></ul><p>What would you do if user-X wants to create a VM, access database, and create a subnet?</p><p>As one policy allows VM creation, but the other does not. When user-X tries to create a VM, the action should be denied. User-X should be able to access a database. As none of the policies linked to User-X states anything for create a subnet action, it should be denied. IAM follows the same logic.</p><ul><li>deny an action if any policy linked to a user has a deny permission</li><li>allow an action only if any policy linked to the user explicitly has an allow permission</li><li>deny otherwise</li></ul><p>In this post, we looked at lots of different key concepts, such as</p><ul><li>Authentication, Authorization</li><li>Identity &amp; access management</li><li>Principle — Resource — Action</li><li>Permission — Policy</li><li>User-group</li><li>Principle of least privilege</li><li>What to do when one policy denies an action, but another policy allows it?</li></ul><p><strong>References</strong></p><p>Blogs</p><ul><li>Wike, R., Richards, O., Macy, M., Waweru, E., Coulter, D., &amp; Adman, N. (2022, September 6).<strong> Authentication vs. authorization</strong> — Microsoft Entra. Retrieved September 20, 2022, from <a href="https://learn.microsoft.com/en-us/azure/active-directory/develop/authentication-vs-authorization">https://learn.microsoft.com/en-us/azure/active-directory/develop/authentication-vs-authorization</a></li><li>Wikipedia contributors. “<strong>Principle of Least Privilege.</strong>” <em>Wikipedia</em>, 14 Sept. 2022, <a href="https://en.wikipedia.org/wiki/Principle_of_least_privilege">Principle_of_least_privilege</a></li><li>What is IAM? — AWS <strong>Identity and Access Management</strong>. (n.d.). Retrieved September 16, 2022, from <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html">https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction.html</a></li><li>Managing <strong>access keys for IAM users</strong> — AWS Identity and Access Management. (n.d.). Retrieved September 21, 2022, from <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html">https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html</a></li><li>Gartner, Inc. (n.d.). Access Management Reviews 2022 | Gartner Peer Insights. Retrieved September 21, 2022, from <a href="https://www.gartner.com/reviews/market/access-management">https://www.gartner.com/reviews/market/access-management</a></li></ul><p>Videos</p><ul><li><strong>Highly recommended — </strong>Amazon Web Services. (<strong>2013</strong>, November 26). <strong><em>Access Control for the Cloud: AWS Identity and Access Management (IAM)</em></strong><em> (SEC201) | AWS re:Invent 2013</em> [Video]. Retrieved September 20, 2022, from <a href="https://www.youtube.com/watch?v=4OpZmBp9S0k&amp;feature=youtu.be">https://www.youtube.com/watch?v=4OpZmBp9S0k&amp;feature=youtu.be</a></li><li>Events, A. (2019, December 9). <em>AWS re:Invent 2019: Access control confidence: Right access to the right things (SEC316-R1)</em> [Video]. Retrieved September 19, 2022, from <a href="https://www.youtube.com/watch?v=XO4CALyzbVM&amp;feature=youtu.be">https://www.youtube.com/watch?v=XO4CALyzbVM&amp;feature=youtu.be</a></li><li><em>AWS re:Invent 2019: [REPEAT 1] </em><strong><em>Getting started with AWS identity</em></strong><em> (SEC209-R1)</em>. (2019, December 10). [Video]. Retrieved September 19, 2022, from <a href="https://www.youtube.com/watch?v=Zvz-qYYhvMk&amp;feature=youtu.be">https://www.youtube.com/watch?v=Zvz-qYYhvMk&amp;feature=youtu.be</a></li><li>Amazon Web Services. (2014, November 14). <em>AWS re:Invent 2014 | (SEC305) </em><strong><em>IAM Best Practices</em></strong> [Video]. Retrieved September 17, 2022, from <a href="https://www.youtube.com/watch?v=ZhvXW-ILyPs&amp;feature=youtu.be">https://www.youtube.com/watch?v=ZhvXW-ILyPs&amp;feature=youtu.be</a></li><li>Amazon Web Services. (2015, October 12). AWS re:Invent 2015: <strong>How to Become an IAM Policy Ninja</strong> in 60 Minutes or Less (SEC305). Retrieved September 17, 2022, from <a href="https://www.youtube.com/watch?v=Du478i9O_mc">https://www.youtube.com/watch?v=Du478i9O_mc</a></li><li>Amazon Web Services. (2018, November 28). <em>AWS re:Invent 2018: [REPEAT 1] </em><strong><em>Become an IAM Policy Master</em></strong><em> in 60 Minutes or Less (SEC316-R1)</em> [Video]. Retrieved September 17, 2022, from <a href="https://www.youtube.com/watch?v=YQsK4MtsELU&amp;feature=youtu.be">https://www.youtube.com/watch?v=YQsK4MtsELU&amp;feature=youtu.be</a></li></ul><p>Image</p><ul><li>File:Airport security check.svg — Wikimedia Commons. (2019, January 11). Retrieved September 18, 2022, from <a href="https://commons.wikimedia.org/wiki/File:Airport_security_check.svg#/media/File:Airport_security_check.svg">https://commons.wikimedia.org/wiki/File:Airport_security_check.svg#/media/File:Airport_security_check.svg</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d6f905a078e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intro to orchestration tools]]></title>
            <link>https://jigarr.medium.com/intro-to-orchestration-tools-5b88515221a3?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b88515221a3</guid>
            <category><![CDATA[orchestration]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Mon, 12 Sep 2022 11:18:34 GMT</pubDate>
            <atom:updated>2022-09-12T16:00:13.365Z</atom:updated>
            <content:encoded><![CDATA[<p>This post is a continuation of</p><ul><li><a href="https://jigarr.medium.com/divide-your-application-into-smaller-chunks-intro-to-microservice-docker-276ad91c830e">divide-your-application-into-smaller-chunks</a></li></ul><p>Let us assume we have a VM where you can run containers. However, after running X number of VMs, it may not be able to run any additional containers. To address this, you must spin up another VM (VM2) and run containers on it.</p><p>This setup comes with its challenges, such as:</p><ul><li>Containers on VM2 may need to talk to containers on VM1.</li><li>If VM1 needs to a restart then all the containers running on it, needs to be moved on another VM temporarily.</li><li>As the number of VMs grows, the management of containers will become problematic.</li></ul><p>These challenges are addressed by an <strong>Orchestration tool</strong>. Just like how in an orchestra, a conductor leads musicians to produce beautiful music, an Orchestration tool would decide</p><ul><li>on which machine a container would run</li><li>facilitate networking between containers</li></ul><p>If you want to run 5 containers of web app, orchestration tool would distribute 5 containers on the available machines. Orchestration tools are smart &amp; feature rich.</p><p>If one of the machines (let us say VM1) becomes unavailable, all the containers would be distributed between available machines. Requests would be forwarded to available containers only. Here also, you can set up health checks to classify healthy vs. non-healthy containers. Non-healthy containers can be restarted automatically !! Isn’t that neat?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*fLbPXPZlxnEbAoL0bVMU6g.jpeg" /><figcaption>U.S. Navy photo by Chief Photographer’s Mate Johnny Bivera, Public domain, via <a href="https://commons.wikimedia.org/wiki/File:US_Navy_060529-N-2383B-123_The_U.S._Navy_band_performs_during_Memorial_Day_ceremonies_held_in_the_amphitheater_of_Arlington_National_Cemetery.jpg">Wikimedia Commons</a></figcaption></figure><p>Examples of Orchestration tools</p><ul><li>Docker Swarm</li><li><a href="https://kubernetes.io/">Kubernetes</a> (Open Source tool designed by Google) = there are eight letters between k and s, which is why Kubernetes is also called k8s.</li><li>AWS <a href="https://docs.aws.amazon.com/whitepapers/latest/overview-deployment-options/amazon-elastic-container-service.html">Elastic Container Services</a></li><li>Redhat <a href="https://www.redhat.com/en/technologies/cloud-computing/openshift">OpenShift</a></li></ul><p>You don’t need to install Orchestration tools anymore. With few clicks, cloud providers offer orchestration tools, so you don’t have to worry about installation and upgradation.</p><p>Amazon Web Services offer the following managed solutions</p><ul><li>Elastic Kubernetes Service = Kubernetes managed by Amazon</li><li><a href="https://docs.aws.amazon.com/ROSA/latest/userguide/what-is-rosa.html">Openshift on AWS</a></li><li>Elastic Container Service</li></ul><p>In this post, we briefly looked at</p><ul><li>Orchestration tool</li></ul><p><strong>References</strong></p><p>Image</p><ul><li>Conductor leading orchestra image — <a href="https://commons.wikimedia.org/wiki/File:US_Navy_060529-N-2383B-123_The_U.S._Navy_band_performs_during_Memorial_Day_ceremonies_held_in_the_amphitheater_of_Arlington_National_Cemetery.jpg">File:US_Navy_060529-N-2383B-123_The_U.S._Navy_band_performs_during_Memorial_Day_ceremonies_held_in_the_amphitheater_of_Arlington_National_Cemetery.jpg</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b88515221a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Divide your application into smaller chunks | Intro to microservice & Docker]]></title>
            <link>https://jigarr.medium.com/divide-your-application-into-smaller-chunks-intro-to-microservice-docker-276ad91c830e?source=rss-a6fb2ddfac5e------2</link>
            <guid isPermaLink="false">https://medium.com/p/276ad91c830e</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[sofware-engineering]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Jigar R]]></dc:creator>
            <pubDate>Thu, 08 Sep 2022 04:45:13 GMT</pubDate>
            <atom:updated>2022-09-12T12:40:38.495Z</atom:updated>
            <content:encoded><![CDATA[<p>An application always starts small. As it matures, more features and code gets added and becomes larger. Eventually, the application gets divided into separate projects focusing on different key areas. Then, some parts of it can be deployed together and others separately.</p><p>Let’s talk about extreme scenarios: if applications are deployed together, it would be challenging to scale up. You can maybe get more VMs and replicate the setup. You may save money by deploying some parts of an application on a separate VM.</p><p>Another scenario is when your application is fragmented into pieces. We can call these pieces <strong>micro-services or microservice</strong>. Imagine a web app with dedicated VMs that deal with the login of users, another app that figures out recommendations per user, another app that handles various payment methods, and so on. A microservice on its own is a piece of the puzzle. It needs to be able to interact with other microservices to paint the whole picture. If you observe that payment microservices are getting busier, you can increase the number of microservices to meet the demand. Isn’t that awesome? Just like any process, microservices need the following items:</p><ol><li>resources such as CPU, memory, disk, port</li><li>security &amp; networking</li><li>instructions on what to do</li></ol><h3>Requirement 1: Resources such as CPU, memory, disk, port</h3><p>How about we create a VM per microservice?</p><ul><li>A microservice is micro. It needs cpu and disk. Let’s say 1 CPU and 100 MB disk space</li><li>A VM requires an Operating System — which needs more resources than our microservice needs</li><li>creating a VM per microservice is overkill as we would <strong>have to</strong> get more CPU and disk than we needed</li></ul><p><strong><em>Can we run our microservice just like a VM (but without Operating System)?</em></strong></p><p>The answer is yes. In 2007, Google engineers released Control Groups (cgroups). <strong>Cgroups</strong> can limit how much resources a process can use; it can measure how much resources are being used and restart processes safely by taking snapshots.</p><h3><strong>Requirement 2: Security &amp; networking</strong></h3><ul><li>Let’s say we gave a microservice1 access to /micros_service1/path. It should not be able to read /micro_service2/path.</li><li>Microservice1 would have access to the memory. We need some way to isolate memory so that microservice1 can not read other microservices’ memory data.</li><li>If microservice1 needs to talk to microservice3, how do we do network between microservices?</li></ul><p>Linux <strong><em>Namespaces</em></strong> (created in 2002) helps with above questions.</p><ul><li>limited disk access is facilitated by the Mount namespace</li><li>memory access is facilitated by the process ID namespace</li><li>network related things are handled by the network namespace</li></ul><p>There are other kinds of namespaces. Combine multiple namespaces to put a virtual fence around your microservice. To understand cgroups and namespaces in detail, check out the book “ <em>Linux Kernel Networking: Implementation and Theory by Rosen, Rami.”</em></p><p><strong>Docker</strong> (launced in 2013) combined the concepts of cgroups and namespace.</p><h3>Requirement 3: instructions on what to do ?</h3><p>With Docker, you would write a program in your favorite language, java/python/go. But you need to define how Docker can run your service. These instructions are stored in Dockerfile.</p><p>Let’s say you have a simple HTML file. We can run it on the Nginx server. The Dockerfile would look like following</p><pre>FROM nginx<br>COPY index.html /usr/share/nginx/html/</pre><p>Assuming you have installed docker on your machine. Run</p><ul><li>docker build — just like how a java program is packaged inside a jar file, docker will package our program inside an <strong>image</strong>. You can run 1, 2, 3, or however many microservices you want, all of them performing instructions found inside an image.</li><li>docker run will run microservice which is also called a <strong>container</strong>.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*znLxh6RK3ax7r3pf4VxXXQ.jpeg" /><figcaption>Image copied from <a href="https://pixnio.com/miscellaneous/colorful-container-export-business-warehouse-urban-sky-cargo">colorful-container-export-business-warehouse-urban-sky-cargo</a></figcaption></figure><p>You would run the following commands to run our microservice:</p><pre>docker build -t test .<br># -t option here is to name the image</pre><pre><br>docker run -d -p 20000:80 test<br>#    find an image with name &quot;test&quot; and use it to run a container<br># -d option to run command in the background<br># -p to bind 20000 port of your machine to port 80 of container</pre><p>If you went to localhost:20000 in the browser, you would see your index.html. You can even peek inside a container using docker exec command. You can also restrict how much memory and CPU a container can use. If you want to know more about docker, visit the official <a href="https://docs.docker.com/">docker docs</a>.</p><p><em>Interesting information</em></p><p><strong>Ed Robinson</strong> (author of the book Kubernetes on AWS), mentions that chroot (1979) paved the way for modern docker.</p><blockquote>Chroot provided very simple isolation for files. It can prevent access to files outside of the specified directory tree.</blockquote><h3>Sharing container images</h3><p>We often use an app store to find and download smartphone apps. In the same way, after a container image is created, it can be published to a registry. Other people can find a container image, use it to develop and run their micro-services. Examples of popular registries are <a href="https://hub.docker.com/">Docker Hub</a>, Elastic Container Registry, and Google’s Container Registry.</p><p><em>A malicious container image can pose security issues. Therefore, doing some research before using containers written by someone else is critical.</em></p><p>In the previous example, the very 1st line of the dockerfile:</p><pre>FROM nginx</pre><p>will look up the “nginx” image from a registry and download it on the machine. The default option for registry with docker tool is Docker hub.</p><p>In this post, we covered</p><ul><li>Microservice</li><li>Control Groups (cgroups) — to limit and track resource usage</li><li>Namespace</li><li>Docker</li><li>Image — Container</li><li>Registry for container images</li></ul><p>Remember that Docker is a tool that packages software into standard unit called container. Podman, Kaniko and many other tools are alternatives of Docker.</p><p><strong>References</strong></p><p>Blogs &amp; websites</p><ul><li>To understand cgroups and nginx must checkout this blog — Mauro, Tony. “<strong>What Are Namespaces and Cgroups, and How Do They Work?</strong>” <em>NGINX</em>, 16 July 2022, <a href="http://www.nginx.com/blog/what-are-namespaces-cgroups-how-do-they-work.">www.nginx.com/blog/what-are-namespaces-cgroups-how-do-they-work.</a></li><li>Microservice — <a href="https://aws.amazon.com/microservices/">microservices</a></li><li>Docker official page — <a href="https://docs.docker.com/get-started/">get-started</a></li><li>Sample Docker image — <a href="https://medium.com/myriatek/using-docker-to-run-a-simple-nginx-server-75a48d74500b">using-docker-to-run-a-simple-nginx-server</a></li><li>Container landscape on AWS — <a href="https://aws.amazon.com/containers/services/">services</a></li><li>Cgroups wikipedia — <a href="https://en.wikipedia.org/wiki/Cgroups">Cgroups</a></li></ul><p>Books</p><ul><li>Kubernetes on AWS book — Robinson, Ed. <strong><em>Kubernetes on AWS</em></strong>. Zaltbommel, Netherlands, Van Haren Publishing, 2018.</li><li>Networking related — Rosen, Rami. <strong><em>Linux Kernel Networking: Implementation and Theory</em></strong>. Apress, 2013.</li><li>Ovens, Steve. “<strong>The 7 Most Used Linux Namespaces</strong>.” <em>Enable Sysadmin</em>, 11 Mar. 2022, <a href="http://www.redhat.com/sysadmin/7-linux-namespaces.">www.redhat.com/sysadmin/7-linux-namespaces.</a></li></ul><p>Image</p><ul><li><a href="https://pixnio.com/miscellaneous/colorful-container-export-business-warehouse-urban-sky-cargo">colorful-container-export-business-warehouse-urban-sky-cargo</a> by Frank mcKenna</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=276ad91c830e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>