<?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 Sumanth Reddy on Medium]]></title>
        <description><![CDATA[Stories by Sumanth Reddy on Medium]]></description>
        <link>https://medium.com/@sumanthkumarc?source=rss-4ac2ca66499d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*QiJ0Opb9W2wOKF2PIJQXew.jpeg</url>
            <title>Stories by Sumanth Reddy on Medium</title>
            <link>https://medium.com/@sumanthkumarc?source=rss-4ac2ca66499d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 00:37:18 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sumanthkumarc/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[Kubernetes — Double jump upgrades]]></title>
            <link>https://sumanthkumarc.medium.com/kubernetes-double-jump-upgrades-94484240e60b?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/94484240e60b</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[kubernetes-upgrades]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 06:20:39 GMT</pubDate>
            <atom:updated>2023-06-19T06:20:39.022Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kubernetes — Double jump upgrades</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a0UNFmSCnCmJNnkCdeMRBA.png" /><figcaption>Versions show in image are for context of double jump and not constrained to concepts outlined</figcaption></figure><p><strong>Unpopular opinion</strong> — The most difficult part of platform software is not the installation but its maintenance.</p><blockquote>TLDR version</blockquote><blockquote>Kubernetes has a <a href="https://kubernetes.io/releases/version-skew-policy/">version skew policy</a> which allows for data plane to be two minor versions behind control plane. This gives us the ability to skip a version and go ahead to +2 version of the data plane as part of the upgrade.</blockquote><blockquote>As long as one uses GA and Beta API versions in the cluster, it is possible to do double jump upgrades. Meaning we upgrade control plane twice (Say 1.22 → 1.23 → 1.24) and directly upgrade Data plane to +2 version (Say from 1.22 → 1.24).</blockquote><blockquote>The concepts detailed below apply for all Kubernetes clusters in general.</blockquote><blockquote><strong>NOTE</strong> — Doing this has it’s own risks associated, Please do due diligence before taking the decision.</blockquote><p>If the TLDR version looks interesting, please follow along while i take you through some concepts behind Kubernetes release and deprecation policy.</p><p>We all agree to the fact that regular upgrades to the software is important but not necessarily easy, Kubernetes is no different. Kubernetes team has a regular release cadence for various versions. Pre 1.22 version, there was a 4<em>-releases-per-calendar-year cadence </em>which changed to <em>3-releases-per-calendar-year cadence </em>from 1.22 version with KEP(Kubernetes Enhancement Proposal) described <a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-release/2572-release-cadence">here</a>.</p><p>For example, below is the AWS EKS end of life calendar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MwIlyEG2f4_l18nKHb9IA.png" /><figcaption><a href="https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html#kubernetes-release-calendar">https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html#kubernetes-release-calendar</a></figcaption></figure><p>As you can see from above, we need to keep upgrading to the newer version every 4 months. This might not be an easy pace to keep up with, for every team.</p><p>Evidently Kubernetes has very good feature deprecation/removal policy. More on this at <a href="https://kubernetes.io/docs/reference/using-api/deprecation-policy/">https://kubernetes.io/docs/reference/using-api/deprecation-policy/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IvKFg8lwksYtgkz8-CSf_Q.png" /><figcaption>API versions progression example</figcaption></figure><p>Features generally progress from alpha — &gt; beta — &gt; GA, but might be deprecated/removed before reaching GA as well. More about the deprecation policy can be read from above link, but quoting <strong>Rule #4a </strong>which helps us in easy upgrades.</p><blockquote><strong>Rule #4a: API lifetime is determined by the API stability level</strong></blockquote><blockquote>GA API versions may be marked as deprecated, but must not be removed within a major version of Kubernetes</blockquote><blockquote>Beta API versions are deprecated no more than 9 months or 3 minor releases after introduction (whichever is longer), and are no longer served 9 months or 3 minor releases after deprecation (whichever is longer)</blockquote><blockquote>Alpha API versions may be removed in any release without prior deprecation notice</blockquote><blockquote>This ensures beta API support covers the <a href="https://kubernetes.io/releases/version-skew-policy/">maximum supported version skew of 2 releases</a>, and that APIs don’t stagnate on unstable beta versions, accumulating production usage that will be disrupted when support for the beta API ends.</blockquote><p>Delving into the <a href="https://kubernetes.io/releases/version-skew-policy/">version skew policy,</a> you will find below</p><ol><li>Control plane components can be one minor version different from each other in HA cluster.</li><li>Data plane can be two minor versions behind Control plane and shouldn’t be newer than Control plane.</li></ol><p>Most notable points from <strong>Rule #4a </strong>quoted above is as follows</p><ol><li>GA API versions are deprecated but not removed from major version and Beta API versions once marked for deprecation are only removed only after 3 minor versions.</li></ol><p>Combining the above two points one can arrive at below conclusion</p><blockquote>As long as one uses GA and Beta API versions in the cluster, it is possible to do double jump upgrades. Meaning we upgrade control plane twice (Say 1.22 → 1.23 → 1.24) and directly upgrade Data plane to +2 versions (Say from 1.22 → 1.24).</blockquote><p>This might seem insignificant at first glance but the Kubernetes platform teams know that the most difficult part of upgrade is data plane rotation which generally comprises of multiple node groups and combined number makes up to hundreds of nodes.</p><p>In the next blog, i’ll explain the general process of due diligence for making these double jump upgrades safer in general and my experience upgrading clusters from 1.22 -&gt; 1.24 version.</p><h3>General expected FAQ’s</h3><ol><li>Is it safer to do so?</li></ol><p>Depends. Most folks run various things in their data plane and it’s always those that break. Control plane upgrade is the easier part, data plane, not so much. So if your data plane is simple enough, you can do so, at your own risk and after due diligence.</p><p>2. Did i actually do this in practice on real world production clusters?</p><p>Yes. I have succeeded in making the double jump cluster upgrades a couple of times to date. Although i should add that, i did find few small missed points, which i had to fix post upgrade. For example, log format change in 1.24, which earlier had docker json logging which changed to cri format which isn’t json. This will break your json log parsing pipelines. Some folks say this is just luck, i think it’s the beautiful design of Kubernetes feature deprecation and release process. The efforts of Kubernetes community in trying to maintain backward compatibility ♥️.</p><p>3. Does this work on all Kubernetes clusters?<br>Yes, the concept in general is from upstream Kubernetes. It applies equally to self hosted as well as managed Kubernetes clusters. Although i should add that doing this on managed clusters will be a bit easy, especially considering the control plane upgrade in managed services is just a button click.</p><h3><strong>Reference links</strong></h3><ul><li><a href="https://kubernetes.io/releases/version-skew-policy/">https://kubernetes.io/releases/version-skew-policy/</a></li><li><a href="https://github.com/kubernetes/enhancements/tree/master/keps/sig-release/2572-release-cadence">https://github.com/kubernetes/enhancements/tree/master/keps/sig-release/2572-release-cadence</a></li><li><a href="https://kubernetes.io/docs/reference/using-api/deprecation-policy/">https://kubernetes.io/docs/reference/using-api/deprecation-policy/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=94484240e60b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ArgoCD — Custom actions on resources]]></title>
            <link>https://sumanthkumarc.medium.com/argocd-custom-actions-on-resources-aa3bd65fdaa9?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa3bd65fdaa9</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[cncf]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Fri, 12 May 2023 11:35:38 GMT</pubDate>
            <atom:updated>2023-05-13T05:51:56.991Z</atom:updated>
            <content:encoded><![CDATA[<h3>ArgoCD — Custom actions on resources</h3><p>Argo CD is a declarative, GitOps continuous delivery tool for Kubernetes.</p><p>For un-initiated, ArgoCD is a Continuous delivery tool to deploy the Kubernetes manifests from git to cluster. It has integration with various Kubernetes tooling like helm, Kustomize and bare manifests making this one of the best CD tools for the applications deployed into Kubernetes.</p><p>We use ArgoCD to deploy applications onto the cluster. Argo CD has a very good UI which we also provide to devs to visualise the resources and perform some basic actions like ability to restart their deployments when needed. BTW, Argo also supports RBAC which helps to provide granular permissions to logged in users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZXDS7wvhJjqLkhX5kRhDuQ.png" /><figcaption>ArgoCD restart action on deployment</figcaption></figure><p>This is all good but we had a problem with restart action — time it took to rotate all pods. The restart action basically <a href="https://github.com/argoproj/argo-cd/blob/master/resource_customizations/apps/Deployment/actions/restart/action.lua">updates annotation on pod spec</a> which essentially means new Replicaset is created and thereby ending up creating new pods (under new Replicaset). Now this rollout happens using some parameters which are defined in deployment spec namely maxSurge and maxUnavailable . By default the maxSurge is 25%, meaning in one batch, the controller only creates 25% of new pods for rotation. This means for production deployments with huge number of pods and health check thresholds, the time taken to rotate is quite a lot. But again, we can’t increase maxSurge to 100% always because it also means if there was a bad deployment, it will result in large number of pods with errors.</p><p>We wanted a solution to quickly rotate pods when needed but without altering default rollout behaviour permanently. Since devs already are aware of Argo UI, it would be a plus if the solution has similar UX as existing restart action. Welcome custom resource actions 🥳</p><p>From <a href="https://argo-cd.readthedocs.io/en/stable/operator-manual/resource_actions/#custom-resource-actions">https://argo-cd.readthedocs.io/en/stable/operator-manual/resource_actions/#custom-resource-actions</a></p><blockquote>Argo CD supports custom resource actions written in <a href="https://www.lua.org/">Lua</a>. This is useful if you:</blockquote><blockquote>Have a custom resource for which Argo CD does not provide any built-in actions.</blockquote><blockquote>Have a commonly performed manual task that might be error prone if executed by users via kubectl</blockquote><blockquote>You can define your own custom resource actions in the argocd-cm ConfigMap.</blockquote><p>So we have ended up trying out the custom restart actions on deployment resource which essentially does below</p><ol><li>Sets maxSurge value to 100%</li><li>Updates annotation in pod spec</li></ol><p>How is this different from directly setting the value in git? Because we set this value from the action, it ends up making Argo app unhealthy because there is diff in the defined vs expected spec.</p><ul><li>If you have Argo app self heal enabled, it automatically sets this back to value defined in git.</li><li>If you do not have self heal enabled, when argo app sync is triggered by Github, it just overrides the set value by us.</li></ul><p>Beauty of all this process, the app diff sync doesn’t restart the deployment again, because the change doesn’t happen to pod spec.</p><p>There are two parts for defining the custom action on resource— Discovery and action.</p><ul><li>discovery.lua — enables which actions are defined against given resource type.</li><li>action.lua — defines logic for the defined action</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/69f63f41efb8f5b9a36331c79bf95355/href">https://medium.com/media/69f63f41efb8f5b9a36331c79bf95355/href</a></iframe><p>The actual deployment of this action is simple. Just edit the argocd-cmconfigmap in your ArgoCD installation and add above code for the key</p><pre>resource.customizations.actions.apps_Deployment</pre><p>which is of format — resource.customizations.actions.&lt;apiGroup_Kind&gt; In our case, the kind is department and it belongs to apps apiGroup. If you are unsure about this, you can always get this data from kubectl</p><pre>kubectl api-resources | grep -i Deployment<br>deployments     deploy   apps/v1    true         Deployment</pre><p>or through the <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.27/">api reference doc for your cluster version</a>.</p><p>From <a href="https://argo-cd.readthedocs.io/en/stable/operator-manual/resource_actions/#define-a-custom-resource-action-in-argocd-cm-configmap">https://argo-cd.readthedocs.io/en/stable/operator-manual/resource_actions/#define-a-custom-resource-action-in-argocd-cm-configmap</a></p><blockquote>The discovery.lua script must return a table where the key name represents the action name. You can optionally include logic to enable or disable certain actions based on the current object state.</blockquote><blockquote>Each action name must be represented in the list of definitions with an accompanying action.lua script to control the resource modifications. The obj is a global variable which contains the resource. Each action script must return an optionally modified version of the resource.</blockquote><p>In above example, we have added new action named restart-100%-in-1-batch which is returned in discovery and in action logic, updated the deployment rollout strategy maxSurge value to our choice and added annotation to initiate restart.</p><p>Once you update the argocd-cm configmap, restart the argocd-server so that these changes are picked up. You would be seeing extra actions on all deployment resources as below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k3WpxLJuQIgr12sWjo7lVw.png" /><figcaption>Extra custom action on deployment resource visible from Argo UI</figcaption></figure><blockquote><strong>NOTE</strong> — There is an active bug in Argo which makes any new custom actions override the upstream defined ones and is being tracked <a href="https://github.com/argoproj/argo-cd/issues/9147">here</a>.</blockquote><p><a href="https://github.com/argoproj/argo-cd/issues/9147">Custom resource actions overrides default actions · Issue #9147 · argoproj/argo-cd</a></p><p>To work around this, we need to add all the upstream defined actions on resources along with our custom actions. You can find an example full config reference <a href="https://gist.github.com/sumanthkumarc/2a5fd1c9e05a76e5d622c68e3990b79b">here</a> for deployment.</p><p>Also checkout official Argo project which helps extend multiple core functions in ArgoCD — <a href="https://github.com/argoproj-labs/argocd-extensions">https://github.com/argoproj-labs/argocd-extensions</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa3bd65fdaa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EKS + ALB Controller — Simple canary deployment for applications on AWS EKS]]></title>
            <link>https://sumanthkumarc.medium.com/eks-alb-controller-simple-canary-deployment-for-applications-on-aws-eks-82f83ac7b092?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/82f83ac7b092</guid>
            <category><![CDATA[ingress]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[canary-deployments]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[alb]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Sat, 10 Dec 2022 16:58:14 GMT</pubDate>
            <atom:updated>2022-12-10T16:58:14.468Z</atom:updated>
            <content:encoded><![CDATA[<h3>EKS + ALB Controller — Simple canary deployment for applications on AWS EKS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rK_qs7ae_6GFEdGlXTUpBQ.png" /></figure><p>This setup aims at demonstrating basic canary traffic split on EKS using AWS load balancer controller.</p><p>If you are not aware already, <a href="https://kubernetes.io/docs/concepts/services-networking/service/">Services</a> in Kubernetes is the mechanism which helps us to communicate with pods over network. We can use <a href="https://kubernetes.io/docs/concepts/services-networking/service/#type-nodeport">Node port</a> and <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer">LoadBalancer</a> service types for external communication ie., ability to expose pods for communication outside the cluster. Problem is core cloud controller spins up classic load balancer in AWS by default for <a href="https://kubernetes.io/docs/concepts/services-networking/service/#loadbalancer">LoadBalancer</a> type and this doesn’t provide us ability to split traffic. Hence we will be using another open source project <a href="https://github.com/kubernetes-sigs/aws-load-balancer-controller">AWS Load Balancer controller</a> for our goal of traffic splitting.</p><p>From project <a href="https://github.com/kubernetes-sigs/aws-load-balancer-controller#aws-load-balancer-controller">readme</a></p><blockquote>AWS Load Balancer Controller is a controller to help manage Elastic Load Balancers for a Kubernetes cluster.</blockquote><blockquote>It satisfies Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/ingress/">Ingress resources</a> by provisioning <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/introduction.html">Application Load Balancers</a>.</blockquote><blockquote>It satisfies Kubernetes <a href="https://kubernetes.io/docs/concepts/services-networking/service/">Service resources</a> by provisioning <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/network/introduction.html">Network Load Balancers</a>.</blockquote><p>So the idea is simple — We create Ingress resource which creates Application load balancer which provides us with traffic split. We ensure there are two target groups — each pointing to one deployment (primary &amp; canary)— and there is fixed traffic split between these two.</p><p>Installing AWS lb controller is out of scope for this article but the project has <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/deploy/installation/">excellent docs</a> for this.</p><p>Assuming that the controller has been installed, For this example we create two deployments — primary and canary each running nginx, but the index.html overriden to show primary and canary respectively. Two services of type ClusterIP will be created one for each deployment. The ingress will have two weighted routes pointing to these services and on given port. The full manifests for this are available at <a href="https://github.com/sumanthkumarc/aws-eks-canary">https://github.com/sumanthkumarc/aws-eks-canary</a></p><p>The below image is self explanatory as to how infra components are reconciled from code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2MXcKaohGV1b5_laEZ-X-A.png" /><figcaption>Infrastructure As a Code</figcaption></figure><blockquote>Few important observations to note</blockquote><ol><li>This implementation assumes that we use AWS vpc cni networking providing each pod an ip address resolvable from across the vpc. This is important if we want to use target-type as IP in Ingress annotations.</li><li>The Target groups themselves are created by controller based on config provided in Ingress. Controller also creates a new CR of type targetgroupbindings for each target group it creates. This CRD is the binding between target group backends(ip’s) and target group.</li><li>When we use target-type as IP, AWS load balancer controller directly gets the list of pod ip’s from the endpointslices and sync them as backends for the target group. The traffic directly reaches ALB to pod.</li><li>If we use target-type as instance, all the nodes are registered as backends for the Target groups. This adds extra hop for traffic first to node then to pod.</li></ol><h3>Reference links</h3><p>Controller installation — <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/deploy/installation/">https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/deploy/installation/</a></p><p>Target group binding — <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/targetgroupbinding/targetgroupbinding/">https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/targetgroupbinding/targetgroupbinding/</a></p><p>Annotations — <a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/ingress/annotations/">https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.4/guide/ingress/annotations/</a></p><p>Kubernetes services — <a href="https://kubernetes.io/docs/concepts/services-networking/service/">https://kubernetes.io/docs/concepts/services-networking/service/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82f83ac7b092" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kuma service mesh — Data plane token lifecycle]]></title>
            <link>https://sumanthkumarc.medium.com/kuma-service-mesh-data-plane-token-lifecycle-e28fb1fb2a5c?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e28fb1fb2a5c</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[kong]]></category>
            <category><![CDATA[kuma]]></category>
            <category><![CDATA[service-mesh]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 18:04:54 GMT</pubDate>
            <atom:updated>2022-08-03T18:08:56.198Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kuma service mesh — Data plane token lifecycle</h3><p>I generally sift through community slacks of open source tools, to see if i can help answer some questions. I stumbled upon this question about validation of Kuma data plane token at <a href="https://kuma-mesh.slack.com/archives/CN2GN4HE1/p1659536026513639">https://kuma-mesh.slack.com/archives/CN2GN4HE1/p1659536026513639</a> I was intrigued and wanted to dig through the Kuma code.</p><blockquote><strong>NOTE: This blog is just me thinking out loud while browsing through code at </strong><a href="https://github.com/kumahq/kuma">https://github.com/kumahq/kuma</a>. It does not guarantee technical accuracy and is just a code pointer for fellow kumans.</blockquote><blockquote>I would like to thank folks at @<a href="https://konghq.com/">konghq</a> for open sourcing this great software.</blockquote><p>So the first thing i know about data plane token is that every Data plane proxy needs to present a token to zonal CP (control plane) to get itself registered to the zone.</p><p>From official <a href="https://kuma.io/docs/1.6.x/security/dp-auth/#data-plane-proxy-token">doc</a> —</p><blockquote>The data plane proxy token is a <a href="https://jwt.io/">JWT token </a>that contains:</blockquote><blockquote>Mesh to which data plane belongs (required)</blockquote><blockquote>The name of a data plane proxy (optional)</blockquote><blockquote>List of tags that are permitted to use (optional)</blockquote><blockquote>Expiration date of the token (required, 10 years if not specified)</blockquote><blockquote>The Data plane proxy token is signed by a signing key that is autogenerated when Mesh is created. Tokens are never stored in the control plane, the only thing that is stored are signing keys that are used to verify if a token is valid. The signing key is RSA256 encrypted.</blockquote><pre># Example command to get token valid for all dp&#39;s in mesh<br>$~ kumactl generate dataplane-token --mesh mymesh --proxy-type dataplane</pre><p>I also knew that the token generated is a jwt token which is like data palne proxy verifying its identity with the zone CP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*smICM5ksqhVRvC9qN6jFYQ.png" /></figure><p>Some important fields are Mesh , Name and Tags . Also the exp — token expiry field. Default is 10 Years validity.</p><p>Since i didn’t have idea on server side, i started with what i knew — the cli command.</p><ol><li><strong><em>Generation</em></strong></li></ol><p>The code layout of <a href="https://github.com/kumahq/kuma">kumahq</a> always felt little easier to grasp. My favourite folders are app and pkg . App folder has all the tools we generally use, and interesting one for us is app/kumactl . It uses cobra package so i know the command layout. so went to kuma/app/kumactl/cmd/generate/generate_dataplane_token.go I saw that the client uses client.Generate which is essentially a http client which does a POST call to /tokens/dataplane endpoint.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b58aa2fac412a4f10e6454ca51e1ddb8/href">https://medium.com/media/b58aa2fac412a4f10e6454ca51e1ddb8/href</a></iframe><p>As per <a href="https://kuma.io/docs/1.6.x/security/dp-auth/#multizone">doc</a>, in multi-zone mode, the token can be created at both global level and zone level but Signing key rotation or token revocation should be performed on the global control plane.</p><p>I think in a logical way, tokens need to be created at global CP, because meshes can be part of multiple zones and in that case, logic feels token should be valid across zones 😆 Although in below section, we will find out that this doesn’t matter (<strong><em>hint</em></strong>: Token is synced).</p><p><strong><em>2. Validation</em></strong></p><p>So whenever a mesh gets created, it also ensures there is an associated data plane token signing key associated to this mesh.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b86d656bef2672a3fa96728b03a49643/href">https://medium.com/media/b86d656bef2672a3fa96728b03a49643/href</a></iframe><p>But the actual registration happens between DP proxy and Zone CP right? so Global and zones sync this signing key using <a href="https://github.com/kumahq/kuma/tree/master/pkg/kds">kds</a> (kuma discovery service). Reason why generating token at both zone and global works.</p><p>As per <a href="https://kuma.io/docs/1.6.x/security/dp-auth/#data-plane-proxy-token">doc</a>, generated dp tokens aren’t stored but are just validated through signing key. so whenever data plane proxy registers itself with zone CP, it authenticates the jwt token.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/afa77eb5cb8f5e386cda9d4886dd9af6/href">https://medium.com/media/afa77eb5cb8f5e386cda9d4886dd9af6/href</a></iframe><p><strong><em>3. Revocation</em></strong></p><p>From doc at <a href="https://kuma.io/docs/1.6.x/security/dp-auth/#token-revocation">https://kuma.io/docs/1.6.x/security/dp-auth/#token-revocation</a></p><blockquote>Kuma does not keep the list of issued tokens. Whenever the single token is compromised, we can add it to revocation list so it’s no longer valid.</blockquote><blockquote>Every token has its own ID which is available in payload under jti key.</blockquote><p>So as part of validation, token is checked if it is not in the revoke list.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2b3323c5caa163de4db53f7961541d1/href">https://medium.com/media/c2b3323c5caa163de4db53f7961541d1/href</a></iframe><p><strong>Happy meshing 🖖</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e28fb1fb2a5c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Debugging namespace deletion issue in Kubernetes]]></title>
            <link>https://sumanthkumarc.medium.com/debugging-namespace-deletion-issue-in-kubernetes-f6f8b40a4368?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6f8b40a4368</guid>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[namespaces]]></category>
            <category><![CDATA[kubernetes-namespaces]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Thu, 03 Feb 2022 19:26:55 GMT</pubDate>
            <atom:updated>2022-02-03T19:26:55.574Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-y1rXhYcDsimtdFl.png" /><figcaption>Image source — <a href="https://stacksimplify.com/azure-aks/azure-kubernetes-service-namespaces-imperative/">https://stacksimplify.com/azure-aks/azure-kubernetes-service-namespaces-imperative/</a></figcaption></figure><p>I got a support ticket from a developer about their job breaking and when checked, the issue was with namespace stuck in Terminating state forever. Namespace stuck in termination is one of the most classic problems faced by every Kubernetes engineer out there. Yet, the reasons are not always the same 🙃.</p><p>This article is about the experience while debugging namespace deletion issue in Kubernetes. Just one of many fun moments in the day to day life of an Kubernetes engineer :)</p><p>This article has 3 sections</p><ol><li><strong><em>Quick workaround</em></strong></li><li><strong><em>Debugging the underlying issue</em></strong></li><li><strong><em>Namespace deletion under the hood</em></strong></li></ol><blockquote>Workaround</blockquote><p>When i exported the namespace, the status showed that there was some issue with one of the objects —</p><pre>unable to retrieve the complete list of server APIs: external.metrics.k8s.io/v1beta1: the server is currently unable to handle the request</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/285032677183d8e5f607052d8f539524/href">https://medium.com/media/285032677183d8e5f607052d8f539524/href</a></iframe><p>Tried finding out which service uses/creates/manages this using</p><pre>~ k api-resources</pre><p>The results didn&#39;t have the external.metrics.k8s.io/v1beta1 resource and moreover also had message that it was unable to retrieve list.</p><p>Since this was blocking developer pipeline, i had to do cheap workaround to delete the namespace forcefully —</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/75ed6bdc7e224bdc3654ff2316a8281f/href">https://medium.com/media/75ed6bdc7e224bdc3654ff2316a8281f/href</a></iframe><p>Tried out patching/editing spec to remove finalizers, but didn&#39;t work. Finally the above script worked for me. What i did above essentially was, removing finalizers from namespace object. More about finalizers <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/finalizers/">here</a>.</p><blockquote>Debugging</blockquote><p>Now moving on, to fix the actual issue….</p><p>Upon brief ducking(<a href="https://duckduckgo.com/">DuckDuckGo</a> FTW), found that this was installed by external metrics adapter. Found this — <a href="https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/deploy/manifests/custom-metrics-apiservice.yaml#L37">https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/deploy/manifests/custom-metrics-apiservice.yaml#L37</a> We were testing external metric sources and my colleagues tried out <a href="https://github.com/kedacore/keda">Keda</a> as well on cluster. This also made me realise why the k api-resources didn’t yield this in list, it was using the aggregated api server. The error itself was saying unable to retrieve the complete list of server API&#39;s 🤦‍♂️</p><pre>~ k get APIService v1beta1.external.metrics.k8s.io</pre><pre>NAME                              SERVICE                                AVAILABLE                             AGE<br>v1beta1.external.metrics.k8s.io   <strong><em>keda/keda-operator-metrics-apiserver</em></strong>   <strong><em>False(MissingEndpoints)</em></strong>   13h</pre><p>So this cleared that the issue is with keda controller deployed into <strong><em>keda</em></strong> namespace. Upon checking, there was some issue with deployment and once the keda controller was fixed, the namespace deletion issue vanished.</p><pre>~ k get APIService v1beta1.external.metrics.k8s.io</pre><pre>NAME                              SERVICE                                AVAILABLE         AGE<br>v1beta1.external.metrics.k8s.io   keda/keda-operator-metrics-apiserver   <strong><em>True</em></strong>  13h</pre><blockquote>Peek under the hood</blockquote><p>How does the namespace deletion work under the hood?? 🤔</p><p>This took me to namespace package in the <a href="https://github.com/kubernetes/kubernetes/tree/master/pkg/controller/namespace">Kubernetes code repo</a></p><pre>➜  kubernetes/pkg/controller/namespace/namespace<br><br>.<br>├── OWNERS<br>├── config<br>│   ├── OWNERS<br>│   ├── doc.go<br>│   ├── types.go<br>│   ├── v1alpha1<br>│   │   ├── conversion.go<br>│   │   ├── defaults.go<br>│   │   ├── doc.go<br>│   │   ├── register.go<br>│   │   ├── zz_generated.conversion.go<br>│   │   └── zz_generated.deepcopy.go<br>│   └── zz_generated.deepcopy.go<br>├── deletion<br>│   ├── namespaced_resources_deleter.go <strong><em># File of our interest :p </em></strong><br>│   ├── namespaced_resources_deleter_test.go<br>│   ├── status_condition_utils.go<br>│   └── status_condition_utils_test.go<br>├── doc.go<br>└── namespace_controller.go        <strong><em># Main controller</em></strong></pre><pre>3 directories, 17 files</pre><p>namespace_controller.go spins up workers which read the namespace from the queue. Each worker picks a namespace from queue and syncs its status (think control loops) until it receives stop signal in its control channel.</p><p>There are multiple namespace conditions defined in deletion_controller as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d7db993d0ba1c38dca6c886bbd38ce7/href">https://medium.com/media/8d7db993d0ba1c38dca6c886bbd38ce7/href</a></iframe><p>The worker calls the deletion controller to determine the status of the namespace and sets its conditions accordingly on every sync cycle. The entire call stack is roughly as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d0326d2c39213b3a4e79bdd6fe376d1e/href">https://medium.com/media/d0326d2c39213b3a4e79bdd6fe376d1e/href</a></iframe><p>Issue in my case was, when the deletion controller tried to discover all the resources, the aggregated api server(keda in this case) didn’t respond with respective resources, leading to discovery failure.</p><p>Wow this code exploration felt very good 🥳 Ending this article with a hope that i’ll be writing more of these on various Kubernetes objects.</p><h3><strong>Reference links</strong></h3><ul><li><a href="https://kubernetes.io/docs/concepts/architecture/garbage-collection/">https://kubernetes.io/docs/concepts/architecture/garbage-collection/</a></li><li><a href="https://kubernetes.io/docs/tasks/administer-cluster/use-cascading-deletion/">https://kubernetes.io/docs/tasks/administer-cluster/use-cascading-deletion/</a></li><li><a href="https://github.com/kubernetes/kubernetes/tree/master/pkg/controller/namespace">https://github.com/kubernetes/kubernetes/tree/master/pkg/controller/namespace</a></li><li><a href="https://getemoji.com/">https://getemoji.com/</a> — for emojis 🤭</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6f8b40a4368" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes RBAC — Update default ClusterRoles without editing them]]></title>
            <link>https://sumanthkumarc.medium.com/kubernetes-rbac-update-default-clusterroles-without-editing-them-ef206254e0?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef206254e0</guid>
            <category><![CDATA[k8s-security]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[k8s]]></category>
            <category><![CDATA[rbac-access-control]]></category>
            <category><![CDATA[rbac]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Sun, 09 Jan 2022 10:54:26 GMT</pubDate>
            <atom:updated>2022-01-09T10:54:26.598Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nc-sa/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Kubernetes RBAC — Update default ClusterRoles without editing them</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sbnAKKeQxMXMZEOL.png" /><figcaption>Image used from <a href="https://support.huaweicloud.com/intl/en-us/usermanual-cce/cce_01_0189.html">https://support.huaweicloud.com/intl/en-us/usermanual-cce/cce_01_0189.html</a></figcaption></figure><p>Kubernetes RBAC helps us control access to various resources on the cluster. The RBAC API declares four kinds of Kubernetes object: <em>Role</em>, <em>ClusterRole</em>, <em>RoleBinding</em> and <em>ClusterRoleBinding.</em> In simpler terms, the concept of RBAC is as follows</p><ol><li>There are multiple actions which can be performed on various resources like GET, POST, WATCH, LIST, PATCH etc.</li><li>You group all the actions on resources which can be performed for easier management. These are <em>Role </em>and <em>ClusterRole.</em></li><li>You now assign these grouped permissions to Users using <em>RoleBinding</em> and <em>ClusterRoleBinding.</em></li></ol><p><em>Role</em> and <em>RoleBinding</em> are at namespace level, <em>ClusterRole</em> and <em>ClusterRoleBinding </em>are at cluster level.</p><p>There are also default <em>ClusterRoles </em>created by Kubernetes out of the box. You can find them at <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles">https://kubernetes.io/docs/reference/access-authn-authz/rbac/#user-facing-roles</a>. Listing them here for ease</p><ul><li><strong>cluster-admin </strong>—<strong> </strong>Allows super-user access to perform any action on any resource</li><li><strong>admin</strong> — Full admin access, intended to be granted within a namespace</li><li><strong>edit — </strong>Edit access except for editing RBAC</li><li><strong>view </strong>— Allows view for most of objects</li></ul><p>Now this is all good in theory, but real time use cases are always different. In my case the team wanted the access as below —</p><ol><li>Basic access — Full view plus rudimentary edit access to resources like deleting pods, exec’ing to pods, editing HPA etc. at namespace level.</li><li>Edit access — Edit access to all resources at namespace level.</li></ol><p>Now this mean i can’t just use View ClusterRole for #1 because we needed few edit accesses as well. Another way is maintaining our own list of View + edit accesses as another <em>ClusterRole</em>. This felt redundant and need to update <em>ClusterRole</em> for new CRD’s every now and then. This is where the Aggregated ClusterRoles come to help. Quoting from <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/#aggregated-clusterroles">doc</a></p><blockquote>You can <em>aggregate</em> several ClusterRoles into one combined ClusterRole. A controller, running as part of the cluster control plane, watches for ClusterRole objects with an aggregationRule set. The aggregationRule defines a label <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/">selector</a> that the controller uses to match other ClusterRole objects that should be combined into the rules field of this one.</blockquote><p>So in layman terms, we can maintain multiple separate <em>ClusterRoles </em>and bubble/aggregate them to other cluster roles without editing them directly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3f01cd610db45fff37dbe8f6c03936da/href">https://medium.com/media/3f01cd610db45fff37dbe8f6c03936da/href</a></iframe><p><em>We maintain just the extra rules in our own ClusterRole.</em></p><p>This is same as just any other ordinary <em>ClusterRole</em> but with one exception of the label</p><pre>rbac.authorization.k8s.io/aggregate-to-view: &quot;true&quot;</pre><p>Now when we check the main View ClusterRole we can find that our rules are automatically aggregated into it dynamically 😱😍</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c143107c67f2305938664351e9ba2ab/href">https://medium.com/media/7c143107c67f2305938664351e9ba2ab/href</a></iframe><p>The magic here is done by aggregationRule in the ClusterRole. The controller watches the ClusterRoles and merges the rules from other ClusterRoles which has the label defined, and in our case:</p><pre>rbac.authorization.k8s.io/aggregate-to-view: true</pre><p><strong>NOTE — This method aggregates the rules to default </strong><strong><em>View</em> ClusterRole which might be used by third party serviceaccounts and others. Use with caution.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef206254e0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customizing Python argparse for Slack slash commands]]></title>
            <link>https://sumanthkumarc.medium.com/customizing-python-argparse-for-slack-slash-commands-15831a242e71?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/15831a242e71</guid>
            <category><![CDATA[argparse]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[slack]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Tue, 04 May 2021 04:55:16 GMT</pubDate>
            <atom:updated>2021-05-04T04:55:16.611Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hQsoLcaukVhipLSIh8TN5w.png" /></figure><p>We all love slack for the slick UI and its many features. Slack also has apps and something called slash commands to boost productivity. So what are slash commands?</p><blockquote>Slash commands act as shortcuts for specific actions in Slack. There are three types of slash commands that you may be able to use in your workspace:</blockquote><blockquote><a href="https://slack.com/intl/en-in/help/articles/201259356-Slash-commands-in-Slack#h_01EPZ2Z81EJ67RA2BGDKZ9M1AN">Built-in slash commands</a> created by Slack</blockquote><blockquote>App slash commands created by developers</blockquote><blockquote><a href="https://slack.com/help/articles/360001623607-Create-commands-for-Slack-apps">Customised slash commands</a> created by members of your organisation</blockquote><p>More at <a href="https://api.slack.com/interactivity/slash-commands">https://api.slack.com/interactivity/slash-commands</a></p><p>The third option helps us do custom actions using our own slack commands. See <a href="https://api.slack.com/tutorials/your-first-slash-command">https://api.slack.com/tutorials/your-first-slash-command</a> for creation of custom slash commands. This article assumes you have custom slack command for some app already installed which can be invoked like:</p><pre>/my-command</pre><p>In layman terms, slash commands are like text which is POST’ed to some webhook/endpoint. So in above case /my-command is send as text body to some endpoint. You can even do something like below too:</p><pre>/my-command foo --bar=baz</pre><p>Like a command line binary syntax but simply from slack 🤗 Awesome right 😍</p><p>Assuming the webhook or endpoint runs Python app, we can use super powerful python argparse cli library to handle this slack slash command. While in principle, since we get simple text command from slack, we can break the string and parse what command has been sent and options passed etc and do custom validations and send nice error messages. But why go all the lengths when we have super cool library already available to do all these 🤭</p><p>For the above given command, assuming foo as argument —bar as an optional parameter, the simple python code would be as below:</p><pre>import argparse<br><br>parser = argparse.ArgumentParser(description=&#39;Process my command&#39;)<br>parser.add_argument(<strong>&#39;foo&#39;</strong>, type=str, help=<strong>&#39;Magic of foo&#39;</strong>)<br>parser.add_argument(<br>    <strong>&#39;--bar</strong>&#39;,<br>    action=<strong>&#39;store</strong>&#39;,<br>    required=False,<br>    type=str,<br>    default=<strong>&#39;baz</strong>&#39;,<br>    help=<strong>&#39;Bar optional param</strong>&#39;,<br>)<br><br>args = parser.parse_args(command.split())</pre><p>Here the parser.parse_args() takes the input from stdin by default or can be supplied with our own args like parser.parse_args(&#39;foo --bar=baz&#39;.split())</p><p>So basically what the above code does is declare the command params and manually feed the slack slash command we received as text in our python app.</p><p>Now this all seems good until we hit an error or help text. argparse. Because by default argparse prints to stdout and exit 😕 Doesn’t exactly help with our REST app right!!!</p><p>So we now have two issues to resolve before we go ahead to use argparse in our app:</p><ol><li>Argparse exits on error or help flag. ← No, don’t exit.</li><li>Argparse prints out error/help flag to stdout — we need to send back this as response to slack. ← Capture the error/help text.</li></ol><p>The easiest solution for #1 above is to override only those methods from the main ArgumentParser class which exits 🙃 Source for exiting methods at <a href="https://github.com/python/cpython/blob/3.8/Lib/argparse.py#L2503">https://github.com/python/cpython/blob/3.8/Lib/argparse.py#L2503</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a76010ca9972623803e21cbe80e8a157/href">https://medium.com/media/a76010ca9972623803e21cbe80e8a157/href</a></iframe><p>Now our code just uses our CustomArgumentParser class instead of main class, So the code changes to this:</p><pre>import CustomArgumentParser<br><br>parser = CustomArgumentParser(description=&#39;Process my command&#39;)<br>parser.add_argument(<strong>&#39;foo&#39;</strong>, type=str, help=<strong>&#39;Magic of foo&#39;</strong>)<br>parser.add_argument(<br>    <strong>&#39;--bar</strong>&#39;,<br>    action=<strong>&#39;store</strong>&#39;,<br>    required=False,<br>    type=str,<br>    default=<strong>&#39;baz</strong>&#39;,<br>    help=<strong>&#39;Bar optional param</strong>&#39;,<br>)<br><br>args = parser.parse_args(command.split())</pre><p>Now for #2 problem of capturing stdout, StringIO class in python comes to our rescue. — <a href="https://docs.python.org/3.8/library/io.html#io.StringIO">https://docs.python.org/3.8/library/io.html#io.StringIO</a></p><pre>from io import StringIO<br>import sys<br># hack to capture stdout for argparse help/error and send it to <br># client.<br>sys.stdout = result = StringIO()<br>error_text = &#39;&#39;<br>try:<br>    cmd_params = p.parser.parse_args(command.split())<br>except:<br>    # Restore the stdout stream for future code.<br>    sys.stdout = sys.__stdout__<br>    error_text = result.getvalue()</pre><p>In brief, we are just overriding stdout with our StringIO stream and thereby capturing everything written on stdout into our string. Neato 🤭</p><p>The overall code translates roughly into this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/702c05ec71617f9f4193e3dcba278797/href">https://medium.com/media/702c05ec71617f9f4193e3dcba278797/href</a></iframe><p>— Stay Positive and Test Negative —</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15831a242e71" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS — Deploying clustered Rabbitmq on EKS]]></title>
            <link>https://sumanthkumarc.medium.com/aws-deploying-clustered-rabbitmq-on-eks-5f2d9bd6afdc?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f2d9bd6afdc</guid>
            <category><![CDATA[rabbitmq-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[rabbitmq]]></category>
            <category><![CDATA[eksctl]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Mon, 18 Jan 2021 18:07:18 GMT</pubDate>
            <atom:updated>2021-01-18T18:16:48.229Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS — Deploying Rabbitmq cluster on EKS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XD5URYDsX9OP9qFi.png" /><figcaption>Image source: <a href="https://aws.amazon.com/eks/">https://aws.amazon.com/eks/</a></figcaption></figure><p>Amazon Elastic Kubernetes Service (Amazon EKS) is a managed service that you can use to run Kubernetes on AWS without needing to install, operate, and maintain your own Kubernetes control plane or nodes.</p><p>EKS gives you a fully managed, highly available control plane(Kubernetes API servers and the etcd persistence layer).</p><p>For data plane, you have option to either use</p><ol><li>Self managed nodes — EC2 worker nodes and other related resources you create and maintain in your own account. Billed for all the resources which you create.</li><li>Managed node groups — All resources are created same like above in your account but AWS creates them for you. You need to maintain it though like patching the OS etc.</li><li>AWS Fargate — This is the container service managed by AWS and now provides ability to deploy pods to this service. This is not like EC2 instance and resources are not created in your account. You only pay for per pod usage(like cpu and memory). Nothing to manage like OS patching etc.</li></ol><p>More about available compute options here- <a href="https://docs.aws.amazon.com/eks/latest/userguide/eks-compute.html">https://docs.aws.amazon.com/eks/latest/userguide/eks-compute.html</a></p><p>For this example, we are going with Managed node groups. The quickest and easiest way to start with EKS is using <a href="https://eksctl.io/">eksctl</a>. From docs:</p><blockquote>eksctl is a simple CLI tool for creating clusters on EKS - Amazon&#39;s new managed Kubernetes service for EC2. It is written in Go, uses CloudFormation, was created by <a href="https://www.weave.works/">Weaveworks</a> and it welcomes contributions from the community.</blockquote><p>There are two primary ways to create cluster using eksctl.</p><ol><li>Using eksctl cli. Easiest and fastest but difficult to provide all minute details especially when using node groups. If you want to go with Fargate, this is best option.</li><li>Using cluster.yaml file which describes all the details. Schema at <a href="https://eksctl.io/usage/schema/">https://eksctl.io/usage/schema/</a> and config examples at <a href="https://github.com/weaveworks/eksctl/tree/master/examples">https://github.com/weaveworks/eksctl/tree/master/examples</a></li></ol><p>Even though it’s easier to create custom config for node groups in cluster.yaml, for simplicity we will go with eksctl cli.</p><h3>1. Cluster creation</h3><p>Let’s create cluster with below command. We will create node groups later.</p><pre>eksctl create cluster \<br> — name eks-test \<br> — version 1.18 \<br> — with-oidc \<br> — without-nodegroup</pre><p>After successful completion of above command, your kubeconfig is stored at default location <em>~/.kube/config</em>. oidc(OpenID connect) is useful for authentication. For example in use case like assigning iam role to kubernetes service accounts as described <a href="https://sumanthkumarc.medium.com/eks-accessing-aws-services-from-fargate-pods-375e14ae7007">here</a>.</p><p>Next let’s create managed node group using below command. The &lt;SSH_KEY&gt; can either be path on your machine to public key or the existing ssh key pair in your AWS region.</p><pre>eksctl create nodegroup \<br> — cluster eks-test \<br> — region us-west-1 \<br> — name eks-ng \<br> — node-type t2.micro \<br> — nodes 3 \<br> — nodes-min 2 \<br> — nodes-max 4 \<br> — ssh-access \<br> — ssh-public-key &lt;SSH_KEY&gt; \<br> — managed</pre><p>This would create EKS cluster with a managed node group of 3 nodes.</p><h3>2. Nginx ingress controller</h3><p>Deploy nginx ingress controller using below command taken from <a href="https://kubernetes.github.io/ingress-nginx/deploy/#network-load-balancer-nlb">docs</a>.</p><pre>kubectl apply -f <a href="https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.43.0/deploy/static/provider/aws/deploy.yaml">https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.43.0/deploy/static/provider/aws/deploy.yaml</a></pre><p>This provides you with normal http endpoint by launching a network load balancer in your region. See <a href="https://kubernetes.github.io/ingress-nginx/deploy/#tls-termination-in-aws-load-balancer-elb">this</a> if you need TLS termination as well, meaning https endpoints. Take note of lb url which will be used to access Rabbitmq UI in later steps.</p><h3>3. Deploy RabbitMQ</h3><p>Use manifests at <a href="https://github.com/sumanthkumarc/k8s-rabbitmq-clustered">https://github.com/sumanthkumarc/k8s-rabbitmq-clustered</a> to deploy RabbitMQ.</p><p>The setup consists of statefulset with <em>rabbitmq_peer_discovery_k8s </em>plugin. The clustering requirements of RabbitMQ are at <a href="https://www.rabbitmq.com/clustering.html#cluster-formation-requirements">https://www.rabbitmq.com/clustering.html#cluster-formation-requirements</a></p><p><strong>NOTE:</strong> The service.yaml has ingress resource which needs the lb url to be replaced in the hosts section.</p><p>You can now access the RabbitMQ UI at lb url.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZHYjNzse0vI_Hr0VcrlDZQ.png" /><figcaption>RabbitMQ management UI</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f2d9bd6afdc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[EKS — Accessing AWS services from Fargate pods]]></title>
            <link>https://sumanthkumarc.medium.com/eks-accessing-aws-services-from-fargate-pods-375e14ae7007?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/375e14ae7007</guid>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[aws-fargate]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws-eks-fargate]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Wed, 30 Dec 2020 12:13:48 GMT</pubDate>
            <atom:updated>2020-12-30T12:13:48.420Z</atom:updated>
            <content:encoded><![CDATA[<h3>EKS — Accessing AWS services from Fargate pods</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gS_1kpdnEkzyv4Ql.png" /><figcaption>Image copied from ItNext blog <a href="https://itnext.io/eks-fargate-extensibility-of-kubernetes-serverless-benefits-77599ac1763?gi=725777cd6078">here</a></figcaption></figure><p>There is always need to access other AWS services from inside the pods launched by EKS on fargate.</p><p>One way to achieve this, is by mounting the AWS access/secret creds as environment vars in the pod.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: bb<br>spec:<br>  containers:<br>  - image: busybox<br>    name: bb<br>    <strong>env:    <br>    - name: &#39;AWS_ACCESS_KEY_ID&#39;<br>      value: &#39;&lt;AWS_ACCESS_KEY_ID&gt;&#39;<br>    - name: &#39;AWS_SECRET_ACCESS_KEY&#39;<br>      value: &#39;&lt;AWS_SECRET_ACCESS_KEY&gt;&#39;<br>    - name: &#39;AWS_DEFAULT_REGION&#39;<br>      value: &#39;&lt;AWS_DEFAULT_REGION&gt;&#39;</strong></pre><p>but these are secrets and they are better to be created as secrets and mounted as env in pod. You can create secret with some name &lt;MY_AWS_SECRET&gt; with below command:</p><pre>kubectl create secret generic &lt;MY_AWS_SECRET&gt; --from-literal &quot;AWS_ACCESS_KEY_ID=<strong>&lt;AWS_ACCESS_KEY_ID&gt;</strong>&quot; --from-literal &quot;AWS_SECRET_ACCESS_KEY=<strong>&lt;AWS_SECRET_ACCESS_KEY&gt;</strong>&quot; --from-literal &quot;AWS_DEFAULT_REGION=<strong>&lt;AWS_DEFAULT_REGION&gt;&quot;</strong></pre><p>Use the pod spec envFrom key to mount all its keys as env in pod.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: bb<br>spec:<br>  containers:<br>  - image: busybox<br>    name: bb<br>    <strong>envFrom:<br>    - secretRef:<br>        name: &lt;SECRET_NAME&gt;</strong></pre><p>If you do not want to manage secrets in Kubernetes for whatever reasons, you can use AWS Secrets manager to manage/rotate secrets as described at <a href="https://aws.amazon.com/blogs/containers/aws-secrets-controller-poc/">https://aws.amazon.com/blogs/containers/aws-secrets-controller-poc/</a> but the article suggests that this is not intended for production use. Also AWS secret manager has it’s own pricing for storing and accessing secrets. You could also encrypt secrets as explained <a href="https://aws.amazon.com/blogs/containers/using-eks-encryption-provider-support-for-defense-in-depth/">here</a></p><p>All this aside, it’s always good practice to use iam roles attached to instance to access AWS services instead of access keys. This is described at <a href="https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html">https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html</a></p><p>We will essentially be creating a serviceaccount in Kubernetes and associate this to an AWS iam role.</p><blockquote><strong><em>NOTE:</em></strong> One might think that we could just attach an iam role to fargate pod and access services using this, similar to an EC2 instance role. But as doc suggests, the Pod execution role which we attach to each fargate pod is only used by kubelet to register as Node with EKS cluster. The containers running in the Fargate pod cannot assume the IAM permissions associated with the pod execution role. Doc at <a href="https://docs.aws.amazon.com/eks/latest/userguide/pod-execution-role.html">https://docs.aws.amazon.com/eks/latest/userguide/pod-execution-role.html</a></blockquote><p>Now let’s go do this:</p><ol><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html"><strong>Create an IAM OIDC provider for your cluster</strong></a><strong> </strong>— Chances are you already have oidc provider in your cluster if you created it with eksctl. if not, you can easily enable it using above doc link. You will get an oidc connect url in EKS cluster details page in console if it’s enabled. Note down the oidc connect url, which will be used in later steps.</li><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/create-service-account-iam-policy-and-role.html"><strong>Create an IAM role and attach an IAM policy to it with the permissions that your service accounts need</strong></a><strong> — </strong>Create an IAM role with web identity provider<strong> </strong>url(https://medium.com/select%20the%20oidc%20url%20from%20above), attach necessary permissions and save the role ARN you got. Steps in the above doc should be straight forward.</li></ol><p><strong>NOTE:</strong> For service account name and namespace in the IAM role, put the name of the service account you intend to create. It’s ok even if the service account isn’t yet created.</p><p>3. <a href="https://docs.aws.amazon.com/eks/latest/userguide/specify-service-account-role.html"><strong>Associate an IAM role with a service account</strong></a> — Create a service account in kubernetes with annotation which helps associate serviceaccount with the IAM role.</p><pre>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  annotations:<br>    eks.amazonaws.com/role-arn: <strong>&lt;ROLE_ARN&gt;</strong><br>  name: <strong>&lt;MY_SERVICE_ACCOUNT_NAME&gt;</strong><br>...</pre><p>4. Enable pod to use the service account we created.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: bb<br>spec:<br>  containers:<br>  - image: busybox<br>    name: bb<br>  serviceAccountName: <strong>&lt;MY_SERVICE_ACCOUNT_NAME&gt;</strong></pre><p>We need to delete and re-create pods to use this service account. To confirm if everything went alright with this process, you should be able to see the below env vars in pod.</p><pre>AWS_ROLE_ARN=<strong>&lt;ROLE_ARN&gt;</strong><br>AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token</pre><p>If you have aws cli in your pod, you can just do:</p><pre>aws sts get-caller-identity</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=375e14ae7007" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing MongoDB on Kubernetes with locust — First impressions — Part 2]]></title>
            <link>https://sumanthkumarc.medium.com/testing-mongodb-on-kubernetes-with-locust-first-impressions-part-2-7a5d68213efb?source=rss-4ac2ca66499d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a5d68213efb</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[load-testing]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[locust]]></category>
            <dc:creator><![CDATA[Sumanth Reddy]]></dc:creator>
            <pubDate>Sat, 17 Oct 2020 14:46:39 GMT</pubDate>
            <atom:updated>2020-10-17T14:46:39.962Z</atom:updated>
            <content:encoded><![CDATA[<h3>Testing MongoDB on Kubernetes with locust — First impressions — Part 2</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gBCzCbRvZVxzmwMhkpqCg.png" /></figure><p>This article gives my first impressions on trying out load testing Mongodb on Kubernetes with Locust load testing framework.</p><p>The <a href="https://medium.com/@sumanthkumarc/testing-mongodb-on-kubernetes-with-locust-first-impressions-part-1-f537adfc56cf">first part</a> deals with the Mongo application and connecting to it from my laptop for running the tests.</p><p>From <a href="https://docs.locust.io/en/stable/what-is-locust.html">https://docs.locust.io/en/stable/what-is-locust.html</a></p><blockquote>Locust is an easy to use, scriptable and scalable performance testing tool.</blockquote><blockquote>You define the behaviour of your users in regular Python code, instead of using a clunky UI or domain specific language.</blockquote><blockquote>This makes Locust infinitely expandable and very developer friendly.</blockquote><p>Even though the reason for going with locust was ease of installation, i instantly fell in love with clean, minimalist UI and very low entry barrier.</p><p><strong>Prerequisites:</strong> Python 3.6+ , pip3</p><p>Installation <a href="https://docs.locust.io/en/stable/installation.html">https://docs.locust.io/en/stable/installation.html</a> was pretty simple:</p><pre>$ pip3 install locust</pre><p>I’m ready to write locust tests now. I searched for a super quick video on youtube on writing a simple locust file. One video i liked is <a href="https://www.youtube.com/watch?v=L5Tjh19540I">https://www.youtube.com/watch?v=L5Tjh19540I</a></p><p>so i ended writing a super simple python file as below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/071958de1190313f6c47e35b8e4eb125/href">https://medium.com/media/071958de1190313f6c47e35b8e4eb125/href</a></iframe><p><strong>PS: </strong>The above require pymongo package to be installed.</p><p>Writing locust tests is pretty simple. You just need to extend User class and annotate the function which does your work with @task annotation.</p><p>From <a href="https://docs.locust.io/en/stable/writing-a-locustfile.html#user-class">https://docs.locust.io/en/stable/writing-a-locustfile.html#user-class</a></p><blockquote>A user class represents one user (or a swarming locust if you will). Locust will spawn one instance of the User class for each user that is being simulated.</blockquote><p>If you want to write a http load testing, you can extend Httpuser which has inbuilt support for making http requests. If you want to write tests for any task like say load testing a database, you can extend User class.</p><p>From <a href="https://docs.locust.io/en/stable/writing-a-locustfile.html#tasks">https://docs.locust.io/en/stable/writing-a-locustfile.html#tasks</a></p><blockquote>When a load test is started, an instance of a User class will be created for each simulated user and they will start running within their own green thread. When these users run they pick tasks that they execute, sleep for awhile, and then pick a new task and so on.</blockquote><p>So in short there are just 4 steps to be done for writing your locust tests:</p><ol><li>Extend the user class.</li><li>Write a function which does your work and add a @task annotation. Add a wait_time variable which defines how much time the tasks should sleep. This is mandatory and you can set any time you want.</li><li>You can set if a request is success or failure by firing an event using environment.events.request_success.fire or environment.events.request_failure.fire method. This will help locust record the request success/failure data.</li><li>Run the locust framework using locust -f FILE_NAME.PY . This will open up a UI which can be used to set users and rate of swarming users.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9gBCzCbRvZVxzmwMhkpqCg.png" /></figure><p>If you don’t want to provide a UI, you can provide it on cli too.</p><pre>$ locust --users 10000 --spawn-rate 100</pre><p>You can read more about the in-built classes at <a href="https://docs.locust.io/en/stable/api.html#api">https://docs.locust.io/en/stable/api.html#api</a></p><p><strong>Observations: </strong>The requests per second (RPS) was not so great, it reached ~200 for me. Probably because of limited cpu cores on my laptop. I guess it’s better if we can run distributed locust for more efficient load testing <a href="https://docs.locust.io/en/stable/running-locust-distributed.html">https://docs.locust.io/en/stable/running-locust-distributed.html</a></p><p>Happy load testing :P</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a5d68213efb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>