<?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 Ikram Khan on Medium]]></title>
        <description><![CDATA[Stories by Ikram Khan on Medium]]></description>
        <link>https://medium.com/@ikramkhan951?source=rss-c6c7c248471c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KGMOB0xkqYjiU4KQ37mrqg.png</url>
            <title>Stories by Ikram Khan on Medium</title>
            <link>https://medium.com/@ikramkhan951?source=rss-c6c7c248471c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 09:09:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ikramkhan951/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[Microservices on Steroids — The Epic Tale of Service Mesh and How it Helped Overcame the Challenges…]]></title>
            <link>https://medium.com/@ikramkhan951/service-mesh-efb110f1fb24?source=rss-c6c7c248471c------2</link>
            <guid isPermaLink="false">https://medium.com/p/efb110f1fb24</guid>
            <category><![CDATA[linkerd]]></category>
            <category><![CDATA[service-mesh]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[istio-service-mesh]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ikram Khan]]></dc:creator>
            <pubDate>Thu, 01 Dec 2022 11:24:58 GMT</pubDate>
            <atom:updated>2022-12-01T16:55:13.864Z</atom:updated>
            <content:encoded><![CDATA[<h3>Microservices on Steroids — The Epic Tale of Service Mesh and How it Helped Overcame the Challenges of Microservices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6umCLWL7NqjbjUNFbI3dew.png" /><figcaption>Credit: <a href="https://www.toptal.com/kubernetes/service-mesh-comparison">https://www.toptal.com/kubernetes/service-mesh-comparison</a></figcaption></figure><p>Service mesh is a concept which applies to micro-services. So, let’s start with them.</p><h3>Monolith to Microservices</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*Cjphrq9jJkjf95C1Zs2vqQ.png" /><figcaption>Credit: <a href="https://miro.medium.com/max/1000/1*7R3X6gEz2RLRf2ypJTp79w.png">https://miro.medium.com/max/1000/1*7R3X6gEz2RLRf2ypJTp79w.png</a></figcaption></figure><p>Let’s say we have an application, a huge monolith, single codebase, and multiple teams working on it. It contains all the features of your entire application. And let’s say we split that monolith and do a set of micro-services talking to each other and because we do that we get a lot of benefits, such as:</p><ul><li>Faster delivery due to smaller size</li><li>Isolation of services ensure that single micro-service does not crash the entire system</li><li>Flexibility</li><li>Improves culture as each team is working on a individual business logic</li><li>Scaling</li></ul><h4>Challenges of a Micro-service Architecture</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r2XEQrBWVwuvNm6FlJMALQ.png" /><figcaption>Credit: <a href="https://cdn.searchenginejournal.com/wp-content/uploads/2018/03/seo-challenges-606d8bc209177.png">https://cdn.searchenginejournal.com/wp-content/uploads/2018/03/seo-challenges-606d8bc209177.png</a></figcaption></figure><p>Since, we have converted a monolith architecture into a micro-service architecture, we also get a set of challenges. Such as:</p><ul><li>Fault tolerance</li><li>Distributed tracing</li><li>Security (policies, mTLS, patches)</li><li>Load balancing</li><li>Telemetrics</li></ul><h3>Service Discovery</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hidQWwoorseznO_beOsTPA.png" /><figcaption>Model Split into Micro-services</figcaption></figure><p>Let’s say you split your model into micro-services. Each micro service could be running on a different machine or a different VM, with its own IP address and port. How will one service get to know the IP addresses of other services? One option is to just hard code the IP address. But the problem is that in cloud if your container or VM is restarted or if your service has multiple copies, it will have different IP addresses after the restart or each copy will have a different IP address. So, of course you cannot hard-code it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n7yBkqvpOLpxeAdpv-iVKg.png" /><figcaption>Credit: <a href="https://cdn.wp.nginx.com/wp-content/uploads/2016/04/Richardson-microservices-part4-2_client-side-pattern.png">https://cdn.wp.nginx.com/wp-content/uploads/2016/04/Richardson-microservices-part4-2_client-side-pattern.png</a></figcaption></figure><p>What you essentially need is a registry of sorts. Let’s say you have a single service registry, and whenever any of the services comes up it starts. It will register itself to this registry by saying, “ Hey. My name is service A, and this is my IP address” . And when there is any other service which wants to talk to this service, it will look up and say, “Hey. I want to talk to service A. Can you give me the IP address of service A”. During this lookup the service registry will give back the IP address of service A and then the service D can talk to service A. And that is what this “connect” represents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-ej9Ph1dRQpKJXsNacOWg.png" /><figcaption>Credit: <a href="https://spring.io/cloud">https://spring.io/cloud</a></figcaption></figure><p>This is what we have the Spring Cloud project Eureka for. In this project, we have two components. The first component is an application, which is also called as Eureka server, which you deploy. This is a spring boot application that acts as your service registry. This is the application that all your clients and services will talk to, to register itself and to look up the other services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/463/1*zf9tZQ78vBjTEPNjOt6khQ.png" /><figcaption>Service Discovery</figcaption></figure><p>The second component is called a Eureka client. It’s a library that you need to add to each of the microservices projects. Once you do that, and when you start the service it will do the same thing. It will register to the Eureka server, and whenever the Eureka client wants to look up for a client from the server it will give back the IP address. But there are a few problems with this. Since Eureka server is a standalone application, you have to manage it. This is also a single point of failure now. Because if you have <em>n </em>micro-services, and all are talking to this single service registry, so even if for few minutes the service registry goes down, it can affect your entire system right. That’s why it’s a single point of failure and it needs to be highly available all the time. Hence, there is this PR awareness and clustering concepts available in Eureka server, where you can deploy multiple copies of the server. The other problem is that you need to add libraries and code to your micro-services for this entire system to work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*P9agYYnG30ThmdkBXo2f1Q.jpeg" /><figcaption>Credit: <a href="https://www.nexsoftsys.com/articles/images/spring-cloud/springcloud-large.jpg">https://www.nexsoftsys.com/articles/images/spring-cloud/springcloud-large.jpg</a></figcaption></figure><p>So, lets look at the example of services requiring scaling. Let’s say you have a service A which has multiple copies all running at the same time. Here you need to add this library called <em>ribbon </em>on your client, which will get all the addresses of all the copies from the registry. And then it will decide how to do load balancing between these copies. That is, it can first time choose to connect to copy one, and second time it might connect to copy two — and third time it might connect to copy three.</p><h3>Rolling Deployments</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UmUt1BjsfJjsXPTnNJ3ShQ.png" /><figcaption>Credit: <a href="https://www.youtube.com/watch?v=QiXK0B9FhO0">https://www.youtube.com/watch?v=QiXK0B9FhO0</a></figcaption></figure><p>Rolling deployments say that let’s say you have this version 1.0 of the service, and all your traffic is going to that. You want to be able to start a version 1.1, a new update to your service, and at the right time you want to be able to switch all that traffic from 1.0 to 1.1. You also want to ensure that while you do this transition, your services are not getting affected, and your traffic is still getting handled properly, while behind the scenes you are updating your service.</p><h3>Canary Deployments</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*GK6D09J8WUycLvV3rFogDQ.png" /><figcaption>Credit: <a href="https://miro.medium.com/max/661/0*QMwOW8NdTyoPYCnD.png">https://miro.medium.com/max/661/0*QMwOW8NdTyoPYCnD.png</a></figcaption></figure><p>Let’s say you have updated a feature, and you want to test it with a very small crowd before deploying it to a wider audience. And let’s say you want to expose your new feature only to 5% of the users. Somehow, you need to have an ability to push only 5% of your traffic into this new version of the service, and the rest of it, the 95%, will still go to your old service. And once you think that this new feature is now working really well, you will slowly migrate more and more traffic to this version 1.1, until you have migrated the entire hundred percent traffic to this new version. This concept is called canary deploys.</p><h3>Distributed Tracing</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FDAMqlxuP6Rv324vyN0AfA.png" /><figcaption>Credit: <a href="https://www.instana.com/media/Zipkin-distributed-tracing.png">https://www.instana.com/media/Zipkin-distributed-tracing.png</a></figcaption></figure><p>Another problem with micro-service architecture is now that you have flow of an application that can go through multiple microservices. How will you debug that in this case? So, whenever a request comes in, you need to be able to assign it a unique code called trace ID. Now every micro service, when it logs for that request, it needs to log with that unique code so that then you can trace your entire flow across all these services using that particular unique ID.</p><h3>Security</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aDw0yFHwCJbFbl7oG2bUig.jpeg" /><figcaption>Credit: <a href="https://www.zameen.com/blog/things-consider-before-hiring-security-guard.html">https://www.zameen.com/blog/things-consider-before-hiring-security-guard.html</a></figcaption></figure><p>Another challenge of micro services is security. How do you ensure that the two micro-services are using HTTPS when talking to each other? You need to install certificates on both these services for that. Also, there is this concept called certificate rotation. To ensure that if someone gets hold of your certificates they don’t always use your microservices, you need your certificates replaced or renewed every few days. Other security issue is called networking policies. How to ensure that if service A is only allowed to talk to service B, it is not talking with service C? You need to have sets of rules about which service can talk to which other service.</p><h3>Service Mesh</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fnvcpN_fUSEeX8y9Cqu_yQ.png" /><figcaption>Credit: <a href="https://www.redhat.com/cms/managed-files/service-mesh-1680.png">https://www.redhat.com/cms/managed-files/service-mesh-1680.png</a></figcaption></figure><blockquote>Do not burden my code with all these infrastructure related decisions</blockquote><p>Now that we have seen some of these challenges of micro-service architecture, let’s see how service mesh intends to solve all these challenges. All these things that we talked about are sort of administrative, infrastructure related or communication related, but not related to your actual business code/logic. We want some platform, some framework, or some code to take off all these responsibilities from within our application code and do it somewhere else on a different plane.</p><h3>Sidecar — The Confidante</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L4ptbtoECRRJIAMCoCBMBA.png" /><figcaption>Credit: <a href="https://d2bywgumb0o70j.cloudfront.net/2020/10/27/25a3227f717cd9e4ffc9bf4d865e9515_10adfb6a1ff145c0.png">https://d2bywgumb0o70j.cloudfront.net/2020/10/27/25a3227f717cd9e4ffc9bf4d865e9515_10adfb6a1ff145c0.png</a></figcaption></figure><p>Let’s assume initially we had a service A directly talking to service B. Now we have this application called sidecar that is always running in the same place where a micro-service is running. So service A will have its own program running along with it called a sidecar program. And similarly, there is a service B running and in the same machine, or same container, we’ll also have a similar program called sidecar running. Whenever service A wants to connect to service B, it will not connect to it directly. It will just always talk to the sidecar. Side car acts as a proxy for service A. It’s the sidecars responsibility to talk to the other services sidecar. This sidecar proxy is offloading all your communication or infrastructure related difficulties that we spoke about, from within your code to the sidecar.</p><h3>Control Plane — The Big Gun</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uJf77FHdCgkFQLgkKGTK2A.png" /><figcaption>Credit: <a href="https://blogs.mulesoft.com/dev-guides/microservices/what-is-a-service-mesh/">https://blogs.mulesoft.com/dev-guides/microservices/what-is-a-service-mesh/</a></figcaption></figure><p>Now let’s add one more component to this. Let’s say we have a control plane/control tower. Control plane could be a program which always manages these side cars. We don’t want to put the code in the sidecar, we want this sidecar to be managed by someone else called control plane. This control plane will be responsible for pushing all the configuration about service discovery, networking policies, traffic management, load balancing, certificates for mutual TLS authentication, and so on and so forth. The control plane takes care of all these problems and challenges we don’t want to deal with that within our code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*Qc272hDZHlwsGI889NrjFQ.png" /><figcaption>Credit: <a href="https://www.youtube.com/watch?v=QiXK0B9FhO0">https://www.youtube.com/watch?v=QiXK0B9FhO0</a></figcaption></figure><p>If we go one step even further, what we can do is since now we have this control tower component, this program which dynamically takes care of all these side cars, we can do all those things that we talked about. In this example, let’s say we have an updated service that we want to test out. We can ask the control tower to just send 1% of the traffic to this specific service, while the rest of the 99% traffic goes to the same stable service. Similarly, we can check the headers of the request. We can say if the request is coming from an iPhone, send it to service B, otherwise always send it to service A.</p><p>One more advantage of control tower and the sidecar is that since now your services are not talking to each other directly, sidecar can decide which communication protocols to use. In this case let’s say initially it was using HTTP 1, it can switch it to HTTP 2 or it can switch to gRPC.</p><p>You can understand the advantages of this when you have not just two or three micro-services, but when you have hundreds of services and your control plane is responsible for managing all of that. And there is not a single line of code that you have to write to manage these things. This whole concept of a control plane plus a sidecar is called a service mesh. Service mesh allows you to offload this heavy burden from your core on to a control plane.</p><h3>Example Service Mesh</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RhbbaSuCyT67iHX5WEPxNg.png" /><figcaption>Credit: <a href="https://codepull.com/wp-content/uploads/2019/11/Istio-Architecture.png">https://codepull.com/wp-content/uploads/2019/11/Istio-Architecture.png</a></figcaption></figure><p>One of the projects which implements this service mesh is called Istio and Envoy. Envoy is a project which acts as the sidecar. Then in the control plane you have this project called Istio. The configurations are TLS certificates are pushed down to the side cars. And all the metrics and network policies i.e. which services can talk to which other service are pushed down by the control plane. So Istio and Envoy combined are one such service mesh project.</p><h3>Wrapping up</h3><p>That’s it! That’s the responsibilities of service mesh. Service mesh is a mechanism by which you do not have to write the code for any of the challenges of micro-services. So service mesh is the framework, component or platform that will handle all of these issues for you.</p><h3>References</h3><ul><li><a href="https://istio.io/latest/about/service-mesh/">https://istio.io/latest/about/service-mesh/</a></li><li><a href="https://www.redhat.com/en/topics/microservices/what-is-a-service-mesh">https://www.redhat.com/en/topics/microservices/what-is-a-service-mesh</a></li><li><a href="https://cloud.google.com/architecture/service-meshes-in-microservices-architecture">https://cloud.google.com/architecture/service-meshes-in-microservices-architecture</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efb110f1fb24" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kaniko — An Advanced User Guide]]></title>
            <link>https://medium.com/@ikramkhan951/kaniko-an-advanced-user-guide-1ae8053a2bba?source=rss-c6c7c248471c------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ae8053a2bba</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kaniko]]></category>
            <category><![CDATA[k8s]]></category>
            <dc:creator><![CDATA[Ikram Khan]]></dc:creator>
            <pubDate>Wed, 26 Oct 2022 14:05:41 GMT</pubDate>
            <atom:updated>2022-10-26T14:12:32.590Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kaniko — An Advanced User Guide</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkfKPi2k9aTeRA-d7iOWbw.png" /><figcaption>Credit: <a href="https://www.infracloud.io/assets/img/Blog/Blog-updated-creatives/index-image-1200x628/build-container-images-with-kaniko-1200x628.png">https://www.infracloud.io/assets/img/Blog/Blog-updated-creatives/index-image-1200x628/build-container-images-with-kaniko-1200x628.png</a></figcaption></figure><h3>Introduction</h3><p>Kaniko is a daemonless container image builder that allows users to build container images, inside a container or Kubernetes cluster. Since Kaniko is not dependent on Docker daemon it creates container images in Kubernetes cluster in userspace without using Docker Daemon. It was a project initiated by Google to remove the need for elevated privileges when performing container image builds.</p><ul><li>Kaniko is independent of the Docker daemon.</li><li>Each command within a Dockerfile is executed in userspace.</li><li>Suitable for environments like the Kubernetes Cluster where running a Docker daemon safely is challenging.</li></ul><p>Let’s explore Kaniko!</p><h3><strong>Prerequisites?</strong></h3><ul><li>Kubernetes cluster</li><li>Dockerhub account</li><li>Config files (pod.yaml, volume.yaml, volume-claim.yaml)</li></ul><h3>How Kaniko works?</h3><p>Let’s dig into internals of Kaniko and explore about how does Kaniko launch containers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81U3eYZdNzur-tG5cUlHhA.png" /><figcaption>Credit: <a href="https://goglides.io/wp-content/uploads/2020/03/kaniko-how-it-works.png">https://goglides.io/wp-content/uploads/2020/03/kaniko-how-it-works.png</a></figcaption></figure><p>The filesystem from the base image is extracted to a local directory (e.g., /kaniko/imagename) by Kaniko once it has parsed the Dockerfile and retrieved the base image. The commands contained in the docker file are then translated into shell commands and used to build several stages. By carrying out these actions, Kaniko directly alters the local filesystem. This presents no problems because Kaniko is designed to run within an already-existing container, but if it were to run from within a host, things might not go well.</p><p>The procedure of taking a snapshot, compiling the change files into a tarball, and adding files to a layer map or whiteout then takes place. Kaniko uses a hashing algorithm that incorporates the file’s modification time (mtime) to detect whether the files have been modified.</p><p>Also, full instructs Kaniko to take a complete filesystem snapshot but by default time instructs Kaniko to perform an mtime-based filesystem snapshot.</p><p>Kaniko requires following instructions to build a Docker image:</p><ul><li>Path to Dockerfile</li><li>Path to build context</li><li>URL/Destination of the repository where the image will be pushed</li></ul><p>Let’s take deep dive into how Kaniko ACTUALLY works!</p><h3>Kaniko “Hello World” Refresher</h3><p><em>Step 1:</em></p><p>Prepare local mounted directory and create a simple Dockerfile in it</p><pre>$ mkdir kaniko &amp;&amp; cd kaniko<br>$ echo &#39;FROM ubuntu&#39; &gt;&gt; dockerfile<br>$ echo &#39;ENTRYPOINT [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]&#39; &gt;&gt; dockerfile<br>$ cat dockerfile<br>FROM ubuntu<br>ENTRYPOINT [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]<br>$ pwd<br>/home/&lt;user-name&gt;/kaniko # copy this path in volume.yaml file</pre><p><em>Step 2:</em></p><p>To authenticate with Docker registry create a Secret named “regcred”</p><pre>kubectl create secret docker-registry regcred --docker-server=&lt;your-registry-server&gt; --docker-username=&lt;your-name&gt; --docker-password=&lt;your-pword&gt; --docker-email=&lt;your-email&gt;</pre><p><em>Step 3:</em></p><p>Create resources in Kubernetes cluster:</p><pre># create persistent volume<br>$ kubectl create -f volume.yaml<br>persistentvolume/dockerfile created# create persistent volume claim<br>$ kubectl create -f volume-claim.yaml<br>persistentvolumeclaim/dockerfile-claim created# check whether the volume mounted correctly<br>$ kubectl get pv dockerfile<br>NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                      STORAGECLASS    REASON   AGE<br>dockerfile   10Gi       RWO            Retain           Bound    default/dockerfile-claim   local-storage            1m# create pod<br>$ kubectl create -f pod.yaml<br>pod/kaniko created<br>$ kubectl get pods<br>NAME     READY   STATUS              RESTARTS   AGE<br>kaniko   0/1     ContainerCreating   0          7s# check whether the build complete and show the build logs<br>$ kubectl get pods<br>NAME     READY   STATUS      RESTARTS   AGE<br>kaniko   0/1     Completed   0          34s<br>$ kubectl logs kaniko<br>➜ kubectl logs kaniko<br>INFO[0000] Resolved base name ubuntu to ubuntu<br>INFO[0000] Resolved base name ubuntu to ubuntu<br>INFO[0000] Downloading base image ubuntu<br>INFO[0000] Error while retrieving image from cache: getting file info: stat /cache/sha256:1bbdea4846231d91cce6c7ff3907d26fca444fd6b7e3c282b90c7fe4251f9f86: no such file or directory<br>INFO[0000] Downloading base image ubuntu<br>INFO[0001] Built cross stage deps: map[]<br>INFO[0001] Downloading base image ubuntu<br>INFO[0001] Error while retrieving image from cache: getting file info: stat /cache/sha256:1bbdea4846231d91cce6c7ff3907d26fca444fd6b7e3c282b90c7fe4251f9f86: no such file or directory<br>INFO[0001] Downloading base image ubuntu<br>INFO[0001] Skipping unpacking as no commands require it.<br>INFO[0001] Taking snapshot of full filesystem...<br>INFO[0001] ENTRYPOINT [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]</pre><p><em>Step 4:</em></p><p>If you have followed the steps mentioned above correctly an image will be built by Kaniko and pushed to Dockerhub. Pull that image from the Dockerhub to your local machine and run to test it</p><pre>$ sudo docker run -it &lt;user-name&gt;/&lt;repo-name&gt;<br>Unable to find image &#39;debuggy/helloworld:latest&#39; locally<br>latest: Pulling from debuggy/helloworld<br>5667fdb72017: Pull complete<br>d83811f270d5: Pull complete<br>ee671aafb583: Pull complete<br>7fc152dfb3a6: Pull complete<br>Digest: sha256:2707d17754ea99ce0cf15d84a7282ae746a44ff90928c2064755ee3b35c1057b<br>Status: Downloaded newer image for debuggy/helloworld:latest<br>hello</pre><p>Congratulation! You successfully completed the “Hello World” section. For additional information, please see the <a href="https://github.com/GoogleContainerTools/kaniko">project</a>.</p><h3>Jenkins Kubernetes cloud configuration for Kaniko</h3><p><em>Note: This entire section is the work Tanvi P Karennavar. For more refer to this </em><a href="https://tech.groww.in/an-introduction-to-kaniko-5cf4a8168d80"><em>link</em></a></p><p>Configure your Kubernetes cluster in Jenkins under configure clouds option.</p><p>Once the cluster is configured, to authenticate to AWS and GCP’s container registries, we need to create secrets accordingly.<br>- For AWS create a secret which has access key ID and secret access key of the user which has push and pull access to ECR.<br>- For GCP create a secret which has the service account json key.</p><p><em>Step 1:</em></p><p>Following is the pod configuration for kaniko on Jenkins, which has 2 containers configured — kaniko and jnlp(default jenkins slave container).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jhe-OXjc-0OZ9LgQ6S-0Hg.png" /></figure><p><em>Step 2:</em></p><p>Using the above pod configuration, we can run the kaniko executor command for building the container images. Below is an example command of how to use the executor command in Jenkins pipelines.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iSB3g6YAX7fhta3H8x1m5w.png" /></figure><h3>Kaniko on AWS EC2 Machine</h3><p><em>Step 1:</em></p><p>First, confirm that your cluster of EC2 instances has the appropriate permissions before applying the pod manifest. For Amazon ECR, your worker nodes need to have the following IAM policy permissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*1cJWDB9fOBpkfiec9tjmyg.png" /></figure><p><em>Step 2:</em></p><p>Run Kaniko by following these instructions, being sure to change “bucket-name,” “aws-account,” and “AWS REGION” to match your settings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*VlQ8CFb84rrykfaM_EWr0g.png" /></figure><p><em>Step 3:</em></p><p>Once everything is finished, you may inspect the kubectl logs kaniko and launch the docker image using ECR</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*Fp2bnY5Tc-TBPCHULD3nKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*ScWRl4YE568klY4hfaRfkA.png" /></figure><h3>Issues with Kaniko</h3><ul><li>Kaniko does not have v1 Registry API support</li><li>Kaniko does not have Windows container support</li><li>Other then official Kaniko image, running Kaniko in any other Docker image is not supported</li><li>Kaniko might perform poor in some cases as it needs to perform snapshot of the file frequently and also due to lack of proper caching</li></ul><h3>Wrapping up</h3><p>Kaniko is one of the new tool that enables creating container images in Kubernetes cluster and aims to prevent long standing reliance on the Docker daemon. It is an effective tool that enables securely creating container images in Kubernetes. It effectively accomplishes this and offers Kubernetes a reliable container image development tool. And it has done so without the usual security nightmare that came with building images on the daemon.</p><p>The official documentation for Kaniko can be found <a href="https://github.com/GoogleContainerTools/kaniko">here</a></p><h3>References</h3><ul><li><a href="https://github.com/GoogleContainerTools/kaniko">https://github.com/GoogleContainerTools/kaniko</a></li><li><a href="https://www.youtube.com/watch?v=EgwVQN6GNJg">https://www.youtube.com/watch?v=EgwVQN6GNJg</a></li><li><a href="https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-admin-guide/using-kaniko">https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-admin-guide/using-kaniko</a></li><li><a href="https://tech.groww.in/an-introduction-to-kaniko-5cf4a8168d80">https://tech.groww.in/an-introduction-to-kaniko-5cf4a8168d80</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ae8053a2bba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kaniko —  Building Container Images in a Kubernetes Cluster]]></title>
            <link>https://medium.com/@ikramkhan951/kaniko-building-container-images-in-a-kubernetes-cluster-a9381fe01976?source=rss-c6c7c248471c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9381fe01976</guid>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kaniko]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Ikram Khan]]></dc:creator>
            <pubDate>Fri, 16 Sep 2022 13:46:08 GMT</pubDate>
            <atom:updated>2022-09-16T19:27:13.296Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kaniko — Building Container Images in a Kubernetes Cluster</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SkfKPi2k9aTeRA-d7iOWbw.png" /><figcaption>Credit: <a href="https://www.infracloud.io/assets/img/Blog/Blog-updated-creatives/index-image-1200x628/build-container-images-with-kaniko-1200x628.png">https://www.infracloud.io/assets/img/Blog/Blog-updated-creatives/index-image-1200x628/build-container-images-with-kaniko-1200x628.png</a></figcaption></figure><h4><strong>Introduction</strong></h4><p>How do you build container images locally? The answer is most likely that you are executing commands like:</p><pre>$ docker image build [OPTIONS] PATH | URL | -</pre><p>But let’s move to the cluster and how do you build container images inside Kubernetes clusters as part of your continuous integration pipelines or any other process. Because remember we are moving most of the things to Kubernetes and that applies to building container images.</p><p>Within Kubernetes clusters Docker is a bad option because docker cannot run inside containers. Using Docker to build images within containers or inside Kubernetes clusters requires communication to the Docker engine running in cluster nodes. And that is a big security concern.</p><p>But if that security concern is not enough Dockershim, the one responsible for communication between Kubernetes and Docker is deprecated in Kubernetes v1.20. And sooner, depending on when you are reading this blog, it will be removed from Kubernetes. So, even if you are fine with running Docker inside of containers, even though that’s only a client that communicates with Docker engine running on the node and does the communication through socket and all that madness, even if you’re fine with all that which you shouldn’t be in any form or way, Docker will be removed, now that it is deprecated, from Kubernetes clusters. That means that you will be using alternative container engines now that there will be no Docker.</p><h4>What are containers?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUVSQuETtALZ0wrvE4hvsQ.jpeg" /><figcaption>Credit: <a href="https://www.ondat.io/hubfs/Assets%20Sep%202021/shutterstock_1677166660-min-min.jpg">https://www.ondat.io/hubfs/Assets%20Sep%202021/shutterstock_1677166660-min-min.jpg</a></figcaption></figure><p>Before diving into Kaniko, it is crucial to briefly clarify what is a container in software industry.</p><p>In the application layer, containers are an abstraction where code and dependencies are built or packaged together. It is a piece of software that you may use to wrap your software process or microservice and make it runnable in any computing environment. Generally speaking, containers can be used to hold any type of executable file, including configuration files, libraries, code, and binary files.</p><p>On a single system, several containers may be running. Each container instance runs as a separate process while sharing the OS kernel with other containers. A sample application or microservice is deployed for use via the container platform after being packed into a container image.</p><p>Moreover, a container image is an application’s code, runtime, system tools, libraries and settings all packed up in a lightweight, independent executable package.</p><h4>What is Kaniko?</h4><p>Kaniko is a daemonless container image builder that allows users to build container images, inside a container or Kubernetes cluster. Since Kaniko is not dependent on Docker daemon it creates container images in Kubernetes cluster in userspace without using Docker Daemon. It was a project initiated by Google to remove the need for elevated privileges when performing container image builds.</p><p>Let’s explore Kaniko!</p><h4>Why Kaniko?</h4><p>So you should not be building container images on Docker inside Kubernetes clusters and even if you ignore me and you say hey you’re talking nonsense what will you do when Docker will disappear from Kubernetes. So, you must look for alternative method to build images as Docker will not an option anymore within Kubernetes.</p><p>So the alternatives. What are the alternatives?</p><p>There are more then 10 viable alternatives out there but today we will talk about the one that I like the most and that one is called Kaniko.</p><p>It is a tool to build container images from a Dockerfile just like Docker does but the major difference is that Kaniko can run inside containers and that means that it can run inside the Kubernetes clusters. There is no need for privileged mode and there is no need for exposing any sockets . There is no need for Docker running on nodes of our cluster as it does not really matter which container engine we are using for running containers. What does matter is that Kaniko can build container images inside containers and automatically inside Kubernetes clusters.</p><p>Now, let’s explore how Kaniko works by looking at a hands-on demonstration</p><h4><strong>How does Kaniko work?</strong></h4><p>Let’s dig into internals of Kaniko and explore about how does Kaniko launch containers</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*81U3eYZdNzur-tG5cUlHhA.png" /><figcaption>Credit: <a href="https://goglides.io/wp-content/uploads/2020/03/kaniko-how-it-works.png">https://goglides.io/wp-content/uploads/2020/03/kaniko-how-it-works.png</a></figcaption></figure><p>The filesystem from the base image is extracted to a local directory (e.g., /kaniko/imagename) by Kaniko once it has parsed the Dockerfile and retrieved the base image. The commands contained in the docker file are then translated into shell commands and used to build several stages. By carrying out these actions, Kaniko directly alters the local filesystem. This presents no problems because Kaniko is designed to run within an already-existing container, but if it were to run from within a host, things might not go well.</p><p>The procedure of taking a snapshot, compiling the change files into a tarball, and adding files to a layer map or whiteout then takes place. Kaniko uses a hashing algorithm that incorporates the file’s modification time (mtime) to detect whether the files have been modified.</p><p>Kaniko requires following instructions to build a Docker image:</p><ul><li>Path to Dockerfile</li><li>Path to build context</li><li>URL/Destination of the repository where the image will be pushed</li></ul><p><strong>Prerequisites:</strong></p><ul><li>Kubernetes cluster</li><li>Dockerhub account</li><li>Config files (pod.yaml, volume.yaml, volume-claim.yaml)</li></ul><p><strong>Demo:</strong></p><p><em>Step 1:</em></p><p>Prepare local mounted directory and create a simple Dockerfile in it</p><pre>$ mkdir kaniko &amp;&amp; cd kaniko<br>$ echo &#39;FROM ubuntu&#39; &gt;&gt; dockerfile<br>$ echo &#39;ENTRYPOINT [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]&#39; &gt;&gt; dockerfile<br>$ cat dockerfile<br>FROM ubuntu<br>ENTRYPOINT [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]<br>$ pwd<br>/home/&lt;user-name&gt;/kaniko # copy this path in volume.yaml file</pre><p><em>Step 2:</em></p><p>To authenticate with Docker registry create a Secret named “regcred”</p><pre>kubectl create secret docker-registry regcred --docker-server=&lt;your-registry-server&gt; --docker-username=&lt;your-name&gt; --docker-password=&lt;your-pword&gt; --docker-email=&lt;your-email&gt;</pre><p><em>Step 3:</em></p><p>Create resources in Kubernetes cluster:</p><pre># create persistent volume<br>$ kubectl create -f volume.yaml<br>persistentvolume/dockerfile created</pre><pre># create persistent volume claim<br>$ kubectl create -f volume-claim.yaml<br>persistentvolumeclaim/dockerfile-claim created</pre><pre># check whether the volume mounted correctly<br>$ kubectl get pv dockerfile<br>NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                      STORAGECLASS    REASON   AGE<br>dockerfile   10Gi       RWO            Retain           Bound    default/dockerfile-claim   local-storage            1m</pre><pre># create pod<br>$ kubectl create -f pod.yaml<br>pod/kaniko created<br>$ kubectl get pods<br>NAME     READY   STATUS              RESTARTS   AGE<br>kaniko   0/1     ContainerCreating   0          7s</pre><pre># check whether the build complete and show the build logs<br>$ kubectl get pods<br>NAME     READY   STATUS      RESTARTS   AGE<br>kaniko   0/1     Completed   0          34s<br>$ kubectl logs kaniko<br>➜ kubectl logs kaniko<br>INFO[0000] Resolved base name ubuntu to ubuntu<br>INFO[0000] Resolved base name ubuntu to ubuntu<br>INFO[0000] Downloading base image ubuntu<br>INFO[0000] Error while retrieving image from cache: getting file info: stat /cache/sha256:1bbdea4846231d91cce6c7ff3907d26fca444fd6b7e3c282b90c7fe4251f9f86: no such file or directory<br>INFO[0000] Downloading base image ubuntu<br>INFO[0001] Built cross stage deps: map[]<br>INFO[0001] Downloading base image ubuntu<br>INFO[0001] Error while retrieving image from cache: getting file info: stat /cache/sha256:1bbdea4846231d91cce6c7ff3907d26fca444fd6b7e3c282b90c7fe4251f9f86: no such file or directory<br>INFO[0001] Downloading base image ubuntu<br>INFO[0001] Skipping unpacking as no commands require it.<br>INFO[0001] Taking snapshot of full filesystem...<br>INFO[0001] ENTRYPOINT [&quot;/bin/bash&quot;, &quot;-c&quot;, &quot;echo hello&quot;]</pre><p><em>Step 4:</em></p><p>If you have followed the steps mentioned above correctly an image will be built by Kaniko and pushed to Dockerhub. Pull that image from the Dockerhub to your local machine and run to test it</p><pre>$ sudo docker run -it &lt;user-name&gt;/&lt;repo-name&gt;<br>Unable to find image &#39;debuggy/helloworld:latest&#39; locally<br>latest: Pulling from debuggy/helloworld<br>5667fdb72017: Pull complete<br>d83811f270d5: Pull complete<br>ee671aafb583: Pull complete<br>7fc152dfb3a6: Pull complete<br>Digest: sha256:2707d17754ea99ce0cf15d84a7282ae746a44ff90928c2064755ee3b35c1057b<br>Status: Downloaded newer image for debuggy/helloworld:latest<br>hello</pre><p>Congratulation! You successfully completed the “Hello World” section. For additional information, please see the <a href="https://github.com/GoogleContainerTools/kaniko">project</a>.</p><h4>Issues with Kaniko</h4><ul><li>Kaniko does not have v1 Registry API support</li><li>Kaniko does not have Windows container support</li><li>Other then official Kaniko image, running Kaniko in any other Docker image is not supported</li><li>Kaniko might perform poor in some cases as it needs to perform snapshot of the file frequently and also due to lack of proper caching</li></ul><h4>Wrapping up</h4><p>Kaniko is one of the new tool that enables creating container images in Kubernetes cluster and aims to prevent long standing reliance on the Docker daemon. It is an effective tool that enables securely creating container images in Kubernetes. It effectively accomplishes this and offers Kubernetes a reliable container image development tool. And it has done so without the usual security nightmare that came with building images on the daemon.</p><p>The official documentation for Kaniko can be found <a href="https://github.com/GoogleContainerTools/kaniko">here</a></p><h4>References</h4><ul><li><a href="https://github.com/GoogleContainerTools/kaniko">https://github.com/GoogleContainerTools/kaniko</a></li><li><a href="https://www.youtube.com/watch?v=EgwVQN6GNJg">https://www.youtube.com/watch?v=EgwVQN6GNJg</a></li><li><a href="https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-admin-guide/using-kaniko">https://docs.cloudbees.com/docs/cloudbees-ci/latest/cloud-admin-guide/using-kaniko</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9381fe01976" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>