<?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 Rishabh Singh on Medium]]></title>
        <description><![CDATA[Stories by Rishabh Singh on Medium]]></description>
        <link>https://medium.com/@rishasi?source=rss-813a01f971a6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*7DMdXzPlPq_FvA5KBSlEiA.jpeg</url>
            <title>Stories by Rishabh Singh on Medium</title>
            <link>https://medium.com/@rishasi?source=rss-813a01f971a6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 22 May 2026 19:06:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rishasi/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[Custom DNS Configuration with CoreDNS: AKS/Kubernetes]]></title>
            <link>https://medium.com/@rishasi/custom-dns-configuration-with-coredns-aks-kubernetes-599ecfb46b94?source=rss-813a01f971a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/599ecfb46b94</guid>
            <category><![CDATA[coredns]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Rishabh Singh]]></dc:creator>
            <pubDate>Fri, 08 May 2020 12:28:38 GMT</pubDate>
            <atom:updated>2020-05-08T14:00:16.103Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Using on-premise DNS Servers for name resolution on AKS Pods by modifying CoreDNS</em></p><p>Recently I published an article for using <a href="https://medium.com/@rishasi/custom-dns-configuration-aks-kubernetes-360e481afc1"><strong>Custom DNS Servers with AKS Pods (and Nodes).</strong></a><br>There, the approach I took was to <strong>modify the DNS Settings of the VNet</strong> and set a DNS forwarder to Azure DNS.</p><blockquote>In this article, I am going to cover how to modify the CoreDNS to use Custom DNS Servers.</blockquote><h4><strong>Some theory of-course …</strong></h4><p>Modifying CoreDNS in AKS requires creation of a ConfigMap with a specific name ‘<strong>coredns-custom</strong>’ in the kube-system namespace.</p><p>The configuration from this custom ConfigMap is read by CoreDNS and the associated Corefile is modified to incorporate the new settings.</p><p>To setup usage of Custom DNS Server as a resolver for my custom domain (testabc.com), the ‘<strong>forward</strong>’ plugin for CoreDNS can be used.</p><p>Note that the earlier used ‘<strong>proxy</strong>’ plugin in now replaced by ‘<a href="https://coredns.io/plugins/forward/"><strong>forward</strong></a>’ plugin.</p><h4><strong>Architecture</strong>:</h4><p>Request from within the Pods:</p><ul><li>to custom domain testabc.com will go to the Custom DNS Server.</li><li>to all other domains will use the default configuration, i.e. use the /etc/resolv.conf file, which is derived from the host. In this specific case, since I have not modified the DNS Settings in the VNet where my AKS Nodes are present, the nodes use Azure DNS as the default DNS resolver.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0M8nQjhqiQn7J9zcWbMnHg.jpeg" /></figure><p>The Custom DNS Server sitting in another VNet should be reachable from the AKS Node.</p><h4>Setup</h4><ul><li>My AKS VNet settings point to the Azure DNS. That means the Nodes will use Azure DNS as the default resolver.</li><li>AKS VNet is peered to another VNet that contains the Custom DNS Server and a VM (VM1) whose hostname we will resolve.</li><li>CoreDNS version is 1.6.6. This is important as the plugin ‘forward’ was introduced in version 1.6.x and the earlier used ‘proxy’ plugin was removed.</li></ul><h4>Steps</h4><p>Assuming you already have an AKS Cluster and the AKS Nodes are able to connect to the Custom DNS Server:</p><ol><li>Write the ConfigMap to ‘forward’ queries to the Custom DNS Server (172.16.0.4 in my case)*<strong>if</strong>* the requested domain for DNS resolution from the Pod is my custom domain (testabc.com).</li><li>Update the custom ConfigMap that the CoreDNS refers to create additional configurations in the CoreFile</li><li>Restart the CoreDNS Pods to take in the new configuration<br>For all other queries, the default configuration of CoreDNS will be used which uses the DNS configuration of the Node.</li></ol><h4>Detailed Steps:</h4><ul><li>Write the ConfigMap named ‘mycoredns.yaml’</li></ul><pre>apiVersion: v1<br>kind: ConfigMap<br>metadata:<br>  <strong>name: coredns-custom</strong><br>  namespace: kube-system<br>data:<br>  yourdns.server: |<br>    <strong>testabc.com:53</strong> {<br>      errors<br>      cache 1<br>      <strong>forward . 172.16.0.4</strong><br>    }</pre><ul><li>Apply the ConfigMap</li></ul><pre>kubectl apply -f &lt;path_to_file/mycoredns.yaml&gt;</pre><ul><li>Restart the CoreDNS Pods to take the new settings</li></ul><pre>kubectl delete pods -n kube-system -l k8s-app=kube-dns</pre><p>Once the reboot is successful, the CoreDNS Pods will be updated with the new settings. The request flow will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A1Zk17AyRG4D5gXjHNvpFg.jpeg" /></figure><h4>Verification</h4><p>In order to verify the settings, I created an httpd pod, installed dnsutils on it, and tried to resolve both external and custom domain.</p><pre>$ kubectl exec -it myapp /bin/bash</pre><pre>root@myapp:/usr/local/apache2# nslookup google.com</pre><pre>Server:  10.0.0.10</pre><pre>Address: 10.0.0.10#53</pre><pre>Non-authoritative answer:</pre><pre>Name: google.com</pre><pre>Address: 172.217.13.238</pre><pre>Name: google.com</pre><pre>Address: 2607:f8b0:4004:808::200e</pre><pre>root@myapp:/usr/local/apache2# <strong>nslookup vm1.testabc.com</strong></pre><pre>Server:  10.0.0.10</pre><pre>Address: 10.0.0.10#53</pre><pre><strong>Name: vm1.testabc.com</strong></pre><pre><strong>Address: 172.16.0.5</strong></pre><p>As can be noted, both custom and external domains are getting resolved as expected.</p><h4>Footnotes</h4><p>For reference, here is the default ConfigMap for CoreDNS:</p><pre>kubectl describe cm -n kube-system coredns<br>Name:         coredns<br>Namespace:    kube-system<br>Labels:       addonmanager.kubernetes.io/mode=Reconcile<br>              k8s-app=kube-dns<br>              kubernetes.io/cluster-service=true<br>Annotations:  kubectl.kubernetes.io/last-applied-configuration:<br>                {&quot;apiVersion&quot;:&quot;v1&quot;,&quot;data&quot;:{&quot;Corefile&quot;:&quot;.:53 {\n    errors\n    health\n    kubernetes cluster.local in-addr.arpa ip6.arpa {\n      pods in...</pre><pre>Data<br>====<br>Corefile:<br>----<br>.:53 {<br>    errors<br>    health<br>    kubernetes cluster.local in-addr.arpa ip6.arpa {<br>      pods insecure<br>      upstream<br>      fallthrough in-addr.arpa ip6.arpa<br>    }<br>    prometheus :9153<br>    forward . /etc/resolv.conf<br>    cache 30<br>    loop<br>    reload<br>    loadbalance<br>    import custom/*.override<br>}<br>import custom/*.server</pre><pre>Events:  &lt;none&gt;</pre><p>These changes, made to the DNS Settings for Pods through CoreDNS modification, <strong>will not modify the DNS Settings in the Nodes</strong>. The Nodes will still refer to the DNS Server configured in the VNet.</p><p>There are various plugins that are available with CoreDNS and they have a specific order of processing. More details can be found below:</p><ul><li><a href="https://coredns.io/manual/plugins/">https://coredns.io/manual/plugins/</a></li><li><a href="https://github.com/coredns/coredns/blob/master/plugin.cfg">https://github.com/coredns/coredns/blob/master/plugin.cfg</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=599ecfb46b94" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Custom DNS Configuration: AKS/Kubernetes]]></title>
            <link>https://levelup.gitconnected.com/custom-dns-configuration-aks-kubernetes-360e481afc1?source=rss-813a01f971a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/360e481afc1</guid>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[dns]]></category>
            <category><![CDATA[on-premise]]></category>
            <category><![CDATA[custom-domain]]></category>
            <dc:creator><![CDATA[Rishabh Singh]]></dc:creator>
            <pubDate>Sun, 03 May 2020 17:37:49 GMT</pubDate>
            <atom:updated>2022-01-27T20:18:54.443Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Using on-premise DNS Servers for name resolution on AKS Pods</em></p><p>I have worked with a lot of clients who want to use their Custom DNS Server to resolve names from Pods hosted on Azure Kubernetes Service.</p><p>These DNS Servers can be on-prem, or in a different VNet, or in the same VNet, and are used to resolve custom domains.</p><p>I have noticed many people having difficulty with the configuration, whereas this is a fairly simple one if the flow of the traffic is clear.</p><p>In this post, I will talk about one of the approaches that can be taken to enable the AKS Pods and resolve custom domain names. One other popular approach is to modify the CoreDNS configuration, which is covered in another post here: <a href="https://medium.com/@rishasi/custom-dns-configuration-with-coredns-aks-kubernetes-599ecfb46b94">https://medium.com/@rishasi/custom-dns-configuration-with-coredns-aks-kubernetes-599ecfb46b94</a></p><p>For the solution to work, in very simple terms, forward all DNS queries to the Custom DNS Server, and:</p><ul><li>resolve the custom domain using this Custom DNS Server, and</li><li>for every other domain, forward request to Azure DNS using DNS forwarder.</li></ul><p><strong>A simple diagram:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAmVocvNHtgCzDakL-ByIg.jpeg" /></figure><p><strong>Approach</strong>:</p><p>Pod requests DNS resolution, which will then be forwarded to the DNS Server configured in VNet settings, say 10.x.x.x.</p><p>This DNS Server can be on-prem, or in the same VNet, or a peered VNet.</p><p>The DNS Server will see the request, and:</p><pre><em>a. If the DNS query is for it’s own custom domain,<br></em>It will itself resolve the query and return the IP.</pre><pre><em>b. If it is any other domain, for example ubuntu.com,<br></em>Then the DNS Server will forward the request to the Azure DNS.</pre><p><em>For it to work, you will have to setup the DNS Forwarder to route traffic for external domains to a public DNS Server. However, it should be noted that the AKS Nodes and the Pods may need to resolve other external domain names for various reasons, which also include Azure’s Internal Domains like cloudapp.net. Thus it is recommended to forward external queries to Azure DNS Server (168.63.129.16).</em></p><pre>Edit:<br>The above approach works as long as the Custom DNS Server is in Azure. So, setting Azure DNS as the forwarder is straightforward using the Azure DNS IP: 168.63.129.16.</pre><pre>However, if the Custom DNS Server is on-prem, or outside Azure, the Azure DNS cannot be reached from there.<br>So setting Azure DNS as the forwarder will not be that straightforward.</pre><pre>In that case, the Custom DNS, which is on-prem, can set the forwarder as:<br>- another DNS Server configured on Azure VM,<br>- or Azure Firewall<br>- or a DNS Proxy on Azure<br>.. and then that device can use Azure DNS as it&#39;s DNS Server.</pre><pre>Basically, we cannot reach Azure DNS IP directly from outside Azure, so we first forward queries to a VM/Firewall/DNS Proxy, which is on Azure, and then that device can forward requests to Azure DNS.</pre><pre>A little tricky, but hopefully this helps.</pre><p><strong>This is it</strong>. If you understood the setup, great. If not, don’t worry, there is more to come.</p><p>I prepared a simple setup to *mimic* the discussed architecture, where the AKS VNet is connected to the on-premise environment using VPN/ExpressRoute.</p><p>For this setup,</p><ul><li>Launched an AKS Cluster</li><li>Created a DNS Server in another VNet</li><li>Created a VM in the DNS Server’s VNet (VM1) whose name we will resolve</li><li>Created a peering connection between AKS VNet and the custom VNet</li><li>Updated AKS VNet to use the custom DNS Server instead of the default Azure Provided DNS Server</li></ul><p>Instead of setting up a VPN/ExpressRoute, I used VNet Peering. The basic idea is to have connectivity to the Custom DNS Server. Thus, here, the custom VNet can be thought of as the on-prem network.</p><p>Creating a DNS Server was the roadblock, as I had done it a long long time ago. I used a Windows 2016 VM and referred this simple article to configure a DNS Server on top of it: <a href="https://www.hostwinds.com/guide/how-to-setup-and-configure-dns-in-windows-server-2016/">https://www.hostwinds.com/guide/how-to-setup-and-configure-dns-in-windows-server-2016/</a></p><p>The details for the setup:</p><pre>AKS VNet CIDR: 10.0.0.0/8</pre><pre>AKS Node IP: 10.240.0.4</pre><pre>Custom VNet CIDR: 172.16.0.0/16</pre><pre>Custom Domain: testabc.com</pre><pre>DNS Server IP: 172.16.0.4</pre><pre>VM1 IP: 172.16.0.5</pre><pre>Hostname for VM1: vm1.testabc.com</pre><p>The DNS Server settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KKKbXHTOW_MRP_Svo5nU_w.png" /></figure><p>DNS Forwarder set to Azure DNS IP:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YDmFucR63h8dYjLXawqBhw.png" /></figure><p>Once setup, I first ensured that the hostname for VM1 is getting resolved from the DNS Server itself. From CMD inside the DNS Server:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*mc-MpF25oKOFKzRVtmrxVA.png" /></figure><p>Then I checked if the DNS is getting resolved from the AKS Node. SSH’d to the AKS Node and tested through CLI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3A9I-n7bskuLDUCm8HwrEg.png" /></figure><p>Here the screenshot validates two things:</p><ol><li>The DNS Server in other VNet is reachable via the private IP, so the peering is working fine,</li><li>and that the hostname for the VM1 is getting resolved to the correct IP</li></ol><p>So far so good. However, currently I have to specify the DNS Server explicitly in the nslookup command. I want the custom DNS Server to be referred by default.</p><p>Thus, I changed the AKS VNet’s DNS Property to refer Custom DNS Server in another VNet (reachable via Private IP due to VNet peering):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tzz7POxPxhk4IjpU2Dcphw.png" /></figure><p>The AKS Node had to be restarted for the new settings to propagate. Once the machine restarted, I verified</p><ol><li>That the DNS Settings for the AKS Nodes are updated</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUmczVzDfL1IYAYIC4GK3A.png" /></figure><p>2. The AKS Node is able to resolve the hostname for VM1:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TPs80lKa_qDh62tApk1X9w.png" /></figure><p>Not only the internal customer domain of ‘testabc.com’ is getting resolved, but also the external domains.</p><p>If you look closely, the url google.com has been resolved by a non-authoritative server, suggesting that the Custom DNS forwarded the query to some other dns server, which validates that the forwarding to Azure DNS is working fine.</p><p>All working as expected!!</p><p><strong>Now the main question, are my pods able to resolve the domain name, both custom and external?</strong></p><p>To test, I launched up a simple httpd pod, installed dnsutils on it and performed the test:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*djJa4A-AivWNgroT6RqJBw.png" /></figure><p><strong><em>Voilà!</em></strong><em>, as simple as that.</em></p><p>From inside the pod, I was able to resolve VM1 hostname to the correct IP and was also able to resolve external domains.</p><h4>Footnotes:</h4><p>It should be noted that I did not specify any <strong>dnsPolicy</strong> for the Pod. Thus, the default policy was applied, in which the Pod inherits the DNS configuration from the node it is running on.</p><p><em>More details about dnsPolicy for pods can be found here: </em><a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy"><em>https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pod-s-dns-policy</em></a></p><p>As a side note, the benefit of forwarding external domain names to Azure DNS is that the custom DNS server will only be responsible for resolving the custom domain, and all other domain names are resolved by Azure DNS, reducing the load on the Custom DNS Server.</p><p>Lastly, this setup can work in any environment, with minor tweaks, be it Azure, AWS, Google Cloud, or others. The requirement is to ensure that:</p><pre>a. Custom DNS Server(s) is/are reachable from the Kubernetes Nodes,</pre><pre>b. The Nodes have the Custom DNS Servers as the default DNS resolver, and</pre><pre>c. the Pods have the default dnsPolicy.</pre><p>Hopefully, this explains the configuration required to use Custom DNS Server with Kubernetes Cluster.</p><p>Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=360e481afc1" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/custom-dns-configuration-aks-kubernetes-360e481afc1">Custom DNS Configuration: AKS/Kubernetes</a> was originally published in <a href="https://levelup.gitconnected.com">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Blue/Green Deployment using Init Containers: Kubernetes]]></title>
            <link>https://medium.com/@rishasi/blue-green-deployment-using-init-containers-kubernetes-b832a09e0e8?source=rss-813a01f971a6------2</link>
            <guid isPermaLink="false">https://medium.com/p/b832a09e0e8</guid>
            <category><![CDATA[init-containers]]></category>
            <category><![CDATA[azure-kubernetes-service]]></category>
            <category><![CDATA[blue-green-deployment]]></category>
            <category><![CDATA[windows-nodes]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Rishabh Singh]]></dc:creator>
            <pubDate>Wed, 29 Apr 2020 18:49:18 GMT</pubDate>
            <atom:updated>2020-05-01T13:25:35.018Z</atom:updated>
            <content:encoded><![CDATA[<h3>Prologue:</h3><p>While working with a client, they wanted zero downtime deployment (updates) for Windows nodes.​ The Deployment resource in Kubernetes, relies on Readiness and Liveness probes for zero downtime deployment.​</p><p>However, at the time of the discussion, there was a known issue with Windows nodes, where the Liveness probes and Readiness probes do not work.​</p><ul><li><a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2FAKS%2Fissues%2F1014%23issuecomment-519866944&amp;data=02%7C01%7CSingh.Rishabh%40microsoft.com%7C9b116190f6a4414ae27008d771b1ef81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637102881347578648&amp;sdata=Gx2Z4rM6wXOsMD2qLWD1cSObuj4Pa7M76H%2BwDs3Xc64%3D&amp;reserved=0">https://github.com/Azure/AKS/issues/1014#issuecomment-519866944</a>​</li><li><a href="https://nam06.safelinks.protection.outlook.com/?url=https:%2F%2Fgithub.com%2Fkubernetes%2Fkubernetes%2Fissues%2F81938%E2%80%8B&amp;data=02%7C01%7CSingh.Rishabh%40microsoft.com%7C9b116190f6a4414ae27008d771b1ef81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637102881347578648&amp;sdata=T8FJQSv4IimL5IiAGzA6wmz5CNnVLCO%2Bw1qSnXJBBNI%3D&amp;reserved=0">https://github.com/kubernetes/kubernetes/issues/81938​</a></li></ul><p>There were certain workarounds, but none worked for all. Different behavior was observed for each case. The suggestion was not to rely on these probes until the Windows nodes are released in GA which happened recently: <a href="https://azure.microsoft.com/en-us/blog/announcing-the-general-availability-of-windows-server-containers-and-private-clusters-for-azure-kubernetes-service/">https://azure.microsoft.com/en-us/blog/announcing-the-general-availability-of-windows-server-containers-and-private-clusters-for-azure-kubernetes-service/</a></p><p>​Hence, I suggested the client to use <strong>Blue/Green Deployment</strong> for zero-downtime.​</p><h3>Problem:</h3><p>The problem is that, everywhere, the approach utilizes Readiness probes. Even with using Jenkins or Istio, these agent based or agent-less integration tools rely on Readiness probes instead of directly checking the health of the application, and why not? When there is an inbuilt feature provided by Kubernetes, why try to re-invent the wheel?​ However, sadly in this case, the wheels were punctured 😜 , so, Readiness probes were not to be used.​​</p><p>As another workaround, the manual solutions just rely on giving a minimum amount of time for the Pods to be ready, and switching the Service to point to New Pods. This is not a permanent solution and is much like a shot in the dark.</p><p>What if the application fails to come up in the given amount of time? No entity is checking the status of the application. The solution only relies on the “status” of the “Pod”, but no entity checks the health of the application.​</p><p><strong>The big question: How to check health of the application without Readiness probes?​</strong></p><p>Do we use a temporary Service? and check the HTTP return code of that service?​ Yes, this could work if implementing a Load Balancer type of service. But this again lead to some problems:</p><ul><li>With many updates, again the Node can have SNAT exhaustion, which the customer had already faced, and had to replace all his nodes.​<a href="https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FAzure%2Fazure-container-networking%2Fissues%2F195&amp;data=02%7C01%7CSingh.Rishabh%40microsoft.com%7C9b116190f6a4414ae27008d771b1ef81%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637102881347588648&amp;sdata=ZGXlDewQu%2BgbJvkA4uzZiqEtQ97wMj%2Fm9VxyhSZmOEE%3D&amp;reserved=0">https://github.com/Azure/azure-container-networking/issues/195</a>​</li><li>Also, the Load balancer IP would take time to come up, causing unnecessary delay in the schedule​</li><li>The biggest problem: Creating a new Load Balancer type Service every time when there is an update made. Like really? This did not seem to be the best approach.​</li></ul><p>Another approach could have been creating a Cluster IP type service and run the automation script inside the same VNet as the Nodes.</p><ul><li>But configuring this would again need us to include some Runtime, either creating a new VM, or using something like Azure Functions.</li><li>Configuring kubectl, managing contexts, providing least required access was again too much of overhead.​</li></ul><h3>Solution​:</h3><p>Here comes <strong>init container</strong> into the picture.​The best thing about init container for this solution was “the application container does not start <strong>initialization </strong>until the init container has completed processing”.​</p><p>Thus came an idea, why not to use a Pod with init container as a health checking entity. Here is a brief overview of the workflow:​</p><p><strong>Phase 1: Deployment Phase</strong>​</p><p>The main Deployment (D1) and the main Service (Svc1) are deployed. This is the Blue Deployment.​ All good here.​</p><p><strong>Phase 2: Update Phase</strong>​</p><p>From the script which is used for update, create the following resources:​</p><p>1. Deployment 2 (D2), which has the new version of the application, i.e. the Green Deployment.​</p><p>2. A temporary service of type ClusterIP. Yeah, we don’t need a Load Balancer or NodePort type service. Let’s call this Svc2. This service will only be needed to check if the application inside the Pods are responding.​</p><p>3. A temporary Pod which has the init container. The init container will perform checks on the Svc2. Once desired HTTP status code is received, the init container can complete execution, and then the app container in this Pod can start. The app container in this Pod can be any simple docker container, which just needs to come up and mark the status of the Pod as Ready.​</p><p>4. Instead of checking the status of the application from the script, which is very complex, the script can just check the status of the Temporary Pod. Once it is in ready state, it means that the init container completed execution, which means, the Svc2 returned HTTP 200 (or 2XX/ 3XX depending on the use case), which in turn means that the D2 pods are ready to serve traffic.​</p><p><strong>Phase 3: Delete Phase</strong>​</p><p>Once the script determines that the Temp Pod is ready, it can move further in the processing by updating Svc1 to point to D2 Pods by modifying the labels, and then delete the temporary resources: Svc2, Temp Pod, and D1. ​</p><p>A simple diagram for the approach:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*8ISPzG-Ihd0SIWdGbX4nzg.png" /></figure><p>• for checking the status of the Pod, you could use something like:​</p><pre>-       $podState = kubectl get pod &lt;temp_pod_name&gt;​</pre><pre>-       $status = $podState[1].SubString(17, 1)​</pre><pre>-       if $status == 0, sleep for 5 sec and keep looping,​</pre><pre>-       if $status == 1, break out of the loop and continue   processing further steps​</pre><p>For the init containers, health checks can be performed using wget. You can launch any simple windows image that has wget installed. One example is <a href="https://hub.docker.com/r/stefanscherer/busybox-windows/"><strong>stefanscherer/busybox-windows docker image</strong></a>, and then can pass a script to the Pod, where the status code is checked. Note, that this image supports shell scripts and not Powershell scripts. It has wget and curl pre-installed.​Alternatively, you could launch a Powershell based docker image, and check the availability of the service using wget.​</p><pre>- $response = wget google.come​</pre><pre>- if $response.StatusCode == 200, break; else sleep 5, keep checking the state. ​</pre><pre>- for a shell script: (for i in {1..100}; do sleep 5; if dig myservice; then exit 0; fi; done; exit 1)​</pre><p>You can create a script which checks for the status code, and if the output returned is 200, it suggests the service is ready, else, keep checking after some interval.​</p><p>If the docker images are heavy, you could use a <a href="https://hub.docker.com/_/microsoft-windows-nanoserver">Windows NanoServer image</a>, and install your own components in the docker image, just like <a href="https://github.com/StefanScherer/dockerfiles-windows/blob/master/busybox/Dockerfile">how the busybox image has been created</a>.</p><p><em>NOTE: ​This is not a complete solution, but more of an architectural guidance, which was more than enough for the client to implement the solution.</em></p><p><em>I am not good with scripts. If anyone would be interested in developing a complete solution, I would be more than happy to collaborate.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b832a09e0e8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>