<?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 Samuel Bagattin on Medium]]></title>
        <description><![CDATA[Stories by Samuel Bagattin on Medium]]></description>
        <link>https://medium.com/@samuelbagattin?source=rss-d75a731a8880------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*v8m1ctGmptADr3aU6d5DZA.jpeg</url>
            <title>Stories by Samuel Bagattin on Medium</title>
            <link>https://medium.com/@samuelbagattin?source=rss-d75a731a8880------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:40:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samuelbagattin/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[Addressing private IPv4 shortage : 5 Strategies for Amazon EKS]]></title>
            <link>https://medium.com/ekino-france/kubernetes-addressing-private-ipv4-shortage-5-strategies-for-amazon-eks-1dc3df270ed8?source=rss-d75a731a8880------2</link>
            <guid isPermaLink="false">https://medium.com/p/1dc3df270ed8</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[container-orchestration]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Samuel Bagattin]]></dc:creator>
            <pubDate>Thu, 21 Dec 2023 10:11:12 GMT</pubDate>
            <atom:updated>2023-12-21T10:13:15.116Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h3>Addressing private IPv4 shortage: 5 Strategies for Amazon EKS</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lHyThdt156PtP8SI" /><figcaption>Photo by <a href="https://unsplash.com/@tvick?utm_source=medium&amp;utm_medium=referral">Taylor Vick</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Everyone who works with Amazon EKS has already faced the challenge of IPv4 scarcity. We will explore 5 solutions to mitigate or to end this problem.</p><h3>Context</h3><p>In Kubernetes, you have to use a Container Network Interface plugin (CNI) to allow pods to communicate with each other with their respective IP addresses.</p><p>When using Amazon EKS, by default you get the VPC Container Network Interface (CNI). This plugin is installed as a daemonset in the cluster.</p><p>EKS Networking with VPC CNI​ uses AWS VPC resources such as Elastic Network Interfaces (ENI) and IP addresses that exist in the VPC and subnets. The CNI plugin allows Kubernetes Pods to have the same IP address as they do on the VPC network.</p><p>It provisions one secondary IP address (an ENI has 1 primary and multiple secondary ones) for each pod in the cluster, which can take up a lot of IP space in your subnets.</p><figure><img alt="IPv4 allocation by the VPC CNI" src="https://cdn-images-1.medium.com/max/1024/0*Uf8BihSF5suH0F1C.png" /><figcaption>IPv4 allocation by the VPC CNI</figcaption></figure><h4>Why not use another CNI?</h4><p>You can disable native AWS IPs provisioning by using another CNI. IPv4 management will work in the following way:</p><ul><li>IP addresses of pods are scoped to the internal network​</li><li>Pods are not directly reachable from outside the cluster​</li><li>Every pod uses the primary node ENI</li></ul><p>There are many benefits you lose by dropping the VPC CNI:</p><ul><li><a href="https://docs.aws.amazon.com/eks/latest/userguide/security-groups-for-pods.html">Security group for pods</a></li><li>Pod identification in <a href="https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html">VPC flow logs</a></li><li><a href="https://kubernetes-sigs.github.io/aws-load-balancer-controller/v2.6/deploy/pod_readiness_gate/">Pod readiness gate</a> with load balancer controller</li><li>Simpler networking: no overlay network, you use the network provided by Amazon VPC</li></ul><p>We will focus in this article on keeping the usage of VPC CNI.</p><h3><strong>An easy change: VPC CNI tweaking</strong>​</h3><p>There are several environment variables used by the VPC CNI to configure its behavior. We will address WARM_ENI_TARGET and WARM_IP_TARGET.</p><p><strong>WARM_ENI_TARGET</strong>: Specifies the number of free elastic network interfaces and all of their available IP addresses. For WARM_ENI_TARGET = 1, A full ENI of unused IP addresses will be provisioned. <br>The maximum number of IPs by ENI is tied to the ec2 instance type. For example, there are 15 IPs on an ENI for an m6a.xlarge. You can find the reference in <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html">the AWS Documentation</a>.</p><p><strong>Unless you have specific requirements, I would advise you to set WARM_ENI_TARGET to 0.</strong></p><p><strong>WARM_IP_TARGET: </strong>Specifies the number of free IP addresses that should be kept at all times on all interfaces.</p><p>When a pod is scheduled on a node, if there are no IP addresses available on all ENIs, there can be an added delay before the pod starts because the VPC CNI plugin is provisioning resources (by calling <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_AssignPrivateIpAddresses.html">AssignPrivateIpAddress</a>).</p><p><strong>Due to this risk, it is a good practice to set WARM_IP_TARGET to at least 1.</strong></p><h3>When using prefix delegation: use subnet CIDR reservation</h3><p>With the VPC CNI, you have the ability to configure IPv4 allocation to be either</p><ul><li>Individual secondary IPv4 addresses (the default mode)</li><li>Or whole /28 prefixes: <a href="https://docs.aws.amazon.com/eks/latest/userguide/cni-increase-ip-addresses.html">Prefix delegation</a> (used when you need larger pod density per node)</li></ul><p>For a prefix to be allocated, a whole /28 range should be available. If at least one IPv4 has been taken beforehand, the prefix cannot be allocated. If there is no contiguous free /28 prefix in your subnet, the allocation fails and your pod will not start (even if there are hundreds of IPs available)</p><p>The diagram below outlines this situation:</p><figure><img alt="CIDR prefix that fails to allocate due to fragmented subnet" src="https://cdn-images-1.medium.com/max/1024/1*Gs0b5TZXK78zrRx-JTCyyA.png" /><figcaption>CIDR prefix that fails to allocate due to fragmented subnet</figcaption></figure><p>One solution to overcome this problem is using <a href="https://docs.aws.amazon.com/vpc/latest/userguide/subnet-cidr-reservation.html">VPC subnet CIDR reservation</a>. This feature allows to <strong>pre-allocate many CIDR ranges, that can only be used by whole /28 prefixes and not individual IP addresses</strong></p><p>You can learn more about this feature in the <a href="https://docs.aws.amazon.com/eks/latest/userguide/cni-increase-ip-addresses.html">AWS documentation</a></p><p>If you still have IP scarcity issues even after these 2 first improvements, the following ones have more impact but require more work to achieve.</p><h3><strong>VPC CNI Custom Networking using Internal SNAT</strong>​</h3><p>The following setup involves 2 features of VPC CNI</p><ul><li>Custom Networking: allows to have a separate ENI configuration between pods and their node. Practically, we will configure all pods to ENIs in another subnet than the one used by the node</li><li>Internal SNAT: routes the outbound traffic from pods to anywhere outside their subnet through the primary IP of the node.</li></ul><p>The diagram below shows an overview of the solution:</p><figure><img alt="Custom networking with internal SNAT" src="https://cdn-images-1.medium.com/max/1024/1*eVhgvULUl-76l-LwOnXCPA.png" /><figcaption>Custom networking with internal SNAT</figcaption></figure><ul><li>We create dedicated subnets for the pods. These ones should not be routable from outside the VPC (we can call these subnets <em>internal</em>)</li><li>New subnets can have any CIDR block, but a good choice is to use <a href="https://en.wikipedia.org/wiki/Carrier-grade_NAT">CG-NAT space</a> because companies don’t usually use these ranges for private networks.</li><li>Use custom networking use the new subnets for pods ENIs (more information on <a href="https://aws.github.io/aws-eks-best-practices/networking/custom-networking/#example-configuration">EKS best practices guide</a>)</li><li>Internal SNAT is enabled by default when using custom networking (see <a href="https://docs.aws.amazon.com/eks/latest/userguide/external-snat.html">AWS documentation</a>)</li></ul><p>With this configuration:</p><ul><li>Network flow from pod to pod will not be NAT-ed. You will see pods IPs in the VPC flow logs</li><li>Network flow from a load balancer in the same VPC to any pod is possible without any NAT</li><li>Network flow from a pod to an address IP not associated with a pod is NAT-ed through the primary node ENI.</li><li>Ingress traffic from outside the VPC to the pods should pass through a load balancer (a.k.a layer 4 proxy) located in non-internal subnets</li><li>You can create as many subnets with overlapping CIDR in different VPCs as you want.</li></ul><h3><strong>NATted data-plane with private NAT gateway</strong></h3><p>A more recent solution to address the issue is using <strong>private NAT gateways</strong>, described in <a href="https://aws.amazon.com/blogs/containers/addressing-ipv4-address-exhaustion-in-amazon-eks-clusters-using-private-nat-gateways/">this blog post.</a></p><figure><img alt="Architecture overview of pods from overlapping CIDRs communicating through a private NAT gateway" src="https://cdn-images-1.medium.com/max/1024/1*JulkHfcN_Ebpe-tTgXXz0w.png" /><figcaption>Architecture overview of pods from overlapping CIDRs communicating through a private NAT gateway</figcaption></figure><p>Since mid-2021, you can create <a href="https://aws.amazon.com/about-aws/whats-new/2021/06/aws-removes-nat-gateways-dependence-on-internet-gateway-for-private-communications">private NAT gateways</a>, allowing you to NAT the entire EKS data plane:</p><ul><li>You create nonroutable subnets (preferably with CIDR ranges from CG-NAT space), but this time for hosting all the data place IPs (pods and nodes)</li><li>This removes the need for Kubernetes-specific configuration to separate node and pods ENIs</li></ul><p>There is a caveat to keep in mind: you get charged per private NAT gateway and for data processing costs for VPC-to-VPC communication. This has to be put in perspective with your whole bill for the EKS infrastructure.</p><h3>IPv6</h3><p>The most future-proof solution to solve IPv4 exhaustion — but the most disruptive — is setting up IPv6.</p><p>Here are some advantages of using IPv6:</p><ul><li>The network infrastructure is simpler: network flow does not need to go through a NAT gateway. Your pods are assigned a public IPv6 address, this simplifies troubleshooting.</li><li>Cost reduction: IPv6 to public IPv6 traffic does not charge you for NAT gateway data processing.</li><li>You can still keep compatibility with existing IPv4-only infrastructure using <a href="https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-nat64-dns64.html">NAT64/DNS64</a></li></ul><p>There are 2 ways to run IPv6 currently on EKS.</p><p>The first one is using dual-stack subnets for the data plane (<a href="https://aws.github.io/aws-eks-best-practices/networking/ipv6/">discussed in the EKS best practices website</a>):</p><ul><li>Every pod has only an IPv6 address</li><li>The node has an IPv4 and an IPv6 address</li><li>For egress traffic from a pod to an IPv4 address, the behavior is similar to using custom networking, the traffic goes through the primary node IP address.</li></ul><figure><img alt="Custom logic for IPv6 to IPv4 translation by the VPC CNI" src="https://cdn-images-1.medium.com/max/1024/0*MhFB6RGg29swm7h4.png" /><figcaption>Custom logic for IPv6 to IPv4 translation by the VPC CNI</figcaption></figure><p>The second one uses IPv6-only subnets:</p><ul><li>This currently requires to use <a href="https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-nat64-dns64.html">NAT64/DNS64</a> for nodes and pods to be able to communicate with the API server because the <a href="https://aws.github.io/aws-eks-best-practices/networking/ipv6/#maintain-access-to-ipv4-eks-apis">EKS API server does not yet support IPv6</a>. This is one reason that explains why EKS is <a href="https://github.com/aws/containers-roadmap/issues/1805">not officially IPv6 only</a></li><li>This solution is preferred as it does not involve custom logic with the host&#39;s local CNI, and <a href="https://docs.aws.amazon.com/vpc/latest/userguide/nat-gateway-nat64-dns64.html">NAT64/DNS64</a> is widely supported by AWS.</li></ul><h3>Conclusion</h3><p>Here is a matrix summarising the main characteristics of each solution:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MMWLohzdOKU69N6hyPxGHQ.png" /></figure><p>​</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1dc3df270ed8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ekino-france/kubernetes-addressing-private-ipv4-shortage-5-strategies-for-amazon-eks-1dc3df270ed8">Addressing private IPv4 shortage : 5 Strategies for Amazon EKS</a> was originally published in <a href="https://medium.com/ekino-france">ekino-france</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Partial Helm values encryption using AWS KMS with ArgoCD]]></title>
            <link>https://medium.com/@samuelbagattin/partial-helm-values-encryption-using-aws-kms-with-argocd-aca1c0d36323?source=rss-d75a731a8880------2</link>
            <guid isPermaLink="false">https://medium.com/p/aca1c0d36323</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[grafana]]></category>
            <category><![CDATA[helm]]></category>
            <category><![CDATA[argo-cd]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Samuel Bagattin]]></dc:creator>
            <pubDate>Mon, 31 Oct 2022 14:35:11 GMT</pubDate>
            <atom:updated>2022-10-31T14:35:11.510Z</atom:updated>
            <content:encoded><![CDATA[<p>How to encrypt only specific yaml fields in values.yaml, and how to configure ArgoCD to decrypt theses secrets before installing a chart.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FE0i2rYRYkDfNUUohQiDSQ.png" /></figure><p>When using Helm chart that you don’t manage, you might need to hardcode secrets in the chart’s values.</p><p>In this blog post I will explain how to encrypt only specific yaml fields in values.yaml, and how to configure ArgoCD to decrypt theses secrets on-the-fly before installing an Helm release. I will use the <a href="https://github.com/grafana/helm-charts/tree/main/charts/grafana">Grafana Helm Chart</a> as example, but this can apply to any Helm chart.</p><h3>Context</h3><p>When deploying an Helm chart, you might want to insert secret data such as API tokens, username/password or any sensitive data. There are many ways to retrieve credentials from your application without writing them to the value files, but some pre-made charts does not allow for retrieving credentials at runtime out of the box. In our case, Grafana requires plaintext datasources configuration, so secrets are hard-coded in <a href="https://github.com/grafana/helm-charts/blob/23a90c0147612f46e39889edbcb93072dd59544d/charts/grafana/values.yaml#L504">datasources.yaml</a>.</p><p>This leads to hazardous practices :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*LNnZXAvN4KSn0IIpE962_Q.png" /><figcaption>Plaintext GitHub API token in Helm values</figcaption></figure><p>The goal of the solution shown in this article is to provide a way to deploy the chart with the secrets configured without storing them in plaintext in the repository, and without losing the GitOps benefits offered by ArgoCD.</p><h3>Setup for local encryption with Mozilla SOPS</h3><p>This section describes how to encrypt and decrypt locally the Helm values you want to protect.</p><p>Prerequisites :</p><ul><li><a href="https://helm.sh/">Helm</a></li><li><a href="https://github.com/jkroepke/helm-secrets">Helm secrets plugin</a></li><li><a href="https://github.com/mozilla/sops">SOPS</a></li><li>An <a href="https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#customer-cmk">AWS KMS CMK</a> programatically accessible in your local environment</li><li>An Helm chart with values you want to encrypt</li></ul><p>First, you will need to create a <strong><em>.sops.yaml </em></strong>file to configure SOPS encryption mechanism. This file can be located in same directory your values are located in, or in any parent directory, as the SOPS cli will scan recursively upwards.</p><p>You can specify which fields to encrypt, which encryption mechanism to use, and other parameters. An extensive list of parameters can be found <a href="https://github.com/mozilla/sops/blob/7ebee3dc7b8f2c5fdf02cac7afca3c72d0af4496/config/config.go#L139">in the source code</a> as no similar documentation exists as of today.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/501fffb82322aceaa426e643fff3fb11/href">https://medium.com/media/501fffb82322aceaa426e643fff3fb11/href</a></iframe><p>From the <em>sops.yaml </em>example file above, the single creation rule has 2 fields specified :</p><ul><li>The ARN of the KMS key that will be used to encrypt/decrypt the data</li><li>A regex that selects which YAML fields to encrypt — In our case “secureJsonData” — All children fields will be encrypted recursively</li></ul><p>As a best practice I would recommend writing the least amount possible of plain text in the file that will be partially encrypted, as it is not possible with SOPS to edit a non-encrypted field without decrypting/encrypting the whole file. You can write the encrypted data to secrets.yaml aside values.yaml for example.</p><p>Here is an unencrypted secrets.yaml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68414ade05a4a2c09e2249306440aa17/href">https://medium.com/media/68414ade05a4a2c09e2249306440aa17/href</a></iframe><p>If you have correctly configured your AWS credentials, you can now run Helm Secrets to encrypt your file using helm secrets decrypt secrets.yaml</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/26105f3f3dcb79a3a2685f81732f0603/href">https://medium.com/media/26105f3f3dcb79a3a2685f81732f0603/href</a></iframe><h3>Configure ArgoCD to decrypt your files on the fly</h3><p>Now that we can encrypt/decrypt values using AWS KMS, we must configure ArgoCD to use the same decryption mechanism, else it will apply values in their encrypted form.</p><p>There are a few steps to follow :</p><ul><li>Install required tools and make them available to ArgoCD</li><li>Edit the <a href="https://github.com/argoproj/argo-cd/blob/master/docs/operator-manual/argocd-cm.yaml">ArgoCD ConfigMap</a> to allow usage of Helm Secrets plugin</li><li>Edit your ArgoCD Application to select witch value file to decrypt</li></ul><p>To install the tools, you can either use an init container or <a href="https://argo-cd.readthedocs.io/en/stable/user-guide/helm/#modifying-the-argocd-container-image">create your own ArgoCD image</a>.</p><p>Add theses fields to your Helm values for deploying ArgoCD.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d1f783cd956f4af80b2cf67e57a81b70/href">https://medium.com/media/d1f783cd956f4af80b2cf67e57a81b70/href</a></iframe><p>This configuration will :</p><ul><li>Create an init container that will download Helm Secrets plugin, SOPS and kubectl in a directory</li><li>Mount this directory to a shared volume between the ArgoCD repo server and the init container</li><li>Set environment variables to configure Helm to use installed tools from the shared volume</li></ul><p>Now we can edit the ArgoCD ConfigMap (via the Helm values) to allow usage of Helm Secrets plugin by allowing the usage of the <em>secrets</em> scheme.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bfec7afaad6ea67d1d2b32ace078fedd/href">https://medium.com/media/bfec7afaad6ea67d1d2b32ace078fedd/href</a></iframe><p>Multiple schemes can specified by using a coma separator.</p><p>Last step ! We can now edit our ArgoCD application manifest to use secrets.yaml alongside values.yaml , and indicate that decryption is necessary for secrets.yaml .</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/07751d0b4e2c9a2b036b7bf72a019023/href">https://medium.com/media/07751d0b4e2c9a2b036b7bf72a019023/href</a></iframe><p>Note the values.yaml and the secrets.yaml in valueFiles : ArgoCD will use values.yaml, alongside decrypting secrets.yaml and use it in the values. secrets:// has been specified to use the Helm Secrets plugin.</p><p>Here it is ! Your ArgoCD application should now be deployed, and our Grafana is secured 🤩</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aca1c0d36323" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS IAM authentication for pods in EKS : IRSA — with examples]]></title>
            <link>https://medium.com/@samuelbagattin/aws-iam-authentication-for-pods-in-eks-irsa-with-examples-5d8fa16aafba?source=rss-d75a731a8880------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d8fa16aafba</guid>
            <category><![CDATA[ek]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Samuel Bagattin]]></dc:creator>
            <pubDate>Tue, 05 Apr 2022 10:55:49 GMT</pubDate>
            <atom:updated>2022-04-05T10:55:49.803Z</atom:updated>
            <content:encoded><![CDATA[<h3>AWS IAM authentication for pods in EKS : IRSA - with examples</h3><p>I have been working with Kubernetes on AWS using EKS for some time, so I wanted to share a better way than using EC2 instance profile to authenticate pods to AWS APIs.</p><p>In this article I will show how to setup <strong>IAM Roles for Service Accounts </strong>(IRSA) using <strong>Terraform</strong> and <strong>Kubernetes manifests</strong>, and how to use this authentication mechanism with a microservice running in the cluster.</p><p>Unlike <a href="https://github.com/jtblin/kube2iam"><strong>kube2iam</strong></a><strong> </strong>or <a href="https://github.com/uswitch/kiam"><strong>kiam</strong></a>, IRSA is the official AWS way to authenticate pods to AWS API.</p><p>The full source code used to create an test all the components — the EKS cluster, the Kubernetes resources, the application and its associated Dockerfile — are publicly available in this GitHub repository.</p><p><a href="https://github.com/SamuelBagattin/eks-irsa-example">GitHub - SamuelBagattin/eks-irsa-example</a></p><h3>Architecture</h3><figure><img alt="Diagram showing how a pod is authenticating to STS using IRSA" src="https://cdn-images-1.medium.com/max/1024/1*QGunaPLP0fLmr7KYs9fN7A.png" /><figcaption>Architecture — Pod authenticating the AWS API using IRSA</figcaption></figure><p>The schema below shows the necessary setup to get security credentials to access the AWS API, using an IAM Role dedicated to its service account.</p><p>There are several components to take into account :</p><ul><li>An up and running <strong>EKS cluster</strong></li><li>An I<strong>AM Identity Provider</strong> configured to authenticate resources from the EKS cluster throught the OpenID Connect protocol (OIDC), to the AWS Account</li><li>A running pod and its associated <strong>service account</strong></li><li>An <strong>IAM role </strong>with a trust policy allowing the previous service account to perform <em>AssumeRoleWithWebIdentity</em></li><li>The process during which the pod obtains temporary STS security credentials, to authenticate to AWS API through the role’s identity</li></ul><h3>AWS IAM Setup</h3><p>This section assumes that you already have an EKS Cluster up and running.</p><p>The full Terraform source code (including the EKS cluster and node group) is available in here :</p><p><a href="https://github.com/SamuelBagattin/eks-irsa-example/tree/master/infrastructure">eks-irsa-example/infrastructure at master · SamuelBagattin/eks-irsa-example</a></p><p>First, we need to create an IAM OIDC provider in the AWS account referencing the cluster’s OIDC issuer url.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7a696cf5930ddc5e34565963b4bd83ec/href">https://medium.com/media/7a696cf5930ddc5e34565963b4bd83ec/href</a></iframe><p>Then, to authenticate our app to the AWS API, we need to create an IAM role</p><p><strong>This role will be assumable only by pods that will mount a specific Kubernetes service-account.</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f9eb13e972ce50bf529f014884584ae/href">https://medium.com/media/5f9eb13e972ce50bf529f014884584ae/href</a></iframe><p>As you can see below, the trust policy of the role has the following specifications :</p><ul><li>Allows assuming the role only through <em>AssumeRoleWithWebIdentity </em>API call</li><li>Only if the requester has the identity of the serviceaccount <em>my-serviceaccount </em>located in the <em>default</em> namespace</li><li>Only if the request has been made through the previously create OIDC provider</li><li>Finally, we create the IAM role and its associated permissions.</li></ul><p>This sample code has been inspired from the <a href="https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_cluster#enabling-iam-roles-for-service-accounts">Terraform documentation</a></p><h3>Kubernetes resources setup</h3><p>We will now create the Kubernetes service-account and associate it to the IAM role.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c98ce9d94cd6f7b11250008b6349d143/href">https://medium.com/media/c98ce9d94cd6f7b11250008b6349d143/href</a></iframe><p>The manifest below creates the <strong>service-account</strong> <em>my-serviceaccount </em>in the namespace <em>default</em></p><p>Note the <em>eks.amazonaws.com/role-arn </em>annotation : this is the one attribute that will <strong>help the app know which IAM role to assume</strong> (full documentation can be found in the <a href="https://docs.aws.amazon.com/eks/latest/userguide/specify-service-account-role.html">AWS website</a>)</p><p>Now we can create a pod (or any Kubernetes resource that manages pods).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7b1e9af8224d96ac3f646c30bc0f7737/href">https://medium.com/media/7b1e9af8224d96ac3f646c30bc0f7737/href</a></iframe><p>This pod manifest creates a pod mounting the service-account previously created, and starts our app.</p><p>The container image used has been built from the app we will create at the end of this article</p><h3>Kubernetes <em>p</em>od-<em>identity </em>mutating webhook configuration</h3><p>To help with authenticating pod to the AWS API, a brand new EKS cluster will come with <strong>a <em>mutating webhook configuration </em>named<em> pod-identity-webhook.</em></strong></p><p><a href="https://github.com/aws/amazon-eks-pod-identity-webhook/">GitHub - aws/amazon-eks-pod-identity-webhook: Amazon EKS Pod Identity Webhook</a></p><p>Here is a sample manifest of this resource (no need to apply it):</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd1e358fe1475dcd273242697fbb869c/href">https://medium.com/media/bd1e358fe1475dcd273242697fbb869c/href</a></iframe><p>When a pod is created in any namespace, for each container located in the namespace, the webhook creates the following environment variables in the manifest :</p><ul><li>AWS_STS_REGIONAL_ENDPOINTS set to regional by default, tells the SDK to use the current region endpoint to issue STS API calls</li><li>AWS_DEFAULT_REGION and AWS_REGION set to the region in which the cluster is running</li><li><strong>AWS_ROLE_ARN</strong> set to <strong>the ARN of the IAM role you specified</strong> in the <em>eks.amazonaws.com/role-arn</em> service-account annotation</li><li><strong>AWS_WEB_IDENTITY_TOKEN_FILE</strong> contains <strong>the path where is stored the Kubernetes service account token</strong>. This token will be used to get temporary STS credentials (usually set to /var/run/secrets/eks.amazonaws.com/serviceaccount/token)</li></ul><h3>Authenticating a microservice</h3><p>Now that all infrastructure and Kubernetes resources are setup, we can develop and deploy an app running in the cluster, that will use the previously described authentication mechanism</p><p>I will use a simple Golang app to perform the authentication and issue API calls using the AWS SDK, but the steps should be fairly similar in any other language.</p><p>As usual the full source code can be found here :</p><p><a href="https://github.com/SamuelBagattin/eks-irsa-example/tree/master/app">eks-irsa-example/app at master · SamuelBagattin/eks-irsa-example</a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8bc24c7959ec83f3769efe82edfd137/href">https://medium.com/media/f8bc24c7959ec83f3769efe82edfd137/href</a></iframe><p>We assume that you already have a Golang app with the AWS SDK installed and an empty <em>main </em>function present.</p><p>The previous code sample :</p><ul><li>Creates a new session using the default credentials chain</li><li>Creates an STS client to receive the temporary credentials</li><li>Gets the service account token associated to the pod</li><li>Gets the ARN of the role that will be assumed</li></ul><p>Now we can get temporary credentials and issue API calls using the IAM role.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/265bfc5c92a843b387a07856e303bc28/href">https://medium.com/media/265bfc5c92a843b387a07856e303bc28/href</a></iframe><p>This code performs the following operations :</p><ul><li>Requests temporary STS credentials using <em>AssumeRoleWithWebIdentity</em> by specifying the previously obtained role ARN and SA token, as well as the session duration and the session name.</li><li>Creates a new session using the temporary credentials</li><li>Creates a new STS client using the new identity and prints authentication information about the current session</li><li>Creates an S3 client using the same identity to test the permissions we gave previously to the role</li></ul><p>Once built into a container image and deployed using the previous pod manifest, the application will output similar logs :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01eb88a1bfd3ef8616ff867a871c960a/href">https://medium.com/media/01eb88a1bfd3ef8616ff867a871c960a/href</a></iframe><p>Here we go ! Your application now has its own role and its own set of permissions thanks to IRSA 🚀</p><p>For further investigation on the full authentication process with OIDC, check out this great blog post from AWS.</p><p><a href="https://aws.amazon.com/blogs/containers/diving-into-iam-roles-for-service-accounts/">Diving into IAM Roles for Service Accounts | Amazon Web Services</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d8fa16aafba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I scored 91/100 at the Certified Kubernetes Administrator Exam]]></title>
            <link>https://medium.com/@samuelbagattin/how-i-scored-91-100-at-the-certified-kubernetes-administrator-exam-29b281efbec1?source=rss-d75a731a8880------2</link>
            <guid isPermaLink="false">https://medium.com/p/29b281efbec1</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[certification-exam]]></category>
            <category><![CDATA[cka]]></category>
            <category><![CDATA[cncf]]></category>
            <dc:creator><![CDATA[Samuel Bagattin]]></dc:creator>
            <pubDate>Mon, 13 Dec 2021 12:10:58 GMT</pubDate>
            <atom:updated>2021-12-20T12:18:52.498Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1JR0VJdNouQlv9Qjb552mQ.png" /></figure><p>Here is the path I took to successfully pass the Certified Kubernetes Administrator exam in two months.<br>Edit : I also got 95 out of 100 for the <strong>Certified Kubernetes Application Developer Exam. </strong>Hence, this article is applicable to both of the exams, as theses 2 certifications requirements are quite similar.</p><h3>Find a complete Udemy course</h3><p>I began my journey by learning with Mumshad Mannambeth’s course for the CKA certification : <a href="https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/">https://www.udemy.com/course/certified-kubernetes-administrator-with-practice-tests/</a></p><p>It helps getting experience without prerequisites about Kubernetes and container orchestration. It also provides hands-on labs on a real command line environment with a running dedicated Kubernetes cluster. At the end of the course, 3 sets of practice tests are provided with 7–8 questions each. The answers are assessed in real time and your score is given at the end of the test.</p><p>While this Udemy course is great to have the minimum requirements, in my opinion it does not train you to be able to correctly answer all advanced cases.</p><h3>Buy the exam and go further with killer.sh</h3><p>When buying the exam, you will have 2 attempts to killer.sh, that is presented as an exam simulator.</p><p>To access to your 2 free attempts, go to<a href="https://trainingportal.linuxfoundation.org/learn/dashboard"> linux foundation learning portal</a>, then to the exam’s dashboard. Here you will be able to book your exam or try killer.sh</p><p>At the moment (December 2021) killer.sh always provides the same set of question for a given exam (CKA, CKAD or CKS). This means that everyone who take the CKA practice test will have the same questions.</p><p>From my point of view, this practice test is more of an online tutorial that provides the most edge cases that you could get at the real exam than a practice exam. It is nothing like an AWS practice exam. It is stated that there is more questions than the real exam (25 vs ~17), and it is filled with tougher exercises.</p><p>I think that most people will fail the first killer.sh attempt if they only had the Udemy course as learning material.</p><p>killer.sh is one of the best material to getting prepared to pass the exam. After the first attempt, they provide a webpage explaining detailed solutions of all questions + 5 extra questions. More importantly, it sometime shows multiple ways to getting to the same result, and how to investigate/troubleshoot issues.</p><p>It also provides a set of external training resources, as well as tips and tricks such as aliases and vim configuration. <strong>You only have access to the killer.sh environment for 36 hours, don’t forget to save this webpage for later use !</strong></p><p>For me this has really stepped up my ability to quickly create necessary resources/configuration.</p><h3>Speak and breath kubectl</h3><p>My next advise is to practice a lot, especially using dry-run kubectl commands and finding common information in the kubernetes.io documentation.</p><p>I learned to setup a 2 nodes cluster from scratch using kubeadm in my own environment : I used to setup my master node on EC2 a t4g.medium using <a href="https://gist.github.com/SamuelBagattin/030a0fea7d1314f905ec3f614f64ec05"><strong>this script</strong></a><strong>.</strong></p><p>Using your environment, practice with the learning resources given by the killer.sh advises, and get used to write your .bashrc and .vimrc setup.</p><h3>Don’t bother about Kubernetes The Hard Way</h3><p>While <a href="https://github.com/kelseyhightower/kubernetes-the-hard-way">Kubernetes The Hard Way</a> is great, especially to learn PKI setup from scratch, it is, in my opinion, useless for the exam and your time could be invested in more relevant training and resources.</p><h3>Use your last killer.sh attempt</h3><p>After you’ve mastered kubectl and kubeadm, you can use your second killer.sh exam ! Even if you already know the questions, completing all 25 questions in the 2 hours will show your readiness for the real exam.</p><h3>Get prepared for the real exam</h3><p>First, carefully read official documentation about the exam and the proctoring :</p><ul><li><a href="https://docs.linuxfoundation.org/tc-docs/certification/faq-cka-ckad-cks">https://docs.linuxfoundation.org/tc-docs/certification/faq-cka-ckad-cks</a></li><li><a href="https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad">https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad</a></li></ul><p>As you can see, documentation is allowed, even using bookmarks. Here are the ones I used :</p><ul><li><a href="https://kubernetes.io/docs/concepts/">https://kubernetes.io/docs/concepts/</a></li><li><a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/">https://kubernetes.io/docs/reference/kubectl/cheatsheet/</a></li><li><a href="https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/#securing-communication">https://kubernetes.io/docs/tasks/administer-cluster/configure-upgrade-etcd/#securing-communication</a></li><li><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume">https://kubernetes.io/docs/tasks/configure-pod-container/configure-persistent-volume-storage/#create-a-persistentvolume</a></li><li><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity">https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#node-affinity</a></li><li><a href="https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/">https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/kubeadm-upgrade/</a></li><li><a href="https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#join-nodes">https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#join-nodes</a></li><li><a href="https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#an-example-of-a-pod-that-uses-pod-affinity">https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#an-example-of-a-pod-that-uses-pod-affinity</a></li><li><a href="https://kubernetes.io/docs/concepts/services-networking/network-policies/#networkpolicy-resource">https://kubernetes.io/docs/concepts/services-networking/network-policies/#networkpolicy-resource</a></li></ul><p>All bookmarks above are about resources/configuration that cannot be created using a dry-run command, or shows long commands that can be easily copied/pasted.</p><p>The exam is web-browser based and 2 monitors (I used my laptop and its webcam + an external monitor), and 2 tabs are allowed in total.<br>I don’t know if the tabs can be separated between two browser windows.</p><h3>The end word</h3><p>If you prepared using the necessary work, you will pass the exam easily.</p><p>The real exam has less questions and the mean difficulty is way below killer.sh. If you have learned to go fast but wisely and efficiently, you will have plenty of time when for questions that need more researches. I got to the end of the exam in 1,5 hours, and I used the remaining time to troubleshoot a question that I couldn’t answer.</p><p>I hope to have helped anyone my experience passing the exam.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29b281efbec1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>