<?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 Gayatri S Ajith on Medium]]></title>
        <description><![CDATA[Stories by Gayatri S Ajith on Medium]]></description>
        <link>https://medium.com/@gayatrisajith?source=rss-154641947ae6------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*cHOVIGYv3AtbFoq0.jpg</url>
            <title>Stories by Gayatri S Ajith on Medium</title>
            <link>https://medium.com/@gayatrisajith?source=rss-154641947ae6------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 05:23:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gayatrisajith/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[Making Sense of EKS: Beginner’s Guide to IRSA]]></title>
            <link>https://gayatrisajith.medium.com/making-sense-of-eks-beginners-guide-to-irsa-9389e5166ad8?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/9389e5166ad8</guid>
            <category><![CDATA[aws-eks]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Sun, 26 Jul 2026 18:31:01 GMT</pubDate>
            <atom:updated>2026-07-26T18:31:01.625Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VeTFvm3cMxu13gmvTb-2nA.png" /><figcaption>IRSA in EKS: giving each pod its own AWS identity card.</figcaption></figure><p>IRSA, or <strong>IAM Roles for Service Accounts</strong>, is one of those things that sounds more complicated than it actually is. Let me explain it the way I would explain it to my grandmother, because honestly, that is how I learn too.</p><p>Imagine a school where different students need access to different rooms.<br>One student may be allowed into the library, another into the science lab, and another into the computer room. Instead of giving every student a master key, the school gives each student a special ID card. That ID card only opens the rooms they are allowed to enter.</p><p>In Kubernetes, pods are like those students. AWS services like S3, DynamoDB, or Secrets Manager are like the rooms. IRSA gives each pod the right “ID card” so it can access only the AWS services it is allowed to use.</p><p>In simple words:</p><blockquote>IRSA lets a Kubernetes pod access AWS services using a specific IAM role, without storing AWS keys inside the pod.</blockquote><p>In Amazon EKS, IRSA is a built-in feature. AWS already wires up most of the plumbing for you.</p><h3>Why do we need IRSA?</h3><p>Before IRSA, there were a couple of common ways to give pods access to AWS services.</p><p>Method 1: Pass AWS credentials into the pod using environment variables, config files, or Kubernetes Secrets. That works, but it is risky.</p><p>Those credentials are often long-term credentials. If they leak, someone can use them outside the cluster too. They also need to be rotated, managed, and protected carefully.</p><p>Method 2: Give permissions to the IAM role attached to the worker node. That means the EC2 instance running the pod has AWS permissions.</p><p>The problem is that one worker node can run many pods. <br>One pod may need access to S3. Another pod may need access to DynamoDB. Another pod may not need AWS access at all. <br>If we give permissions at the node level, it becomes harder to control which pod should access what.</p><p>Going back to our school example, passing AWS credentials into the pod is like giving a student a key and hoping they keep it safe.<br>Giving permissions at the worker node level is like giving the master key to the classroom itself. Any student sitting in that classroom may be able to use it.</p><p>IRSA gives us a cleaner way to handle this.</p><p>Instead of saying: <br><em>“This pod has AWS keys stored inside it.”<br></em>or:<br><em>“This worker node can access S3.”</em></p><p>we can say:<br><em>“Only pods using this specific Kubernetes service account can assume this specific IAM role.”</em></p><p>That gives us better security and better separation of permissions.<br>It also means we do not have to store long-term AWS access keys inside the pod.</p><h3>The Moving Parts</h3><p>Before getting into the setup, let us understand the moving parts.<br>Think of this section as meeting the characters in the story. After this, we will see how they all work together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7aSp9WmOs2u8euRAC1qBIQ.png" /><figcaption>Moving parts in IRSA</figcaption></figure><h4>1. The Pod</h4><p>This is your application running in Kubernetes.</p><p>For example, a pod that needs to read files from S3.</p><h4>2. The Kubernetes Service Account</h4><p>A service account is the name tag a pod wears inside Kubernetes.</p><p>So instead of saying: “Some random pod wants access to S3.”<br>Kubernetes can say: “This pod is wearing the name tag s3-reader, and s3-reader is allowed to access S3.”</p><p>That makes it easier to give the right AWS permissions to the right pod.</p><h4>3. The Service Account Annotation</h4><p><em>This is the link between the Kubernetes service account and the AWS IAM role.</em></p><p>In Kubernetes, annotations are small pieces of metadata (key-value pairs) we add to an object.</p><p>For IRSA, we add an annotation (pointing to the IAM role ARN) to the service account that says:<br><em>“This service account is allowed to use this IAM role.”</em></p><p><strong><em>This is important because not every pod in the cluster should get AWS permissions. <br></em></strong>Only pods using a service account with the IAM role annotation go through the IRSA flow. <br>If a pod uses a normal service account without this annotation, EKS will not inject the IRSA-specific token volume and environment variables for that pod.</p><h4>4. The IAM Role</h4><p>This is the AWS-side permission.</p><p>For example, an IAM role that says: “Whoever assumes this role can read from this specific S3 bucket.”</p><h4>5. The OIDC Provider</h4><p>This is the trust bridge between Kubernetes and AWS.</p><p>Kubernetes says: <em>“I issued this token for this service account.”<br></em>AWS asks: <em>“Can I trust the system that issued this token?”</em></p><p>The OIDC provider is what allows AWS to verify that the token really came from your Kubernetes cluster.</p><p>If you are new to OIDC, <a href="https://gayatrisajith.medium.com/beginner-fundamentals-what-is-oidc-5103c240005a">this beginner-friendly breakdown</a> covers how it works.</p><h4>6. Mutation of Pods</h4><p>In EKS, AWS handles the mutation of pods automatically.</p><p>When a pod uses a service account that is annotated with an IAM role, EKS slightly changes the pod definition before the pod is created. It adds the projected token volume and the environment variables the AWS SDK needs to assume the IAM role.</p><p><em>Whoa! “Mutation of pods”? That is a big phrase Grandma will not appreciate.</em></p><p>Mutation of Pods simply means Kubernetes changes the pod definition slightly before the pod is actually created.</p><p>In this case, it adds the things the pod needs to later ask AWS for temporary credentials.</p><h4>7. The Projected Token</h4><p>When the pod starts, Kubernetes gives it a service account token.</p><p>This token is not something we manually create or store. Kubernetes creates it for the pod and <em>mounts it inside the pod as a file</em>.</p><p>This is called a <strong><em>projected token</em></strong>.</p><p>The pod then uses this token to tell AWS:</p><p><em>“I am this Kubernetes service account. Can I assume the IAM role that is mapped to me?”</em></p><h4>8. AWS STS</h4><p>STS stands for Security Token Service.<br>This is the AWS service that issues temporary credentials.</p><p><strong><em>AWS does not blindly trust a pod. </em></strong><br>When the application inside the pod tries to access an AWS service, the AWS SDK uses the projected token and the IAM role ARN to ask STS for temporary credentials.</p><ul><li>STS checks the token using the OIDC provider and verifies the trust relationship on the IAM role.</li><li>If everything matches, STS returns temporary credentials for that IAM role.</li></ul><p><em>That is the important part.<br></em>The pod does not get permanent AWS keys. It gets temporary credentials only for the IAM role it is allowed to use. It then uses those temporary credentials to talk to AWS. When the credentials expire, the SDK refreshes them automatically.</p><h3>How It All Works Together</h3><p>Now that we know the moving parts, let us see how they work together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*auMy_a_z43BScfSOO7mkMg.png" /><figcaption>IRSA flow: from Kubernetes Service Account to temporary AWS credentials.</figcaption></figure><pre>Pod starts<br>↓<br>Pod uses a Kubernetes Service Account<br>↓<br>That Kubernetes Service Account has IAM role annotation<br>↓<br>EKS mutates the pod because it is using the annotated Kubernetes Service Account<br>↓<br>EKS injects:<br>- projected token volume<br>- AWS_ROLE_ARN<br>- AWS_WEB_IDENTITY_TOKEN_FILE<br>↓<br>Application calls AWS<br>↓<br>AWS SDK uses the token file and role ARN to call STS<br>↓<br>STS validates the projected token using the OIDC provider<br>↓<br>STS verifies the IAM role trust relationship<br>↓<br>STS returns temporary credentials<br>↓<br>SDK uses those credentials to call AWS</pre><h3>High-Level Setup</h3><p>Before the detailed walkthrough, here is the shape of what we will do:</p><ol><li>Create an IAM policy with the AWS permissions the pod needs.</li><li>Create an IAM role for the pod to assume.</li><li>Associate the EKS cluster with an IAM OIDC provider.</li><li>Add a trust relationship to the IAM role.</li><li>Create a Kubernetes service account.</li><li>Annotate the service account with the IAM role ARN.</li><li>Run the pod using that service account.</li><li>Test that the pod can access the AWS service.</li></ol><h3>Example: Pod Accessing S3</h3><p>Let us use a simple use case: a pod needs to read files from an S3 bucket.</p><p>If everything works, the pod should be able to access S3 without any AWS access keys stored inside it.</p><h4>Step 1: Set the Variables</h4><pre>CLUSTER_NAME=peculiar-metal-goose # The EKS Cluster should already exist<br>AWS_REGION=us-east-1<br>NAMESPACE=default<br>SERVICE_ACCOUNT_NAME=s3-reader<br>ROLE_NAME=irsa-s3-reader-role<br>POLICY_NAME=irsa-s3-read-policy<br>BUCKET_NAME=irsa-bucket-forme-gsa # Make sure to use a unique bucket name of your own.<br><br>ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)<br>PRINCIPAL_ARN=$(aws sts get-caller-identity --query Arn --output text)<br>echo ${ACCOUNT_ID}<br>echo ${PRINCIPAL_ARN}</pre><p>I am using variables here so that the same values can be reused throughout the setup.</p><p><em>Note: I am using </em><em>${VARIABLE} format instead of </em><em>$VARIABLE in some places. This avoids shell expansion issues, especially in </em><em>zsh, when a variable is followed by characters like </em><em>:.</em></p><h4>Step 2: Ensure kubectl Is Pointing to the Right Cluster</h4><pre>aws eks update-kubeconfig \<br>  --name ${CLUSTER_NAME} \<br>  --region ${AWS_REGION}</pre><p>Check the current context:</p><pre>kubectl config current-context</pre><p>You should see your EKS cluster ARN.</p><h4>Step 3: Create the S3 Bucket and Upload a Test File</h4><pre>aws s3api create-bucket \<br>  --bucket ${BUCKET_NAME} \<br>  --region ${AWS_REGION}</pre><p><em>Note: For </em><em>us-east-1, we do not need to pass </em><em>--create-bucket-configuration. If you are using a different region, add </em><em>--create-bucket-configuration LocationConstraint=${AWS_REGION} to the command.</em></p><p>Now create a test file and upload it:</p><pre>echo &quot;Hello from S3. IRSA is working.&quot; &gt; test-for-s3.txt<br>aws s3 cp test-for-s3.txt s3://${BUCKET_NAME}/test.txt<br>aws s3 ls s3://${BUCKET_NAME}</pre><p>You should see something like:</p><pre>2026-06-23 23:20:00         34 test.txt</pre><h4>Step 4: Ensure the Current AWS CLI user has access to the cluster</h4><p>This is optional. If kubectl already works for you, you may not need this step. But if you get an error like this when you execute kubectl commands: &quot;the server has asked for the client to provide credentials&quot;, then your AWS CLI identity may not have access to the EKS cluster yet.</p><p>Create an access entry:</p><pre>aws eks create-access-entry \<br>  --cluster-name ${CLUSTER_NAME} \<br>  --region ${AWS_REGION} \<br>  --principal-arn ${PRINCIPAL_ARN}</pre><p>Associate the cluster admin access policy:</p><pre>aws eks associate-access-policy \<br>  --cluster-name ${CLUSTER_NAME} \<br>  --region ${AWS_REGION} \<br>  --principal-arn ${PRINCIPAL_ARN} \<br>  --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy \<br>  --access-scope type=cluster</pre><p><em>Important: This grants full admin access to the cluster. Only do this in a personal or test cluster.</em></p><p>Now test access:</p><pre>kubectl get nodes</pre><h4>Step 5: Get the EKS OIDC Issuer</h4><p>IRSA needs the EKS cluster’s OIDC issuer.</p><pre>OIDC_ISSUER=$(aws eks describe-cluster \<br>  --name ${CLUSTER_NAME} \<br>  --region ${AWS_REGION} \<br>  --query &quot;cluster.identity.oidc.issuer&quot; \<br>  --output text)<br>echo ${OIDC_ISSUER}</pre><p>The output will look something like this:</p><pre>https://oidc.eks.us-east-1.amazonaws.com/id/EXAMPLE</pre><h4>Step 6: Associate the IAM OIDC Provider</h4><p><em>Note: If you do not already have </em><em>eksctl, install it first. You can find the </em><a href="https://docs.aws.amazon.com/eks/latest/eksctl/installation.html"><em>installation steps here</em></a><em>.</em></p><p>Associate the IAM OIDC provider for the cluster:</p><pre>eksctl utils associate-iam-oidc-provider \<br>  --cluster ${CLUSTER_NAME} \<br>  --region ${AWS_REGION} \<br>  --approve</pre><p>Now remove https:// from the issuer URL because the IAM trust policy needs the OIDC provider value without it:</p><pre>OIDC_PROVIDER=$(echo ${OIDC_ISSUER} | sed -e &quot;s/^https:\/\///&quot;)<br>echo ${OIDC_PROVIDER}</pre><p>Example output:</p><pre>oidc.eks.us-east-1.amazonaws.com/id/EXAMPLE</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vKzzejRSgIkYeKVOAOJ2rA.png" /><figcaption>OIDC Provider associated with EKS</figcaption></figure><h4>Step 7: Create the IAM Trust Policy</h4><p>The trust policy controls who is allowed to assume the IAM role.</p><p>In this case, we are saying:</p><p><em>Only the Kubernetes service account named </em><em>s3-reader in the </em><em>default namespace can assume this IAM role.</em></p><pre>cat &gt; trust-policy.json &lt;&lt;EOF<br>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Principal&quot;: {<br>        &quot;Federated&quot;: &quot;arn:aws:iam::${ACCOUNT_ID}:oidc-provider/${OIDC_PROVIDER}&quot;<br>      },<br>      &quot;Action&quot;: &quot;sts:AssumeRoleWithWebIdentity&quot;,<br>      &quot;Condition&quot;: {<br>        &quot;StringEquals&quot;: {<br>          &quot;${OIDC_PROVIDER}:aud&quot;: &quot;sts.amazonaws.com&quot;,<br>          &quot;${OIDC_PROVIDER}:sub&quot;: &quot;system:serviceaccount:${NAMESPACE}:${SERVICE_ACCOUNT_NAME}&quot;<br>        }<br>      }<br>    }<br>  ]<br>}<br>EOF</pre><p>This is the part &quot;${OIDC_PROVIDER}:sub”: “system:serviceaccount:${NAMESPACE}:${SERVICE_ACCOUNT_NAME}&quot; that restricts access to a service account in a particular namespace.</p><p>Optional but useful: validate the JSON.</p><pre>jq . trust-policy.json</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aq-GmvqL2rnw-RK2nchFWA.png" /><figcaption>2 parts of the IAM Role</figcaption></figure><h4>Step 8: Create the S3 Read Policy</h4><p>The trust policy only allows the pod to assume the IAM role.<br>The role also needs an IAM permissions policy that says what the pod can do after assuming the role.<br>For this example, the pod only needs to list the bucket and read objects from it.</p><pre>cat &gt; s3-read-policy.json &lt;&lt;EOF<br>{<br>  &quot;Version&quot;: &quot;2012-10-17&quot;,<br>  &quot;Statement&quot;: [<br>    {<br>      &quot;Sid&quot;: &quot;AllowListBucket&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;s3:ListBucket&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:s3:::${BUCKET_NAME}&quot;<br>    },<br>    {<br>      &quot;Sid&quot;: &quot;AllowReadObjects&quot;,<br>      &quot;Effect&quot;: &quot;Allow&quot;,<br>      &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>      &quot;Resource&quot;: &quot;arn:aws:s3:::${BUCKET_NAME}/*&quot;<br>    }<br>  ]<br>}<br>EOF</pre><p>Validate the JSON:</p><pre>jq . s3-read-policy.json</pre><h4>Step 9: Create the IAM Role and Attach the Policy</h4><p>Create the IAM role:</p><pre>aws iam create-role \<br>  --role-name ${ROLE_NAME} \<br>  --assume-role-policy-document file://trust-policy.json</pre><p>Create the IAM policy:</p><pre>aws iam create-policy \<br>  --policy-name ${POLICY_NAME} \<br>  --policy-document file://s3-read-policy.json</pre><p>Create the role ARN and policy ARN variables:</p><pre>POLICY_ARN=&quot;arn:aws:iam::${ACCOUNT_ID}:policy/${POLICY_NAME}&quot;<br>ROLE_ARN=&quot;arn:aws:iam::${ACCOUNT_ID}:role/${ROLE_NAME}&quot;</pre><p>Attach the S3 policy to the IAM role:</p><pre>aws iam attach-role-policy \<br>  --role-name ${ROLE_NAME} \<br>  --policy-arn ${POLICY_ARN}</pre><p>At this point, we have two things:</p><ul><li>The trust policy says who can assume the role.</li><li>The permissions policy says what the role can do.</li></ul><h4>Step 10: Create the Kubernetes Service Account</h4><p>Now create the Kubernetes service account.</p><pre>kubectl create serviceaccount ${SERVICE_ACCOUNT_NAME} \<br>  --namespace ${NAMESPACE}</pre><h4>Step 11: Annotate the Service Account</h4><p>This is where we connect the Kubernetes service account to the IAM role.</p><pre>kubectl annotate serviceaccount ${SERVICE_ACCOUNT_NAME} \<br>  --namespace ${NAMESPACE} \<br>  eks.amazonaws.com/role-arn=${ROLE_ARN}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uA7PJc0480hHV_ilCzTqKQ.png" /><figcaption>Annotate service account with the IAM Role</figcaption></figure><p>Verify the annotation:</p><pre>kubectl describe serviceaccount ${SERVICE_ACCOUNT_NAME} \<br>  --namespace ${NAMESPACE}</pre><p>You should see something like:</p><pre>Annotations: eks.amazonaws.com/role-arn: arn:aws:iam::&lt;ACCOUNT_ID&gt;:role/irsa-s3-reader-role</pre><p>This annotation tells EKS: <em>&quot;When a pod uses this service account, prepare that pod for IRSA.&quot;</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p5LHGw2KYZEPHnCgooZT8w.png" /><figcaption>Annotated Kubernetes Service Account</figcaption></figure><h4>Step 12: Create the Test Pod</h4><p>Now create a pod that uses the annotated service account.</p><pre>cat &gt; s3-test-pod.yaml &lt;&lt;EOF<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: s3-test-pod<br>  namespace: ${NAMESPACE}<br>spec:<br>  serviceAccountName: ${SERVICE_ACCOUNT_NAME}<br>  containers:<br>    - name: aws-cli<br>      image: amazon/aws-cli:latest<br>      command:<br>        - sleep<br>        - &quot;3600&quot;<br>  restartPolicy: Never<br>EOF</pre><p>Apply the manifest:</p><pre>kubectl apply -f s3-test-pod.yaml</pre><p>Check the pod status:</p><pre>kubectl get pod s3-test-pod \<br>  --namespace ${NAMESPACE}</pre><p>Describe the pod for details:</p><pre>kubectl describe pod s3-test-pod \<br>  --namespace ${NAMESPACE}</pre><p>Look for <em>Service Account: s3-reader<br></em>This confirms that the pod is using the service account we annotated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sFu_rC-xwIBeDQXra8XzTA.png" /><figcaption>Create pod with the annotated Kubernetes service account</figcaption></figure><h4>Step 13: Check if Pod Mutation Worked</h4><p>Now let us check whether EKS injected the IRSA-related environment variables.</p><pre>kubectl exec -it s3-test-pod \<br>  --namespace ${NAMESPACE} \<br>  -- env | grep AWS</pre><p>You should see something like:</p><pre>AWS_ROLE_ARN=arn:aws:iam::&lt;ACCOUNT_ID&gt;:role/irsa-s3-reader-role<br>AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token<br>AWS_REGION=us-east-1<br>AWS_DEFAULT_REGION=us-east-1</pre><p>The important ones are AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE.<br>This indicates the pod knows which IAM role to assume and where the projected token file is mounted.</p><p>Now check that the projected token file exists:</p><pre>kubectl exec -it s3-test-pod \<br>  --namespace ${NAMESPACE} \<br>  -- ls -l /var/run/secrets/eks.amazonaws.com/serviceaccount/</pre><p>You should see a token file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-BQvlcBD79r4H1A3SnirfQ.png" /><figcaption>Confirm Pod Mutation worked</figcaption></figure><h4>Step 14: Test the IAM Role from Inside the Pod</h4><p>Now run:</p><pre>kubectl exec -it s3-test-pod \<br>  --namespace ${NAMESPACE} \<br>  -- aws sts get-caller-identity</pre><p>If IRSA is working, the output should show an assumed role ARN:</p><pre>arn:aws:sts::&lt;ACCOUNT_ID&gt;:assumed-role/irsa-s3-reader-role/...</pre><p>This is the moment where we know the pod is not using hard-coded AWS keys. It is assuming the IAM role through IRSA.</p><h4>Step 15: Test S3 Access from Inside the Pod</h4><p>Now list the S3 bucket from inside the pod:</p><pre>kubectl exec -it s3-test-pod \<br>  --namespace ${NAMESPACE} \<br>  -- aws s3 ls s3://${BUCKET_NAME}</pre><p>You should see the test file:</p><pre>2026-06-23 23:20:00         34 test.txt</pre><p>You can also read the file:</p><pre>kubectl exec -it s3-test-pod \<br>  --namespace ${NAMESPACE} \<br>  -- aws s3 cp s3://${BUCKET_NAME}/test.txt -</pre><p>Expected output:</p><pre>Hello from S3. IRSA is working.</pre><p>And that is IRSA working end to end.</p><p>The pod does not have AWS keys stored inside it. It uses the Kubernetes service account token, asks STS for temporary credentials, assumes the IAM role, and then uses that role to access S3.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jjs2KKyYj3Ca5XBPad5ezg.png" /><figcaption>Check if the pod has the right permissions to access S3</figcaption></figure><h3>Common Issues</h3><p>Even when the setup looks simple, a few things can go wrong.</p><pre>+--------------------------------------+------------------------------------------------------------+<br>| Issue                                | What to check                                              |<br>+--------------------------------------+------------------------------------------------------------+<br>| Pod is still using the node role     | Check whether the pod is using the correct service account |<br>|                                      | and whether that service account has the IAM role          |<br>|                                      | annotation.                                                |<br>+--------------------------------------+------------------------------------------------------------+<br>| IRSA environment variables are       | Check whether the service account has the IAM role         |<br>| missing                              | annotation.                                                |<br>+--------------------------------------+------------------------------------------------------------+<br>| AccessDenied error                   | Check whether the IAM policy allows the required AWS       |<br>|                                      | action and resource.                                       |<br>+--------------------------------------+------------------------------------------------------------+<br>| InvalidIdentityToken error           | Check whether the OIDC provider and IAM role trust policy  |<br>|                                      | are correct.                                               |<br>+--------------------------------------+------------------------------------------------------------+<br>| Works in one namespace but not       | Check the namespace and service account name in the IAM    |<br>| another                              | role trust policy.                                         |<br>+--------------------------------------+------------------------------------------------------------+<br>| AWS SDK is not picking up IRSA       | Check whether the AWS SDK version supports web identity    |<br>|                                      | tokens.                                                    |<br>+--------------------------------------+------------------------------------------------------------+<br>| kubectl says client must provide     | Check whether your AWS CLI identity has access to the EKS  |<br>| credentials                          | cluster. You may need an EKS access entry.                 |<br>+--------------------------------------+------------------------------------------------------------+<br>| Node is NotReady with CNI error      | Check whether the Amazon VPC CNI add-on is installed and   |<br>|                                      | active. Without it, pod networking will not initialize.    |<br>+--------------------------------------+------------------------------------------------------------+</pre><p>The most common mistake is creating the IAM role correctly, but forgetting to make the pod use the annotated service account.</p><h3>Final Summary</h3><p>That is IRSA in action.</p><p>We started with a pod that needed to read from S3. Instead of storing AWS keys inside it, we created an IAM role, linked it to a specific Kubernetes service account through the EKS OIDC provider, and annotated that service account with the role ARN. When the pod started, EKS injected the token and environment variables the AWS SDK needed. The SDK used those to call STS, assume the role, and get temporary credentials.</p><p>The important thing to remember: <strong><em>IRSA does not give AWS permissions to every pod.</em></strong> It gives permissions only to pods using the specific annotated service account.</p><p>No keys stored. No node-level access. Just enough permission for just the workload that needs it.</p><p>If your grandmother asked what IRSA does, you could tell her: it gives each pod its own ID card, so it only opens the doors it is supposed to open. Everything else is just the machinery that makes that work securely at scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9389e5166ad8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner Fundamentals: What is OIDC?]]></title>
            <link>https://gayatrisajith.medium.com/beginner-fundamentals-what-is-oidc-5103c240005a?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/5103c240005a</guid>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[oidc]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[platform-engineering]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Sun, 28 Jun 2026 11:03:59 GMT</pubDate>
            <atom:updated>2026-06-29T17:16:59.557Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORa7wEjlyJmMY3GrAiF6nQ.png" /></figure><p>When I first started looking at OIDC, I kept seeing words like <strong>issuer</strong>, <strong>JWKS</strong>, <strong>claims</strong>, <strong>audience</strong>, <strong>subject</strong>, and <strong>federated identity</strong>. All very accurate. Also very good at making your brain quietly leave the room.</p><blockquote><em>OIDC stands for OpenID Connect.</em></blockquote><p>At a very simple level, OIDC is a way for one system to prove an identity to another system using a signed token.<br>One system says: <br><em>“I know who this requester is.”<br></em>Another system says: <br><em>“I trust you as an identity provider, so I will accept that proof – but only if the token is valid and matches my rules.”</em></p><p>Still feels like a lot? Same. Let’s make it simpler.</p><p>Imagine you are a kid at school, and there is a really cool after-school club called <strong>The Treehouse.</strong></p><p>The treehouse has one strict rule:<br><em>“Only kids the treehouse trusts are allowed in.”</em></p><p>But the treehouse does not want to hand out permanent membership cards to every kid. Because if someone loses that card, anyone who finds it can get into the treehouse forever. That is basically the risk with long-lived access keys.</p><p>So instead, the school and the treehouse make a deal. The treehouse says:<br><em>“I will not give permanent keys to every student. But if the school gives a student a properly signed hall pass, I will trust that hall pass for a short time.”</em></p><p>That is the basic idea behind OIDC.</p><h3>You Have Already Seen OIDC</h3><p>Before we go further, it is worth knowing that you have almost certainly used OIDC before — you just did not know it had a name.</p><p>Have you ever clicked a button that said “Sign in with Google” or “Continue with GitHub”? That is OIDC in action.</p><p>Here is what happens in that moment:</p><ul><li>You click “Sign in with Google” on some website — let’s call it My Clever Shop.</li><li>The tool does not ask you for a password. Instead, it sends you over to Google and says: <em>“Can you tell me who this person is?”</em></li><li>Google already knows who you are because you are logged in. So Google writes you a signed token that says: <em>“This is Gayatri. Her email is </em><a href="/service/mailto:gayatri@gmail.com"><em>xxx@gmail.com</em></a><em>. I, Google, am vouching for her.”</em></li><li>Google sends that token back to My Clever Shop.</li><li>My Clever Shop checks the token — is the signature really Google’s? Has it expired? Is it meant for this tool? — and if everything checks out, it logs you in. No password shared. No account created from scratch.</li></ul><p>That is the login flow. My Clever Shop never saw your Google password. It just received a trustworthy, short-lived proof of identity from an issuer it already trusts.</p><p>This is the human-facing side of OIDC.</p><p>What we will explore through the rest of this article is the machine-facing side — where instead of a person clicking “Sign in with Google,” it is a pipeline, a service, or a workload proving its identity to a cloud provider. The mechanics are the same. The players are just different.</p><h3>The Hall Pass Story</h3><p>Let’s say you want to visit The Treehouse.<br>You go to your school and say:</p><p><em>“I need to visit the treehouse.”</em></p><p>In a real-world example, the school is the <strong>OIDC provider</strong>. It could be GitLab, GitHub Actions, Kubernetes, or any system that can issue OIDC tokens.</p><p>The school already knows who you are. You are part of that school. You show up there every day. The school does not need the treehouse to know your password.</p><p>So the school writes you a hall pass that says:</p><p><em>“This is Gayatri. She belongs to Class 4B. She is allowed to go to the treehouse. This pass was issued by the school and expires soon.”</em></p><p>Then the school signs it with a special stamp.</p><p>That hall pass is the <strong><em>JWT token</em></strong><em>.</em></p><p>A JWT has three parts: a header, a payload, and a signature.</p><ul><li>The header says which algorithm was used.</li><li>The payload contains the claims — things like who issued the token, who it is for, when it expires, and what the subject is.</li><li>The signature is the issuer’s cryptographic stamp that proves the token has not been tampered with.</li></ul><p>When the receiver checks the JWT, it can read the claims, but it should only trust them after verifying the signature.</p><h3>What Happens When You Reach The Treehouse?</h3><p>You walk up to The Treehouse and show your hall pass.</p><p>In OIDC terms, the system receiving and validating the token is often called the relying party. For this article, I will mostly call it the receiver to keep things simple.</p><p>The treehouse guard does not blindly believe the pass. It checks a few things first.</p><p>It asks:</p><ul><li>Who issued this pass?</li><li>Is this issuer someone I trust?</li><li>Is the signature real?</li><li>Has the pass expired?</li><li>Was this pass meant for me?</li><li>Does the pass match the conditions the receiver has configured?</li></ul><p>Only if all of those checks pass will the receiver allow access.</p><p>In cloud and workload identity use cases, this often means exchanging the token for short-lived temporary credentials.</p><p>That is the beauty of this model.</p><ul><li>You did not store a long-lived access key anywhere.</li><li>You did not give anyone a permanent secret.</li><li>You did not create a dedicated user just so automation could log in.</li></ul><p>Instead, the OIDC provider proved who the requester was, and the receiver used that proof to decide whether access should be granted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nMWzV57VMzk6YplDDxwjDA.png" /><figcaption>OIDC Hall Pass Analogy</figcaption></figure><h3>But How Does the Receiver Know the Hall Pass Is Real?</h3><p>This is where the <strong><em>JWKS endpoint</em></strong> comes in.</p><p>The school has a public noticeboard that shows what the teacher’s official signature looks like. Anyone can look at this noticeboard.</p><p>That may sound scary at first, but it is not.<br>Because seeing what the signature looks like is not the same as being able to create that signature. This is the difference between a public key and a private key.</p><p>The private key is used by the issuer to sign the token.<br>The public key is used by others to verify that the token was really signed by that issuer.</p><p>The OIDC provider keeps the private signing key safe.<br>The receiver reads the OIDC provider’s public keys and uses them to verify the token signature.</p><p>This is why public verification is safe.<br>Anyone can verify the hall pass. But only the real issuer can create a valid one.</p><h3>Where Does the Receiver Find the Public Keys?</h3><p>Now let’s look at the actual OIDC endpoints involved.</p><p>An OIDC provider usually exposes a standard discovery document at this path:</p><pre>https://&lt;oidc-provider-domain&gt;/.well-known/openid-configuration</pre><p>It tells anyone who wants to trust this OIDC provider:</p><ul><li>Who the issuer is</li><li>What endpoints are available</li><li>Which signing algorithms are supported</li><li>Which claims may appear in the token</li><li>Where to find the public keys</li></ul><p>Sample discovery document JSON looks like this:</p><pre>{<br>  &quot;issuer&quot;: &quot;https://&lt;oidc-provider-domain&gt;&quot;,<br>  &quot;authorization_endpoint&quot;: &quot;https://&lt;oidc-provider-domain&gt;/oauth/authorize&quot;,<br>  &quot;token_endpoint&quot;: &quot;https://&lt;oidc-provider-domain&gt;/oauth/token&quot;,<br>  &quot;userinfo_endpoint&quot;: &quot;https://&lt;oidc-provider-domain&gt;/oauth/userinfo&quot;,<br>  &quot;jwks_uri&quot;: &quot;https://&lt;oidc-provider-domain&gt;/oauth/discovery/keys&quot;,<br>  &quot;response_types_supported&quot;: [<br>    &quot;code&quot;,<br>    &quot;id_token&quot;,<br>    &quot;token id_token&quot;<br>  ],<br>  &quot;subject_types_supported&quot;: [<br>    &quot;public&quot;<br>  ],<br>  &quot;id_token_signing_alg_values_supported&quot;: [<br>    &quot;RS256&quot;<br>  ],<br>  &quot;scopes_supported&quot;: [<br>    &quot;openid&quot;,<br>    &quot;profile&quot;,<br>    &quot;email&quot;<br>  ],<br>  &quot;claims_supported&quot;: [<br>    &quot;iss&quot;,<br>    &quot;sub&quot;,<br>    &quot;aud&quot;,<br>    &quot;exp&quot;,<br>    &quot;iat&quot;,<br>    &quot;name&quot;,<br>    &quot;email&quot;<br>  ]<br>}</pre><p>The discovery document is like the school office directory. The receiver starts at the issuer URL, reads this document, finds the jwks_uri, and then goes to that endpoint to fetch the public keys. Those public keys are used to check whether the JWT token was really signed by the trusted OIDC provider.</p><p>A real discovery document may contain more fields than we need for this article. Two important fields relevant to this article are:</p><pre># This tells who issued the token.<br>&quot;issuer&quot;: &quot;https://&lt;oidc-provider-domain&gt;&quot;,<br><br># This points to the JWKS endpoint which has the public keys used to <br># verify the token signature.<br>&quot;jwks_uri&quot;: &quot;https://&lt;oidc-provider-domain&gt;/&lt;path-to-public-keys&gt;&quot;</pre><p>The path to the JWKS endpoint is not always the same for every provider.<br>For one provider, it may look like this: https://&lt;oidc-provider-domain&gt;/oauth/discovery/keysFor another provider, it may look different.</p><p>That is why the receiver does not need to manually guess the public keys URL. It starts with the issuer URL, reads the discovery document, finds the jwks_uri, and then fetches the public keys from there.</p><p>In our analogy:</p><ul><li>The issuer URL is the school address.</li><li>The discovery document is the school office directory.</li><li>The jwks_uri tells you where the signature noticeboard is.</li><li>The JWKS endpoint is the public noticeboard with the teacher’s official signature.</li><li>The receiver uses that public signature to check whether the hall pass is real.</li></ul><p>The JWKS endpoint is public on purpose. It only contains public keys.<br>Public keys can verify a signature, but they cannot create a valid signature.</p><p>The private key stays with the OIDC provider.<br>That private key is what signs the token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CXRxwWUIcGC7TiqXR_wYZA.png" /><figcaption>OIDC Analogy Mapping</figcaption></figure><h3>What Makes OIDC Different From Just Sharing a Password?</h3><p>With a password or access key, both sides depend on a shared secret. If that secret leaks, you have a problem. Someone can keep using it until you find out and rotate it.</p><p>OIDC works differently.</p><p>The system that needs access gets a short-lived token. That token proves identity. The receiver validates the token and then grants access, or in cloud scenarios, returns short-lived temporary credentials. <br>If someone steals the token after it expires, it is useless.<br>Even while it is valid, the receiver will only accept it if the issuer, audience, subject, signature, and configured policy conditions all match.</p><p>So the point is not just:</p><p><em>“Can this token be verified?”</em></p><p>The real question is:</p><p><em>“Do I trust the issuer of this token, and does this token match the exact access rules I configured?”</em></p><p>That is the important shift.</p><h3>How Does a System Know Which OIDC Provider to Trust?</h3><p>When a system is configured to trust an OIDC provider, it is essentially saying:</p><p><em>“I trust tokens issued by this specific identity provider.”</em></p><p>For example, if you configure GitLab as an OIDC provider, you are telling the receiver to trust tokens issued by GitLab.</p><p>You do not usually hardcode the JWKS endpoint directly. <br>Instead, you give the receiver the issuer URL. <br>The issuer publishes a discovery document at a standard location. The discovery document tells the receiver where to find important information, including the JWKS URI.</p><p>So the flow is roughly:</p><p>1. The receiver knows the issuer URL.<br>2. The receiver checks the issuer’s OIDC discovery document.<br>3. The discovery document points the receiver to the JWKS endpoint.<br>4. The receiver fetches the public keys from the JWKS endpoint.<br>5. The receiver uses those keys to validate the JWT signature.</p><p>In school terms:</p><ul><li>You give the receiver the school address.</li><li>The receiver goes to the school office.</li><li>The school office points the receiver to the official signature noticeboard.</li><li>The receiver uses that noticeboard to check whether the hall pass is genuine.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9XfBYFtF4iyfExbQLxna8w.png" /><figcaption>OIDC Control Flow</figcaption></figure><h3>Then What About TLS Certificate Validation or Thumbprints?</h3><p>There is one more trust check that is worth understanding.</p><p>The JWKS helps the receiver verify the token signature.<br>But the receiver also needs to know that it is talking to the real OIDC provider when it fetches the discovery document and public keys.</p><p>That part is handled through HTTPS and TLS certificate validation.</p><p>In some integrations, a certificate thumbprint may also be configured or used as an additional check.</p><p>In the analogy:</p><ul><li>The JWKS tells the receiver what the teacher’s signature should look like.</li><li>TLS certificate validation helps the receiver confirm that it is actually standing inside the real school office, not a fake building with a fake noticeboard.</li></ul><p>So, JWKS and TLS validation are related to trust, but they are not the same thing.</p><p>JWKS verifies the token.</p><p>TLS validation helps verify the endpoint used to fetch the OIDC metadata and keys.</p><h3>The Important OIDC Pieces</h3><p>Here are the main moving parts in normal language.</p><pre>+--------------------+--------------------------------------------------------------------+<br>| OIDC Term          | Simple Meaning                                                     |<br>+--------------------+--------------------------------------------------------------------+<br>| Issuer             | The system that creates and signs the token                        |<br>| JWT                | The signed hall pass                                               |<br>| Claims             | Details written inside the token                                   |<br>| Subject            | Who or what the token is about                                     |<br>| Audience           | Who the token is meant for                                         |<br>| JWKS               | Public keys used to verify the token signature                     |<br>| Discovery document | A standard document that tells receivers where OIDC endpoints are  |<br>| Trust policy /     | Rules that decide which identities can be granted access           |<br>| access rules       |                                                                    |<br>| Token exchange     | The process of exchanging a valid token for access or temporary    |<br>|                    | credentials                                                        |<br>| Relying party      | The system that trusts the issuer and validates the token          |<br>+--------------------+--------------------------------------------------------------------+</pre><p>Once these pieces click, OIDC becomes much less mysterious. It is not magic.</p><p>It is just a structured way for one system to say:</p><p><em>“I know who this is.”</em></p><p>And for another system to say:</p><p><em>“I trust you as an issuer, so I will accept that identity proof under these specific conditions.”</em></p><h3>Why This Matters</h3><p>OIDC is useful because it removes the need for long-lived secrets in many automation flows.</p><p>That is why it shows up in places like:</p><ul><li>GitLab pipelines accessing cloud resources</li><li>GitHub Actions deploying to cloud accounts</li><li>Kubernetes service accounts accessing cloud services</li><li>Service-to-service authentication without shared secrets</li><li>Workload identity patterns across cloud platforms</li></ul><p>Instead of storing static credentials, the workload proves who it is using a short-lived signed token. Then the cloud provider gives it temporary access based on trust rules.</p><p>This is safer because access is:</p><ul><li>Short-lived</li><li>Scoped</li><li>Verifiable</li><li>Based on identity</li><li>Controlled by policy</li></ul><h3>Try It Yourself</h3><p>I created a small GitHub project that shows these moving parts in action: <br>a simple OIDC issuer, a discovery document, a JWKS endpoint, a signed JWT, and a consumer that validates the token.</p><p><a href="https://github.com/gayatri-sa/learn-oidc">https://github.com/gayatri-sa/learn-oidc</a></p><h3>The Simplest Way to Remember OIDC</h3><ul><li>OIDC is like a trusted hall pass system.</li><li>The issuer writes and signs the hall pass.</li><li>The receiver checks the signature using public keys.</li><li>The receiver also checks whether it trusts that issuer.</li><li>If everything matches, the receiver gives temporary access.</li><li>No permanent password is shared.</li><li>No long-lived access key is stored.</li><li>No secret needs to be copied from one system to another.</li></ul><p>That is the whole trick.</p><p>Everything else — JWT claims, JWKS endpoints, issuer URLs, thumbprints, audiences, subjects, and trust policies or access rules — is just the machinery that makes the hall pass system work securely at scale.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5103c240005a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making Sense of EKS: Beginner’s Guide to Cluster Access with IAM]]></title>
            <link>https://gayatrisajith.medium.com/making-sense-of-eks-beginners-guide-to-cluster-access-with-iam-aabaf1d32e67?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/aabaf1d32e67</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[iam-roles]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[ek]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Thu, 01 May 2025 10:05:24 GMT</pubDate>
            <atom:updated>2025-05-01T10:05:24.057Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PuONAP8FRpUUXFyDEeCUJg.png" /><figcaption>Cluster Access with IAM</figcaption></figure><p>Moving from standalone Kubernetes clusters to managed Kubernetes can feel like a loss of control. Even something as simple as accessing the cluster can seem like jumping through hoops. <br>The first step to simplifying things? Separate ‘EKS’ and ‘cluster’. <br><em>EKS is the service that manages your Kubernetes cluster.</em> <br>Let’s dive in.</p><p>Note: The assumption is that you already have a cluster via EKS. You don’t need any managed nodes. A plain cluster with no nodes is good enough.</p><h3>Cluster IAM Role</h3><p>One of the first things you do when setting up a Kubernetes cluster using EKS is to create an IAM role — the EKS Cluster IAM Role.</p><p>The most important thing to remember about this role? <strong><em>It’s not for accessing the cluster</em></strong>. It’s for EKS — the service that’s managing your cluster — to access AWS resources.<br>Why does EKS need access to AWS resources? Because its job is to set up and manage your Kubernetes cluster!<br>Things you would normally have to do manually — like creating servers, networks, routes, and security groups — EKS handles for you. But for that, you need to give it permissions inside your AWS account.</p><p>Think of it like this: you’re giving your house help (EKS) the keys (Cluster IAM Role) to the storeroom (AWS resources) so they can manage your home (your Kubernetes cluster).<br><em>But — and this is key — if someone wants to walk into your home, these keys won’t help.</em></p><p>Moral of the story: Forget about the Cluster IAM Role for now.<br>We don’t need it for what we’re focusing on in this article — accessing the cluster!</p><p>(P.S. If you’re setting up fancy add-ons or deep integrations later, the Cluster IAM Role might pop back into the story — but for now, you can safely ignore it!)</p><h3><strong>AWS IAM Role for Access</strong></h3><p>In AWS, access is typically given through IAM roles, especially when you want to securely interact with services like EKS. <br>So let&#39;s start with creating a new IAM Role for users/developers to access our cluster. <br><em>Note: In this article, my users are Kubernetes administrators — hence, they need admin access.</em></p><h4>Create the IAM Role</h4><p>Here are the details of my IAM Role:<br>Name: <em>EKSAdminUserRole</em><br>Permissions: <em>AmazonEKSClusterPolicy, AmazonEKSServicePolicy, AmazonEKSWorkerNodePolicy (optional, if users need to manage nodes)</em><br>Trusted Policy: <em>Choose ‘AWS Account’ for now. We’ll come back to this soon.</em></p><p><em>Notes:</em></p><ol><li><em>AmazonEC2ContainerRegistryReadOnly is useful only if pulling ECR images from CLI — Kubernetes doesn’t need it unless you manually troubleshoot ECR.</em></li><li><em>AmazonEKSServicePolicy is deprecated now. Suggest using AmazonEKSVPCResourceController instead.</em></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JTzWpw_3GTosPEYBPls30A.png" /><figcaption>Create a new IAM role: Select AWS account as the trusted entity for now.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ABzc4LJmbnuA2VrILwkc8Q.png" /><figcaption>Create a new IAM role: Give admin permissions to the cluster. Ignore trusted entities for now.</figcaption></figure><h3>Connect the IAM Role to the cluster</h3><p>Currently, the role exists but isn’t connected to any cluster yet. It’s like having a key but no door assigned yet. Let’s fix that.</p><h4>EKS Cluster IAM Access Entries</h4><p>If you open your cluster in the AWS Management Console and click on the ‘Access’ tab, you’ll find a section called ‘IAM Access Entries’. This is where you decide how an IAM role or user interacts with your cluster.</p><p>Depending on how your EKS cluster was set up, you might already see the root user listed here.<br>We now need to add an entry for our EKSAdminUserRole:</p><ul><li>Click on ‘Create access entry’</li><li>Add the EKSAdminUserRole</li><li>Assign the policies AmazonEKSAdminPolicy and AmazonEKSClusterAdminPolicy</li></ul><p><em>Note: My cluster name is ‘gsa-eks’ </em>(yeah, I know, very intuitive)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G5EtaOxSiv8ebbHcI1-ICw.png" /><figcaption>IAM Access Entry: Select the EKSAdminUser IAM Role. Leave the Type as Standard.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YjznLvExNyuP3XP_S1FvPA.png" /><figcaption>IAM Access Entry: Select the policies to decide how the role interacts with the cluster.</figcaption></figure><p>And that’s it — technically.<br>Anyone assuming the EKSAdminUserRole now has admin access to the cluster.</p><p>Are we done? No way — we are Enterprise Architects! (Or at least, we could be if we wanted.)</p><h3>Delegator IAM Role</h3><p>What we have at the moment is <em>one big key to the house — anyone with the key can enter and do everything.</em><br>This might work in very small teams with tight manual controls, but it becomes risky as we grow.</p><p>Here are some concerns we’ll encounter when we try to scale:</p><ul><li>Over-provisioning risk: Anyone can become the administrator of the cluster. As long as they’re assigned or assume the role, they get full admin rights. Even if they just want to view logs, they could accidentally (or maliciously) delete clusters.</li><li>Blast radius: If a user’s account is compromised, the attacker immediately gains full cluster admin access.</li><li>Maintenance pain: As new access levels are needed (like SREs who only need partial access), we’ll end up creating new roles and access entries and having to track everything manually.</li></ul><p>What if you had a security guard who checks who’s allowed in — and hands out keys only to the rooms they’re permitted to access?</p><p>That’s the job of the <em>Delegator IAM Role</em>.</p><h4>Assume Role</h4><p>Instead of permanently assigning roles to users, get them to assume roles only when needed.<br>Assuming a role temporarily grants a user all the permissions of that role for the duration of their session — no more, no less.</p><p>This is much safer:</p><ul><li>Users don’t have permanent access.</li><li>Permissions exist only for as long as the session is active.</li><li>Risk exposure is greatly reduced.</li></ul><h3>Command Line Codes</h3><h4>Assume Role — Get Temporary Credentials</h4><ol><li>Use the <em>assume-role</em> command of the AWS CLI (which calls the AWS STS service) to assume the EKSAdminUserRole.</li><li>The command will give you a set of temporary credentials.</li><li>Set environment variables AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_SESSION_TOKEN with these temporary values.</li></ol><p>Let’s combine all of this in one command</p><pre>eval $(aws sts assume-role --role-arn arn:aws:iam::XXXXXXXXXXXX:role/EKSAdminUserRole --role-session-name eks-admin-session --query &#39;Credentials.{AWS_ACCESS_KEY_ID:AccessKeyId, AWS_SECRET_ACCESS_KEY:SecretAccessKey, AWS_SESSION_TOKEN:SessionToken}&#39; --output text | awk &#39;{print &quot;export AWS_ACCESS_KEY_ID=&quot;$1&quot;\nexport AWS_SECRET_ACCESS_KEY=&quot;$2&quot;\nexport AWS_SESSION_TOKEN=&quot;$3}&#39;)</pre><h4>Kubeconfig — Get the cluster information</h4><p>Now that we have the temporary credentials that give us permissions, let’s get the cluster information so that we can start interacting with it. Here we use kubectl to connect to the cluster.</p><pre>aws eks update-kubeconfig --name gsa-eks --region us-east-1</pre><h4>You are in! Access the cluster</h4><p>Now you have the permissions and cluster information. Go ahead and try to access the objects in the cluster</p><pre>kubectl get nodes</pre><p>(PS: If you have just created a cluster and have not set up any managed nodes, then this command will return no response. As long as you do not get an error, you are good!)</p><p>Let’s continue down the rabbit hole…</p><h3>Delegator IAM Role — The Traffic Guard</h3><p>Think of a Delegator IAM role as a traffic router. Based on conditions, it can route users to other roles that have relevant permissions.</p><p>To understand this better, let’s use the load balancer analogy:</p><ul><li>Delegator IAM Role = Entry point (like a load balancer)</li><li>Conditions like tags, MFA, other attribute checks = Routing rules (like load balancer listeners)</li><li>Different destination roles (Admin, Read-Only, Operator) = Target groups</li></ul><p><em>One delegator, many pathways — based on policies + conditions.</em></p><h4>Create the Role &amp; Permissions</h4><p>Name: <em>EKSAccessDelegatorRole</em><br>Permissions: <em>Allow to assume role EKSAdminUserRoles </em><strong><em>IF</em></strong><em> they have the tag eks-admin-user=true<br></em>Trust Policy: <em>Trust any principal in the AWS account</em></p><p>Permissions JSON</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;AllowAssumeOnlyForAdminTaggedUsers&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:iam::XXXXXXXXXXXX:role/EKSAdminUserRole&quot;,<br>            &quot;Condition&quot;: {<br>                &quot;StringEquals&quot;: {<br>                    &quot;aws:PrincipalTag/eks-admin-user&quot;: &quot;true&quot;<br>                }<br>            }<br>        }<br>    ]<br>}</pre><p>Trust Policy JSON</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::XXXXXXXXXXXX:root&quot;<br>            }<br>        }<br>    ]<br>}</pre><h4>Update EKSAdminUserRole</h4><p>You should already have a role EKSAdminUserRole. The trust policy of EKSAdminUser role allows anyone in the AWS account to assume the admin. This means, anyone in the AWS account can become the administrator of the Kubernetes cluster. And we definitely don’t like that.</p><p>Edit EKSAdminUserRole and modify the trust policy to allow ONLY users who come via the <em>EKSAccessDelegatorRole </em>to assume this role. So the only way you can get admin permissions into the cluster is if the Delegator role allows you to.</p><p>Trust Policy JSON</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>                &quot;AWS&quot;: &quot;arn:aws:iam::XXXXXXXXXXXX:role/EKSAccessDelegatorRole&quot;<br>            },<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>        }<br>    ]<br>}</pre><h3>Testing it All Out: Final Command Flow</h3><p>On my laptop, my current AWS CLI user is terraformcli</p><pre>gayatriajith@mymaclaptop ~ % aws sts get-caller-identity<br>{<br>    &quot;UserId&quot;: &quot;ABCDEFGHIJ4LMNO8PQRS3&quot;,<br>    &quot;Account&quot;: &quot;XXXXXXXXXXXX&quot;,<br>    &quot;Arn&quot;: &quot;arn:aws:iam::XXXXXXXXXXXX:user/terraformcli&quot;<br>}</pre><p>Assume the Delegator Role</p><pre>eval $(aws sts assume-role --role-arn arn:aws:iam::XXXXXXXXXXXX:role/EKSAdminAccessDelegatorRole --role-session-name eks-admin-session --query &#39;Credentials.{AWS_ACCESS_KEY_ID:AccessKeyId, AWS_SECRET_ACCESS_KEY:SecretAccessKey, AWS_SESSION_TOKEN:SessionToken}&#39; --output text | awk &#39;{print &quot;export AWS_ACCESS_KEY_ID=&quot;$1&quot;\nexport AWS_SECRET_ACCESS_KEY=&quot;$2&quot;\nexport AWS_SESSION_TOKEN=&quot;$3}&#39;)</pre><p>Assume the Admin Role</p><pre>eval $(aws sts assume-role --role-arn arn:aws:iam::XXXXXXXXXXXX:role/EKSAdminUserRole --role-session-name eks-final-admin-session --query &#39;Credentials.{AWS_ACCESS_KEY_ID:AccessKeyId, AWS_SECRET_ACCESS_KEY:SecretAccessKey, AWS_SESSION_TOKEN:SessionToken}&#39; --output text | awk &#39;{print &quot;export AWS_ACCESS_KEY_ID=&quot;$1&quot;\nexport AWS_SECRET_ACCESS_KEY=&quot;$2&quot;\nexport AWS_SESSION_TOKEN=&quot;$3}&#39;)</pre><p>Get the cluster info (kubeconfig)</p><pre>aws eks update-kubeconfig --name gsa-eks --region us-east-1</pre><p>Access cluster resources</p><pre>kubectl get nodes</pre><p>That’s it? Not quite yet. There is one more thing that we need to do for us to get admin access — add the tag to the user. Remember, we have the permission to assume the admin role only if our current user has the tag <em>eks-admin-user=true</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWi_j-OVsU5sZ_68CsISkQ.png" /><figcaption>The eks-admin-user tag must be set to true to access the cluster</figcaption></figure><p>That’s it? Nope — not yet. ((Because nothing’s ever truly simple, right?))</p><p>This is what we have so far:</p><ul><li>Delegator Role who has permission to assume the admin role, provided they have the tag, and trusts anyone in the AWS account</li><li>Admin Role who has admin permissions in the cluster and trusts anyone who has the delegator role.</li><li>An IAM User <em>terraformcli</em> who has the tag <em>eks-admin-user=true</em></li></ul><p>What is missing is giving the IAM user permission to assume the delegator role. It is not enough for the role to trust an entity, the entity needs to have permissions to assume the role too! <br>That is why you will see the admin role trusts anyone who has the delegator role, while the delegator role has the permission to assume the admin role.</p><p>IAM User <em>terraformcli</em> Permissions JSON</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Action&quot;: &quot;sts:AssumeRole&quot;,<br>            &quot;Resource&quot;: &quot;arn:aws:iam::XXXXXXXXXX:role/EKSAccessDelegatorRole&quot;<br>        }<br>    ]<br>}</pre><p>That’s it? Yes — finally!</p><h4>Workflow Diagram</h4><pre>terraformcli IAM User (with tag)<br>        │<br>        ▼<br>Assume → EKSAccessDelegatorRole<br>        │<br>        └── condition: tag eks-admin-user=true<br>                │<br>                ▼<br>          Assume → EKSAdminUserRole<br>                ▼<br>        Access the EKS Cluster</pre><h3>Further Options</h3><p>You can play around with this and expand it to be as simple or as complicated as you need. Some examples:</p><ul><li>have more paths and permission types.</li><li>create an AWS User Group and add the assume delegator permission to the group so that you do not have to edit the permissions of every user who needs admin access.</li><li>connect an external identity provider (IdP) like Azure AD, Okta etc, and dynamically tag users during login — zero manual tag management.(Attribute-Based Access Control, ABAC.)</li></ul><p>We came for cluster access, stayed for the role chaining, and left with tagged elegance. So the next time someone asks, “Can I get admin access?”, you can smile and say, “Only if the Delegator lets you in.”</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aabaf1d32e67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Operator Demystified]]></title>
            <link>https://gayatrisajith.medium.com/kubernetes-operator-demystified-dd8336c056dd?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd8336c056dd</guid>
            <category><![CDATA[custom-resource]]></category>
            <category><![CDATA[kubernetes-operator]]></category>
            <category><![CDATA[kubernetes-controller]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Fri, 06 Aug 2021 21:30:35 GMT</pubDate>
            <atom:updated>2021-08-07T13:52:25.488Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lh9Rmm0d3FezBLMdQnoThA.png" /><figcaption>The mystery behind Kubernetes Operators!</figcaption></figure><p>Let’s get one thing off the plate — Kubernetes Operator is not an object. It&#39;s a design pattern. With that, let&#39;s understand what is Kubernetes Operator.</p><h3>Operator Pattern</h3><p>From the <a href="https://kubernetes.io/docs/concepts/extend-kubernetes/operator/">official documentation</a>,</p><blockquote>Operators are software extensions to Kubernetes that make use of custom resources to manage applications and their components. Operators follow Kubernetes principles, notably the control loop.</blockquote><p>So, what does this mean? It means a Kubernetes operator is a design pattern that combines custom resources &amp; custom controllers.</p><p>Again, what does this mean?</p><figure><img alt="Custom Resource + Custom Controller = Kubernetes Operator" src="https://cdn-images-1.medium.com/max/582/1*zV1GEb54qS12fOE_Ozl12g.png" /><figcaption>Kubernetes Operator is a design pattern.</figcaption></figure><h3>Custom Resource</h3><p>A <em>resource</em> is an endpoint in the Kubernetes API. <br>This endpoint manages data of a particular object type — add, edit, delete. <br>For example, Pod resource is an endpoint in the Kubernetes API that manages Pod object data.</p><p>In the same way, a <em>custom resource</em> is a custom endpoint in the Kubernetes API that isn’t a part of the default installation. Once you create a custom resource definition (CRD) in the cluster, you can perform all the basic REST API calls — GET, PUT, POST, DELETE, PATCH and so on — using the custom endpoint created to manage the data of the custom resource objects.</p><h3>Controller or Control Loop</h3><p><em>Once again, let&#39;s get this one too out of the picture — a controller is not a Kubernetes object. It&#39;s a design pattern. Moving on….</em></p><p>Custom Resource Definition will just create a custom endpoint to blindly store and retrieve data related to the custom object. But, what should this custom resource do? For example, ReplicaSet resource creates pods, Pod resource creates containers — what will your resource do? This is where <em>custom controllers</em> come into the picture.</p><p>A <em>controller</em> is a control loop/non-terminating process that is constantly checking the state of at least one Kubernetes object (built-in or custom). This is the script that is notified when an object of a particular resource type is added, deleted or modified. You can then decide what you want to do with the event — create containers, call external URLs, whatever you fancy.</p><p>To create a control loop script all you need is a way to detect changes happening in the cluster — like, a new object of a particular type added, deleted or modified. Kubernetes has a built-in feature for this called <strong><em>Watch</em></strong>.</p><h3>Kubernetes API Watch</h3><p>The <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#efficient-detection-of-changes">documentation</a> explains this quite well,</p><blockquote>To enable clients to build a model of the current state of a cluster, all Kubernetes object resource types are required to support consistent lists and an incremental change notification feed called a <strong>watch</strong>. Every Kubernetes object has a resourceVersion field representing the version of that resource as stored in the underlying database. When retrieving a collection of resources (either namespace or cluster scoped), the response from the server will contain a resourceVersion value that can be used to initiate a watch against the server. The server will return all changes (creates, deletes, and updates) that occur after the supplied resourceVersion. This allows a client to fetch the current state and then watch for changes without missing any updates. If the client watch is disconnected they can restart a new watch from the last returned resourceVersion, or perform a new collection request and begin again.</blockquote><p>Let’s try to understand this with an example.</p><p>This is a sample API call to GET the list of Pods in the default namespace. <br>The response returns 3 Pods. Notice the <em>resourceVersion</em> in the metadata of each Pod. <em>resourceVersion</em> is like an ID for the object in the database.</p><pre><em>curl --insecure -H &quot;Authorization: Bearer $TOKEN&quot; </em><a href="https://kubernetes/api/v1/namespaces/default/pods"><em>https://kubernetes/api/v1/namespaces/default/pods</em></a><em><br></em>{<br>  &quot;kind&quot;: &quot;PodList&quot;,<br>  &quot;apiVersion&quot;: &quot;v1&quot;,<br>  &quot;metadata&quot;: {<br>    &quot;resourceVersion&quot;: &quot;1291&quot;<br>  },<br>  &quot;items&quot;: [<br>    {<br>      &quot;metadata&quot;: {<br>        &quot;name&quot;: &quot;test-ccdc9b768-nxtcw&quot;,<br>        &quot;namespace&quot;: &quot;default&quot;,<br><strong>        &quot;resourceVersion&quot;: &quot;918&quot;,</strong><br>        ...<br>      },<br>      &quot;spec&quot;: {<br>      ...  <br>      },<br>      &quot;status&quot;: {<br>        ...<br>      }<br>    },<br>    {<br>      &quot;metadata&quot;: {<br>        &quot;name&quot;: &quot;test-ccdc9b768-vwsxn&quot;,<br>        &quot;namespace&quot;: &quot;default&quot;,<br><strong>        &quot;resourceVersion&quot;: &quot;953&quot;,</strong><br>        ...<br>      },<br>      &quot;spec&quot;: {<br>        ...<br>      },<br>      &quot;status&quot;: {<br>        ...<br>      }<br>    },<br>    {<br>      &quot;metadata&quot;: {<br>        &quot;name&quot;: &quot;test-ccdc9b768-vxhds&quot;,<br>        &quot;namespace&quot;: &quot;default&quot;,<br><strong>        &quot;resourceVersion&quot;: &quot;<em>987</em>&quot;,</strong><br>        ...<br>      },<br>      &quot;spec&quot;: {<br>        ...<br>      },<br>      &quot;status&quot;: {<br>        ...<br>      }<br>    }<br>  ]<br>}</pre><p>You can now initiate a <em>Watch</em> for Pods in the default namespace by sending watch=1 and resourceVersion=&lt;resourceVersion&gt; in the API call. What this will do is,</p><ul><li>return all the events for the object type Pod in the default namespace after this resourceVersion.</li><li>keep the connection open (using long-polling)so that you can continue getting the events.</li></ul><p>For example, if I created a new Pod named “my-new-test-pod” and then, started a Watch using the latest resourceVersion from the previous call (which is 987 in our example) then I would get a response like this…</p><pre><em>curl --insecure -H &quot;Authorization: Bearer $TOKEN&quot; </em><a href="https://kubernetes/api/v1/namespaces/default/pods?watch=1&amp;resourceVersion=987"><em>https://kubernetes/api/v1/namespaces/default/pods?</em><strong><em>watch=1&amp;resourceVersion=987</em></strong></a></pre><pre>{&quot;type&quot;:&quot;ADDED&quot;,&quot;object&quot;:{&quot;kind&quot;:&quot;Pod&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;metadata&quot;:{&quot;name&quot;:&quot;my-new-test-pod&quot;,&quot;resourceVersion&quot;:&quot;11046&quot;...},&quot;spec&quot;:{...}...}}<br>{&quot;type&quot;:&quot;MODIFIED&quot;,&quot;object&quot;:{&quot;kind&quot;:&quot;Pod&quot;,&quot;apiVersion&quot;:&quot;v1&quot;,&quot;metadata&quot;:{&quot;resourceVersion&quot;:&quot;11047&quot;...},&quot;spec&quot;:{...}...}}</pre><p>Every time an event associated with a Pod in the default namespace occurs, I will get the event type and the object information that has the resourceVersion and the specs. And this connection will not close — so, I will continue getting the list of events. I can now decide what I want to do with these events!</p><h3>Let’s Understand the Flow with an Example.</h3><p>A Kubernetes Operator is a Custom Resource Definition &amp; a Control Loop script (controller) for that custom resource. That is it.</p><p>These are the steps we will follow:</p><ol><li>Create a custom resource</li><li>Create a Pod that will run our control loop script</li><li>Decide what our script will do with the events</li></ol><h4>Step 1: Create a Custom Resource</h4><p>To create a Custom Resource we need to create a <em>Custom Resource Definition</em> (CRD). Check the official documentation for more on the <a href="https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/">syntax of a Custom Resource Definition</a></p><p>CRD will describe the schema of our new resource (schema means what fields can be used in our new resource, what is the data type of the values, default values, validations etc).</p><pre><em>mycrd.yaml</em></pre><pre>apiVersion: apiextensions.k8s.io/v1<br>kind: CustomResourceDefinition<br>metadata:<br>  name: mywebservers.k8sobjects.gsa.com<br>spec:<br>  group: k8sobjects.gsa.com<br>  scope: Namespaced<br>  names:<br>    kind: MyWebserver<br>    singular: mywebserver<br>    plural: mywebservers<br>    shortNames:<br>    - myweb<br>    - mws<br>  versions:<br>    - name: v2<br>      served: true<br>      storage: true<br>      schema:<br>        openAPIV3Schema:<br>          type: object<br>          properties:<br>            spec:<br>              type: object<br>              properties:<br>                image:<br>                  type: string<br>                port:<br>                  type: integer<br>                replicas:<br>                  type: integer</pre><p>Above CRD defines the schema for a new object called ‘MyWebserver’. It can be referred to with the names <em>mywebserver</em>, <em>mywebservers</em>, <em>myweb</em>, <em>mws</em>.</p><pre>kubectl apply -f mycrd.yaml</pre><p>This custom resource definition will create new endpoints in the Kubernetes API</p><pre><strong># Get the list of API groups available. You should see your custom resource listed here</strong><br><em>curl --insecure -X GET -H &quot;Authorization: Bearer $TOKEN&quot; </em><a href="https://kubernetes/apis/"><em>https://kubernetes/apis/</em></a></pre><pre>{<br>  &quot;kind&quot;: &quot;APIGroupList&quot;,<br>  &quot;apiVersion&quot;: &quot;v1&quot;,<br>  &quot;groups&quot;: [<br>    ...<br>    {<br>      &quot;name&quot;: &quot;apps&quot;,<br>      &quot;versions&quot;: [<br>        {<br>          &quot;groupVersion&quot;: &quot;apps/v1&quot;,<br>          &quot;version&quot;: &quot;v1&quot;<br>        }<br>      ],<br>      &quot;preferredVersion&quot;: {<br>        &quot;groupVersion&quot;: &quot;apps/v1&quot;,<br>        &quot;version&quot;: &quot;v1&quot;<br>      }<br>    },<br>    ...<br>    {<br>      &quot;name&quot;: &quot;k8sobjects.gsa.com&quot;,<br>      &quot;versions&quot;: [<br>        {<br>          &quot;groupVersion&quot;: &quot;k8sobjects.gsa.com/v2&quot;,<br>          &quot;version&quot;: &quot;v2&quot;<br>        }<br>      ],<br>      &quot;preferredVersion&quot;: {<br>        &quot;groupVersion&quot;: &quot;k8sobjects.gsa.com/v2&quot;,<br>        &quot;version&quot;: &quot;v2&quot;<br>      }<br>    }<br>  ]<br>}</pre><pre><strong># Get list of <em>mywebserver</em> objects in any namespace</strong><br><em>curl --insecure -X GET -H &quot;Authorization: Bearer $TOKEN&quot; </em><a href="https://kubernetes/apis/k8sobjects.gsa.com/v2/mywebservers"><em>https://kubernetes/apis/k8sobjects.gsa.com/v2/mywebservers</em></a></pre><pre>{<br>  &quot;apiVersion&quot;:&quot;k8sobjects.gsa.com/v2&quot;,<br>  &quot;items&quot;:[....],<br>  &quot;kind&quot;:&quot;MyWebserverList&quot;,<br>  &quot;metadata&quot;:{&quot;continue&quot;:&quot;&quot;,&quot;resourceVersion&quot;:&quot;16800&quot;}<br>}</pre><p>So, the YAML to create my new object based on this custom resource definition will look like this</p><pre><em>myobj.yaml</em></pre><pre>apiVersion: &quot;k8sobjects.gsa.com/v2&quot;<br>kind: MyWebserver<br>metadata:<br>  name: webapp<br>spec:<br>  image: nginx<br>  port: 80<br>  replicas: 2</pre><pre><strong>kubectl apply -f myobj.yaml</strong></pre><p><em>apiVersion</em> is your CRD &lt;group name&gt;/&lt;version name&gt;<br>the object has a property <em>spec</em> which has the sub-properties <em>image</em> of the type string, <em>port</em> of the type integer and <em>replicas</em> of the type integer.<br>You can now use kubectl to manage the object.</p><pre><strong>kubectl get mws</strong><br>NAME     AGE<br>webapp   67s</pre><pre><strong>kubectl describe mws webapp</strong><br>Name:         webapp<br>Namespace:    default<br>Labels:       &lt;none&gt;<br>Annotations:  &lt;none&gt;<br>API Version:  k8sobjects.gsa.com/v2<br>Kind:         MyWebserver<br>Metadata:<br>  Creation Timestamp:  2021-08-06T18:57:09Z<br>  Generation:          1<br>  Managed Fields:<br>    API Version:  k8sobjects.gsa.com/v2<br>    Fields Type:  FieldsV1<br>    fieldsV1:<br>      f:metadata:<br>        f:annotations:<br>          .:<br>          f:kubectl.kubernetes.io/last-applied-configuration:<br>      f:spec:<br>        .:<br>        f:image:<br>        f:port:<br>        f:replicas:<br>    Manager:         kubectl-client-side-apply<br>    Operation:       Update<br>    Time:            2021-08-06T18:57:09Z<br>  Resource Version:  17033<br>  UID:               ce87c872-ad71-4092-a0ec-a10f65a4b132<br>Spec:<br>  Image:     nginx<br>  Port:      80<br>  Replicas:  2<br>Events:      &lt;none&gt;</pre><pre><strong># List mywebserver objects in the default namespace</strong><br><em>curl --insecure -X GET -H &quot;Authorization: Bearer $TOKEN&quot; </em><a href="https://kubernetes/apis/k8sobjects.gsa.com/v2/namespaces/default/mywebservers"><em>https://kubernetes/apis/k8sobjects.gsa.com/v2/namespaces/default/mywebservers</em></a></pre><pre>{<br>  &quot;apiVersion&quot;:&quot;k8sobjects.gsa.com/v2&quot;,<br>  &quot;items&quot;:[<br>    {<br>      &quot;apiVersion&quot;:&quot;k8sobjects.gsa.com/v2&quot;,<br>      &quot;kind&quot;:&quot;MyWebserver&quot;,<br>      &quot;metadata&quot;:{<br>        &quot;annotations&quot;:{...},<br>        &quot;creationTimestamp&quot;:&quot;2021-08-06T18:57:09Z&quot;,<br>        &quot;generation&quot;:1,<br>        &quot;managedFields&quot;:[...],<br>        &quot;name&quot;:&quot;webapp&quot;,<br>        &quot;namespace&quot;:&quot;default&quot;,<br>        &quot;resourceVersion&quot;:&quot;17033&quot;,<br>        &quot;uid&quot;:&quot;ce87c872-ad71-4092-a0ec-a10f65a4b132&quot;<br>      },<br>      &quot;spec&quot;:{<br>        &quot;image&quot;:&quot;nginx&quot;,<br>        &quot;port&quot;:80,&quot;replicas&quot;:2<br>      }<br>    }<br>  ],<br>  &quot;kind&quot;:&quot;MyWebserverList&quot;,<br>  &quot;metadata&quot;:{<br>    &quot;continue&quot;:&quot;&quot;,<br>    &quot;resourceVersion&quot;:&quot;17265&quot;<br>  }<br>}</pre><h4><strong>Step 2: Create a Pod that will run our Control Loop script</strong></h4><p>Now that the Custom Resource has been created, we need a Control Loop script that will monitor this custom resource and get events when an object of this custom resource type is created, deleted or modified.</p><p>Why are we running this Control Loop script inside a Pod?</p><ul><li>It&#39;s easier to grant the necessary permissions to our script using Service Accounts.</li><li>You can run the pod as a <em>daemonset</em> to ensure that it&#39;s always running.</li></ul><p>To keep things simple, I am going to use PHP to run our control loop script. Feel free to use any programming language you like. It&#39;s a misconception that control loop scripts can be written only in Go, Python or Java!</p><p>Here is the <em>Service Account</em> to give our script the necessary permissions. We are permitting ourselves to work with our Custom Resource (MyWebserver), Deployments and Pods in any namespace.</p><pre><em>permissions.yaml</em></pre><pre>---<br>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  name: mywebservers-sa</pre><pre>---<br>apiVersion: rbac.authorization.k8s.io/v1<br>kind: ClusterRole<br>metadata:<br>  name: mywebservers-cr<br>rules:<br>- apiGroups:<br>  - apiextensions.k8s.io<br>  resources:<br>  - customresourcedefinitions<br>  verbs:<br>  - list<br>- apiGroups: [&quot;extensions&quot;, &quot;apps&quot;]<br>  resources: [&quot;deployments&quot;]<br>  verbs: [&#39;*&#39;]<br>- apiGroups:<br>  - &quot;&quot;<br>  resources:<br>  - pods<br>  verbs:<br>   - &#39;*&#39;<br>- apiGroups:<br>  - &quot;k8sobjects.gsa.com&quot;<br>  - &quot;k8sobjects.gsa.com/v2&quot;<br>  resources:<br>  - mywebservers<br>  verbs:<br>   - &#39;*&#39;</pre><pre>---<br>kind: ClusterRoleBinding<br>apiVersion: rbac.authorization.k8s.io/v1<br>metadata:<br>  name: mywebservers-crb<br>subjects:<br>- kind: ServiceAccount<br>  name: mywebservers-sa<br>  namespace: default<br>roleRef:<br>  kind: ClusterRole<br>  name: mywebservers-cr<br>  apiGroup: rbac.authorization.k8s.io</pre><p>This Deployment will run my control loop script. It is of course in the custom Docker image.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: php-client<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: php-client<br>  template:<br>    metadata:<br>      labels:<br>        app: php-client<br>    spec:<br>      serviceAccountName: mywebservers-sa<br>      containers:<br>        - name: n1<br>          image: gayatrisa/learn-k8s:client<br>          ports:<br>            - containerPort: 80</pre><h4><strong>Step 3: Decide what you want to do inside your script</strong></h4><p>Ultimately, what I am hoping to do is, when an object of the type <em>mywebserver</em> is created, a Deployment &amp; Service object must be created using the image name and port number specified in the <em>mywebserver</em> object.</p><p>My control loop script looks like this. (I have hidden the PHP coding complexities of streams etc. A working code is available on <a href="https://github.com/gayatri-sa/k8s-operator">GitHub</a>.)</p><pre>&lt;?php<br>$myop = new K8sClient();</pre><pre>$resourceVersion = &#39;&#39;;<br>do {<br>    $events = $myop-&gt;watchObject($resourceVersion);<br>    if (!empty($events) &amp;&amp; is_array($events)) {<br>       $latestResourceVersion = $events[sizeof($events)-1][&#39;object&#39;][&#39;metadata&#39;][&#39;resourceVersion&#39;];</pre><pre>if ($resourceVersion &gt;= $latestResourceVersion) {<br>            break;<br>        }<br>        $resourceVersion = $latestResourceVersion;<br>    }<br>    foreach ($events as $event) {       <br>        switch ($event[&#39;type&#39;]) {<br>            case &#39;ADDED&#39;:<br>                echo &#39;----- EVENT TYPE: ADDED -----&#39; . &quot;\n&quot;;<br>                <strong><em>// Create a deployment and service based on the object data we got from the event</em></strong><br>                break;<br>            case &#39;DELETED&#39;:<br>                echo &#39;----- EVENT TYPE: DELETED -----&#39; . &quot;\n&quot;;<br>                <strong><em>// Delete the deployment and service we created based on the object data we got from the event</em></strong><br>                break;<br>        }<br>    }<br>    <br>} while (!empty($events));</pre><p>So for every <em>mywebserver</em> object that is added 1 Deployment and 1 Service object is created by my controller (control loop script). Similarly, for every <em>mywebserver</em> object, you delete the corresponding 1 Deployment and 1 Service object will get deleted by my controller.</p><p>Now, you have total power — you can choose to even trigger an external action!</p><h3>Conclusion</h3><p>So, what do you need in a simple Kubernetes Operator Design:</p><ul><li>A Custom Resource Definition, to create your custom API endpoints</li><li>A Custom Controller/Control Loop script, that will get the events related to your custom resource</li><li>A Pod, to run your control loop script</li><li>A Service Account, which gives your control loop script the necessary permissions</li></ul><p>Many wonderful SDKs hide these complexities and steps, making it all smooth and easy for you. One of the most popular ones is <a href="https://sdk.operatorframework.io/">OperatorSDK</a>. Once this flow is clear I would recommend using an SDK instead of doing it all yourself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd8336c056dd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AWS KMS for a Kops Kuberenetes Cluster]]></title>
            <link>https://medium.com/geekculture/aws-kms-for-a-kops-kuberenetes-cluster-4f5716cccf7d?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f5716cccf7d</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[kops]]></category>
            <category><![CDATA[amazon-aws]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Thu, 01 Jul 2021 12:09:57 GMT</pubDate>
            <atom:updated>2021-07-03T08:30:07.411Z</atom:updated>
            <content:encoded><![CDATA[<h3>Amazon KMS for a Kops Kuberenetes Cluster</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHc0E6xH4V-NEhg_voGqLQ.png" /></figure><p>When using Amazon EKS you can configure a AWS KMS key to encrypt etcd. How to do that for a cluster created using <a href="https://github.com/kubernetes/kops">kops</a>? It took me a few hours to understand the whole flow. So, here goes.</p><h4>What is Kops?</h4><p>kops helps you create, update &amp; maintain production-quality, highly available, Kubernetes cluster — also taking care of provisioning the necessary cloud infrastructure. Its officially supports Amazon AWS at the moment (rest of the cloud providers are in alpha &amp; beta mode)</p><h4>Pre-requisites</h4><ul><li>A working Kubernetes Cluster created using Kops on Amazon AWS</li><li>The AWS CLI Amazon AWS user that was used to create the cluster should be given permissions to manage Amazon KMS Keys. I gave my kops Amazon AWS user <em>AWSKeyManagementServicePowerUser</em> permissions. (I am sure its not safe to give such elevated permissions but, I didn’t have the patience or need to explore further for my development cluster. Do leave a comment if you find out the exact permissions needed.)</li></ul><h4>Step 1: Create the Amazon KMS master key</h4><p>This is the Key that will be used by Amazon KMS provider (we will see what is a provider soon) to manage the encrypted data.</p><p>You can create this Key via the Amazon AWS Web Console or if your AWS CLI user has enough permissions you can create it via AWS CLI too.</p><pre>KEY_ID=$(aws kms create-key --query KeyMetadata.KeyId --output text)<br>aws kms describe-key --key-id $KEY_ID</pre><p>You will get a long JSON output that will looks like this. Note the ARN value — we will need it.</p><pre>{<br>    &quot;KeyMetadata&quot;: {<br>        &quot;Origin&quot;: &quot;AWS_KMS&quot;,<br>        &quot;KeyId&quot;: &quot;1234abcd-12ab-34cd-56ef-1234567890ab&quot;,<br>        &quot;Description&quot;: &quot;&quot;,<br>        &quot;KeyManager&quot;: &quot;CUSTOMER&quot;,<br>        &quot;Enabled&quot;: true,<br>        &quot;KeyUsage&quot;: &quot;ENCRYPT_DECRYPT&quot;,<br>        &quot;KeyState&quot;: &quot;Enabled&quot;,<br>        &quot;CreationDate&quot;: 1403010355.345,<br>        &quot;Arn&quot;: &quot;arn:aws:kms:ap-south-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab&quot;,<br>        &quot;AWSAccountId&quot;: &quot;111122223333&quot;<br>    }<br>}</pre><h4>Step 2: Create the KMS Provider Docker Image</h4><p>A provider is the program/script that will be called by K8s when data needs to be encrypted or decrypted. You need to create such a provider for Amazon KMS so that the K8s cluster can call this provider to encrypt/decrypt data using Amazon KMS.</p><p>There is a ready provider program for Amazon KMS here: <a href="https://github.com/kubernetes-sigs/aws-encryption-provider">https://github.com/kubernetes-sigs/aws-encryption-provider</a></p><p>Clone the project, build the docker image and we will the imageto create the container which will run the Amazon KMS provider program.</p><pre>git clone <a href="https://github.com/kubernetes-sigs/aws-encryption-provider">https://github.com/kubernetes-sigs/aws-encryption-provider</a><br>cd aws-encryption-provider/<br>docker build -t &lt;the name for your Docker Image&gt; ./<br>[DONT FORGET TO PUSH YOUR DOCKER IMAGE TO A REPO LIKE DOCKER HUB]</pre><h4>Step 3: Add a label to all Master nodes</h4><p>The KMS provider program running inside the container uses labels to identify master nodes. We need to add this label to all master node. To do this we will edit the Master Node Instance Group.</p><pre># List all the instance groups<br>kops get ig --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt;</pre><pre># Edit the master instance group<br>kops edit ig &lt;MASTER IG NAME&gt; --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt;</pre><pre>kind: InstanceGroup<br>spec:<br>  nodeLabels:<br>    <em>dedicated: master</em> # this is the label<br>  role: Master</pre><h4>Step 4: Create the Amazon KMS Provider container on the Master node</h4><p>We need to now run this provider container on the master node(s) since that is where the API Server is. We will create this container as a Static Pod on all master nodes. Why <a href="https://kubernetes.io/docs/tasks/configure-pod-container/static-pod/">static pod</a>? Because this container needs to be independent of the API Server. Static pods are managed by the kubelet directly.</p><p>On the master nodes, manifest files for static pods are found in <em>/etc/kubernetes/manifests</em>. So we need to create our Amazon KMS Provider’s static pod manifest file in this path too.</p><p>How do we create static pods in a kops managed cluster? Using the <em>fileAssets</em> key in the <a href="https://github.com/kubernetes/kops/blob/master/docs/cluster_spec.md">Cluster spec</a>. <em>fileAssets</em> allows you to create files (using inline file contents) on nodes in the cluster. You can use <em>roles</em> to decide which type of nodes you want this file to be created on. This ensures that even if you have multiple master, the provider static pod manifest file will be created on all of them.</p><pre># Edit the cluster object spec<br>kops edit cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt;</pre><pre>kind: Cluster<br>spec:<br>  fileAssets:<br>  - name: aws-encryption-provider.yaml # name of the file we want to create<br>    path: /etc/kubernetes/manifests/aws-encryption-provider.yaml<br>    roles:<br>    - Master # want to create this on Master nodes<br>    content: | # contents of the file<br>      apiVersion: v1<br>      kind: Pod<br>      metadata:<br>        annotations:<br>          scheduler.alpha.kubernetes.io/critical-pod: &quot;&quot;<br>        labels:<br>          k8s-app: aws-encryption-provider<br>        name: aws-encryption-provider<br>        namespace: kube-system<br>      spec:<br>        containers:<br>        - image: &lt;THE AWS PROVIDER DOCKER IMAGE YOU BUILT&gt;<br>          name: aws-encryption-provider<br>          command:<br>          - /aws-encryption-provider<br>          - --key=&lt;ARN OF THE KEY YOU CREATED&gt;<br>          - --region=&lt;THE AWS REGION OF THE KEY&gt;<br>          - --listen=/srv/kubernetes/socket.sock<br>          - --health-port=:8083<br>          ports:<br>          - containerPort: 8083<br>            protocol: TCP<br>          livenessProbe:<br>            httpGet:<br>              path: /healthz<br>              port: 8083<br>          volumeMounts:<br>          - mountPath: /srv/kubernetes<br>            name: kmsplugin<br>        hostNetwork: true<br>        priorityClassName: system-cluster-critical<br>        volumes:<br>        - name: kmsplugin<br>          hostPath:<br>            path: /srv/kubernetes<br>            type: DirectoryOrCreate</pre><p>Save the file and when you exit the Cluster Objects specs will be saved. To update the cluster and roll the changes to all the nodes in the cluster execute these. Give the cluster 10–15 mins to get ready.</p><pre>kops update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes --admin<br>kops rolling-update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes</pre><h4>Step 5: Give Master node’s IAM Role permissions to manage KMS</h4><p>Ensure Master node’s IAM role (not the use that created the cluster) has permissions to encrypt/decrypt using the kms. Use the <em>additionalPolicies</em> key of the kops Cluster Object spec</p><pre># Edit the cluster object spec<br>kops edit cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt;</pre><pre>kind: Cluster<br>spec:<br>  additionalPolicies:<br>    master: |<br>      [<br>        {<br>          &quot;Effect&quot;: &quot;Allow&quot;,<br>          &quot;Action&quot;: [<br>            &quot;kms:Decrypt&quot;,<br>            &quot;kms:Encrypt&quot;<br>          ],<br>          &quot;Resource&quot;: [<br>            &quot;&lt;ARN OF THE KEY YOU CREATED&gt;&quot;<br>          ]<br>        }<br>      ]</pre><pre>kops update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes --admin</pre><p>Save the file and when you exit the Cluster Objects specs will be saved. To update the cluster and roll the changes to all the nodes in the cluster execute these. Give the cluster 10–15 mins to get ready.</p><pre>kops update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes --admin<br>kops rolling-update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes</pre><h4>STEP 6: Create the encryption configuration file</h4><p>The encryption configuration YAML file tells the K8s cluster what type of encryption provider to use and where the provider program/script is.</p><pre>apiVersion: apiserver.config.k8s.io/v1<br>kind: EncryptionConfiguration<br>resources:<br>  - resources:<br>    - secrets<br>    providers:<br>    - kms:<br>        name: aws-encryption-provider<br>        endpoint: unix:///srv/kubernetes/socket.sock<br>        cachesize: 1000<br>        timeout: 3s<br>    - identity: {}</pre><p>This encryption configuration file is telling K8s to use the KMS provider. And we are giving the path to the socket that will be called when the cluster needs to handle encryption. This socket is created/managed by our static pod. Look the socket path. It’s the same that is mounted into our static pod.</p><p><strong>Note:</strong> There are different types of encryption providers available. KMS is just one of them. This link has more info about the other types of providers: <a href="https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/#understanding-the-encryption-at-rest-configuration">https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/#understanding-the-encryption-at-rest-configuration</a></p><h4>STEP 7: Tell Kops about the encryption configuration file</h4><p>To tell Kops about this encryption config file all you need to do is create a kops secret with a special name <em>encryptionconfig</em></p><pre>kops create secret encryptionconfig -f &lt;PATH TO ENCRYPTION CONFIG FILE&gt; --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt;<br>kops update cluster &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes --admin</pre><h4>STEP 8: Enable encryption configuration in the cluster object</h4><p>Edit the cluster object and enable the feature to read/process the encryption configuration file.</p><pre># Edit the cluster object spec<br>kops edit cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt;</pre><pre>kind: Cluster<br>spec:<br>  encryptionConfig: true</pre><p>Save the file and when you exit the Cluster Objects specs will be saved. To update the cluster and roll the changes to all the nodes in the cluster execute these. Give the cluster 10–15 mins to get ready.</p><pre>kops update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes --admin<br>kops rolling-update cluster --name &lt;CLUSTER NAME&gt; --state &lt;STATE S3 BUCKET&gt; --yes</pre><h4>And, that’s it…</h4><p>You can confirm that all is well by creating a secret and querying ETCD to confirm that its encrypted using our provider.</p><pre># Create the secret object<br>kubectl create secret generic <strong>secret1</strong> -n default --from-literal=mykey=allgood</pre><pre># Enter the ETCD-Server<br>kubectl exec -it -n kube-system $(kubectl get pods -n kube-system | grep etcd-manager-main | awk &#39;{print $1}&#39;) sh</pre><pre># Query ETCD<br>cd /opt/etcd-v3.3.10-linux-amd64/<br>ETCDCTL_API=3 ./etcdctl \<br>    --key /rootfs/etc/kubernetes/pki/kube-apiserver/etcd-client.key \<br>    --cert  /rootfs/etc/kubernetes/pki/kube-apiserver/etcd-client.crt \<br>    --cacert /rootfs/etc/kubernetes/pki/kube-apiserver/etcd-ca.crt  \<br>    --endpoints &quot;<a href="https://127.0.0.1:4001/">https://127.0.0.1:4001</a>&quot; get /registry/secrets/default/<strong>secret1</strong></pre><p>Your output will look something like this. The value should be encrypted and you will notice the provider name in the output.</p><pre>/registry/secrets/default/secret1</pre><pre>0o0m0hc:`?He.0:<strong>aws-encryption-provider</strong>:?1xf???Ԥ????ʭ?i?$?I?M7?ۜ??c??(!?_B5 ?p?ؙ~0| *?H??</pre><pre>ka?H|C?[?OS?????٫?e??_!??ݥqx7f? E?`?{K{?t???;}??m??m?????|s??N^i1???,?b;?&amp;?`l[{R4&amp;c??Թ}?????)?`?{????-?T??˽4??|??T?+?$年g&lt;VHAĎ????Ǧo&gt;? ]W???</pre><pre>:?% ??Z7:?t?u?B??ء?w?G?3??7??@)\ x?????o?_???&#39;?&quot;?3F??K? &quot;ͤ6???.??????5?+?????H?\~YF????j???:$ϯOI8????????.0?</pre><p>Remember, technically, you can make all the changes together and update the cluster once. I’m sharing the steps as I executed it!</p><h4>Reference Links</h4><ul><li><a href="https://github.com/kubernetes-sigs/aws-encryption-provider/KOPS.md">https://github.com/kubernetes-sigs/aws-encryption-provider</a></li><li><a href="https://github.com/kubernetes-sigs/aws-encryption-provider/blob/master/KOPS.md">https://github.com/kubernetes-sigs/aws-encryption-provider/blob/master/KOPS.md</a></li><li><a href="https://github.com/kubernetes/kops/blob/master/docs/cluster_spec.md">https://github.com/kubernetes/kops/blob/master/docs/cluster_spec.md</a></li><li><a href="https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/#understanding-the-encryption-at-rest-configuration">https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f5716cccf7d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/geekculture/aws-kms-for-a-kops-kuberenetes-cluster-4f5716cccf7d">AWS KMS for a Kops Kuberenetes Cluster</a> was originally published in <a href="https://medium.com/geekculture">Geek Culture</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Fundamentals: Volumes]]></title>
            <link>https://faun.pub/kubernetes-fundamentals-volumes-226da3b55753?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/226da3b55753</guid>
            <category><![CDATA[persistent-volume-claim]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[kubernetes-volume]]></category>
            <category><![CDATA[persistent-volume]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Fri, 19 Mar 2021 15:03:36 GMT</pubDate>
            <atom:updated>2021-03-21T10:56:52.482Z</atom:updated>
            <cc:license>https://creativecommons.org/licenses/by-nd/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Data storage in a distributed environment is complex in itself. Add to that virtualisation and automation and you have multiple layers of planning to do. So, how does data work in a Kubernetes cluster?</p><p>Here I assume you are familiar with the <a href="https://medium.com/@gayatrisajith/kubernetes-fundamentals-common-terms-4cc63bb4718d">basic objects in Kubernetes</a> and how they interact with each other.</p><h3>There are 2 Parts</h3><p>There are 2 components to volumes in Kubernetes —</p><ul><li>The Cluster Object.</li><li>The Physical Storage.</li></ul><p>The persistence and share-ability of these components are independent of each other. This means <strong><em>if the object dies it doesn’t imply that the physical data is lost/cleared</em>.</strong> A new object can be created and attached to the same physical storage. For beginners, this part can be quite confusing since persistence of object is often equated to persistence of data. It is not.</p><figure><img alt="Multiple objects can point to the same physical storage. Persistence of the object is independent of the physical storage persistence" src="https://cdn-images-1.medium.com/max/1024/1*4L0seFU54rYO2oBm25NSKw.gif" /><figcaption>Volumes in Kubernetes</figcaption></figure><h3>I — Cluster Objects</h3><p>Kubernetes supports 2 types of objects —</p><ul><li>Volumes</li><li>Persistent Volumes</li></ul><p>Remember, we are talking about the cluster object, not the physical storage. Irrespective of whether it&#39;s a Volumes or Persistent volume you have to plan on what physical storage will back the object— where will the files be actually saved.</p><h4><strong>Kubernetes Volumes</strong></h4><p>Containers inside a Pod can share Kubernetes Volume objects. Hence, the life of such objects is tightly associated with the life of the Pod. These objects do not have a life independent of the Pod. As soon as the Pod dies this object dies. This object persists across container restarts.</p><p>Anytime you want to access data in a container of a Pod you have to use a Kubernetes Volume object — whether the data is from a Folder, ConfigMap, Secret, or a Kubernetes Persistent Volume.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*PFIHtym0UBk4nKrRCvAZlg.png" /><figcaption>Kubernetes Volumes</figcaption></figure><h4><strong>Kubernetes Persistent Volumes (PV)</strong></h4><p>Pods can share Kubernetes Persistent Volume objects — irrespective of the node where the Pod is created on. Hence, the life of persistent volume objects are independent of any other object in the cluster. Remember, Kubernetes will <em>NEVER</em> automatically delete a Persistent Volume object. You have to always do/trigger the deletion manually.</p><p>Just because the persistent volume object can be shared across Pods it does not mean Pods across nodes will have access to the same files — that depends on the physical storage. So, if the physical storage is a simple folder then Pods across nodes need not have the same files. On the other hand if, the physical storage is an NFS volume then, Pods across nodes can have the same files. Beginners tend to stumble on this.</p><p>For a container to access a Kubernetes Persistent Volume it has to create a Kubernetes Volume backed by the Kubernetes Persistent Volume. Remember, containers can only access/mount Kubernetes Volumes.</p><p><strong>How to define and use a Persistent Volume</strong></p><p>Defining and using a Kubernetes Persistent Volumes isn’t as simple as a Kubernetes Volume. The easiest way to understand this is by breaking it down into 2 steps:</p><ul><li>Splitting the physical storage into multiple cluster objects of defined size — <em>Kubernetes Persistent Volume object (PV)</em></li><li>Describing the type of storage your application needs and finding the cluster object that matching this requirement — <em>Kubernetes Persistent Volume Claim object (PVC)</em></li></ul><p>When a PVC object is created, K8s searches through all available PV objects and finds the one that matches the PVC. As soon as a match is found, the PV object is attached to the claim. It is a 1–1 relationship i.e., one PV object can be attached to only one PVC and vice versa. This PVC object is then used by the Pod.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*Nl8_tJUhzECax4w03S9cPA.png" /><figcaption>Kubernetes Persistent Volumes</figcaption></figure><h3>II — Physical Storage</h3><p>Kubernetes supports a lot of volume types (that is, physical storage solutions). You can find a complete list in the <a href="https://kubernetes.io/docs/concepts/storage/volumes/#volume-types">k8s official documentation</a>. Depending on the type of volume (storage solution) you choose the parameters that need to be passed change.</p><p>An interesting point to remember is, some of these storage solutions can be dynamically provisioned — these are especially useful when you want to work with StatefulSets objects.</p><h4><strong>Kubernetes Volume Syntax</strong></h4><p>Remember,</p><ul><li>K8s volumes do not have independent existence — tightly coupled with the life of the Pod. Hence, they are defined as part of your pod spec.</li><li>You can have multiple K8s volume objects defined inside a Pod</li><li>The same K8s volume object can be mounted inside multiple containers in a Pod</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: [POD NAME]<br>spec:<br>  volumes:<br>    - [K8s VOL OBJ NAME]<br>      [STORAGE SOLUTION TYPE]<br>        [STORAGE SOLUTION PARAMETERS]<br>    - ....<br>    - ....<br>  containers:<br>    - name: [CONTAINER NAME]<br>      image: [CONATINER IMAGE]<br>      volumeMounts<br>        - name: [ANY K8s VOL OBJ NAME DEFINE ABOVE]<br>          path: [PATH INSIDE THE CONTAINER TO MOUNT THE VOL]<br>    - name: [CONTAINER NAME]<br>      image: [CONATINER IMAGE]<br>      volumeMounts<br>        - name: [ANY K8s VOL OBJ NAME DEFINED ABOVE]<br>          path: [PATH INSIDE THE CONTAINER TO MOUNT THE VOL]<br>    - ...<br>    - ...</pre><p>Example:</p><ul><li>A K8s Volume object with the name shared-data is defined</li><li>Both the containers, <em>first</em> and <em>second</em> mount the same object inside the container. Note that the mount path need not be the same.</li><li>Container <em>second</em> is manipulating a file in the mount path which will be available in the container <em>first</em> since they are sharing the same K8s volume object.</li><li>Here the physical storage solution used is <strong><em>emptyDir </em></strong>— which is an ephemeral storage solution.</li></ul><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: two-containers<br>  labels:<br>    app: two<br>spec:<br><strong>  volumes:<br>  - name: shared-data<br>    emptyDir: {}</strong><br>  containers:<br>  - name: first<br>    image: nginx<br>    ports:<br>      - containerPort: 80<br><strong>    volumeMounts:<br>      - name: shared-data<br>        mountPath: /usr/share/nginx/html</strong><br>  - name: second<br>    image: debian<br>    volumeMounts:<br><strong>    - name: shared-data<br>      mountPath: /pod-data</strong><br>    command: [&quot;/bin/sh&quot;]<br>    args:<br>      - &quot;-c&quot;<br>      - &gt;<br>        while true; do<br>          date &gt;&gt; /pod-data/index.html;<br>          echo Hello from the second container more &gt;&gt; /pod-data/index.html;<br>          sleep 20;<br>        done</pre><h4><strong>Kubernetes Persistent Volume Syntax</strong></h4><p>Remembering the break down that we mentioned before, these are the steps to use a PV.</p><p><strong>Step 1: Define the Kubernetes Persistent Volume Object<br></strong>This is where you define the cluster object and the physical storage that backs the object. Every Kubernetes PV object defines these 4 attributes:</p><ul><li><strong>Capacity:</strong> What is the size of the volume object. This size is defined in gigibytes (Gi) by default.</li><li><a href="https://unofficial-kubernetes.readthedocs.io/en/latest/concepts/storage/persistent-volumes/"><strong>AccessModes</strong></a><strong>:</strong> Describes how the object can be accessed by the nodes — ReadWriteOnce, ReadWriteMany, ReadOnlyMany. This depends on the underlying storage solution too. For example, NFS can support multiple read/write, but a specific NFS volume object can be defined as read-only.</li><li><strong>StorageClassName:</strong> What type of physical storage are you using and which class should K8s use to access the physical storage</li><li><strong>Additional storage parameters:</strong> any values needed for the physical storage type</li></ul><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: [OBJECT NAME]<br>spec:<br>  storageClassName: [PHYSICAL STORAGE NAME]<br>  capacity:<br>    storage: [SIZE IN GiGiBytes (by default)]<br>  accessModes:<br>    - [ACCESS MODE; ReadWriteOnce/ReadOnlyMany/ReadWriteMany]<br>  [PHYSICAL STORAGE PARAMETERS]</pre><p><strong>Step 2: Define the Kubernetes Persistent Volume Claim Object</strong><br>Once the volume objects are ready, we need to describe the type of volume our application needs. For this we create a PVC object. The PVC object describes the StorageClassName, AccessMode and Capacity needed for our application. Kubernetes will then search for a PV object that matches this claim and attaches it.</p><p>A point to note here is, the StorageClassName and AccessMode have to be an exact match but, the Capacity can be equal to or greater. So, if a 1 Gi object isn’t available it will search for the next higher object (≥ 1Gi).</p><pre>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: [OBJECT NAME]<br>  labels:<br>    type: local<br>spec:<br>  storageClassName: [PHYSICAL STORAGE YOU NEED]<br>  accessModes:<br>    - [ACCESS MODE YOU NEED]<br>  resources:<br>    requests:<br>      storage: [SIZE YOU NEED IN Gigi Bytes (by default)]</pre><p><strong>Step 3: Use the Volume Claim object to create a Kubernetes Volume object in the Pod and mount it into the containers<br></strong>Like mentioned before, only Kubernetes Volume objects can be mounted inside a container. So,</p><ul><li>first, you define a Kubernetes Volume in the Pod backed by the PVC</li><li>then, you mount it inside the container as usual</li></ul><p>Remember, the rules for Kubernetes Volumes apply here too — you can mount this same Kubernetes Volume object inside multiple containers in the Pod.</p><pre>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: [POD NAME]<br>spec:<br>  volumes:<br>    - [K8s VOL OBJ NAME]<br>      persistentVolumeClaim:<br>        claimName: [PVC OBJ NAME]<br>    - ....<br>    - ....<br>  containers:<br>    - name: [CONTAINER NAME]<br>      image: [CONATINER IMAGE]<br>      volumeMounts<br>        - name: [K8s VOL OBJ NAME]<br>          path: [PATH INSIDE THE CONTAINER TO MOUNT THE VOL]<br>    - ...<br>    - ...</pre><p>Example:</p><ul><li>PV object named <em>pv-volume</em> is created. Physical storage solution is a folder on the host (<em>/mnt/data</em>) hence, the access mode is ReadWriteOnce (i.e., only 1 node can use it as ReadWrite)</li><li>PVC object name <em>pv-volume-claim</em> is created — the capacity requirement is slightly lesser than the available pv object. Hence, a successful match will happen.</li><li>The same PVC is connected to 2 pods — <em>task-pv-pod </em>and<em> task-pv-pod2</em> — via Kubernetes Volume objects defined in the Pod spec (called <em>pv-storage</em> and <em>pv-storage2</em> respectively)</li><li>This Kubernetes volume object is then mounted inside the container.</li></ul><pre>apiVersion: v1<br>kind: PersistentVolume<br>metadata:<br>  name: pv-volume<br>  labels:<br>    type: local<br>spec:<br>  storageClassName: manual<br>  capacity:<br>    storage: 2Gi<br>  accessModes:<br>    - ReadWriteOnce<br>  hostPath:<br>    path: &quot;/mnt/data&quot;</pre><pre>---<br>apiVersion: v1<br>kind: PersistentVolumeClaim<br>metadata:<br>  name: pv-volume-claim<br>  labels:<br>    type: local<br>spec:<br>  storageClassName: manual<br>  accessModes:<br>    - ReadWriteOnce<br>  resources:<br>    requests:<br>      storage: 1Gi</pre><pre>---<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: task-pv-pod<br>spec:<br>  volumes:<br>    - name: pv-storage<br>      persistentVolumeClaim:<br>        claimName: pv-volume-claim<br>  containers:<br>    - name: pv-container<br>      image: nginx<br>      ports:<br>        - containerPort: 80<br>      volumeMounts:<br>        - name: pv-storage<br>          mountPath: &quot;/usr/share/nginx/html&quot;</pre><pre>---<br>apiVersion: v1<br>kind: Pod<br>metadata:<br>  name: task-pv-pod2<br>spec:<br>  volumes:<br>    - name: pv-storage2<br>      persistentVolumeClaim:<br>        claimName: pv-volume-claim<br>  containers:<br>    - name: pv-container2<br>      image: nginx<br>      ports:<br>        - containerPort: 80<br>      volumeMounts:<br>        - mountPath: &quot;/usr/share/nginx/html&quot;<br>          name: pv-storage2</pre><h3>Putting it all together!</h3><p>The easiest way to plan volumes in Kubernetes is by following these steps:</p><ul><li>Why do you need the volume in the application?</li><li>How do you want the actual data to persist?</li><li>Which Physical Storage solution will match the above requirements?</li><li>Create a cluster object backed by the physical storage</li><li>Mount the object in the containers of the Pod</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/0*Piks8Tu6xUYpF4DU" /></figure><p>👋 <a href="https://faun.dev/join"><strong>Join FAUN today and receive similar stories each week in your inbox!</strong></a><strong> </strong>️ <strong>Get your weekly dose of the must-read tech stories, news, and tutorials.</strong></p><p><strong>Follow us on </strong><a href="https://twitter.com/joinfaun"><strong>Twitter</strong></a><strong> </strong>🐦<strong> and </strong><a href="https://www.facebook.com/faun.dev/"><strong>Facebook</strong></a><strong> </strong>👥<strong> and </strong><a href="https://instagram.com/fauncommunity/"><strong>Instagram</strong></a><strong> </strong>📷 <strong>and join our </strong><a href="https://www.facebook.com/groups/364904580892967/"><strong>Facebook</strong></a><strong> and </strong><a href="https://www.linkedin.com/company/faundev"><strong>Linkedin</strong></a><strong> Groups </strong>💬</p><figure><a href="https://www.faun.dev/join?utm_source=medium.com/faun&amp;utm_medium=medium&amp;utm_campaign=faunmediumbanner"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_cT0_laE4iPcqW1qrbstAg.gif" /></a></figure><h4>If this post was helpful, please click the clap 👏 button below a few times to show your support for the author! ⬇</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=226da3b55753" width="1" height="1" alt=""><hr><p><a href="https://faun.pub/kubernetes-fundamentals-volumes-226da3b55753">Kubernetes Fundamentals: Volumes</a> was originally published in <a href="https://faun.pub/">FAUN.dev() 🐾</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner Fundamentals: Push & Pull Configuration Management Tools]]></title>
            <link>https://gayatrisajith.medium.com/beginner-fundamentals-push-pull-configuration-management-tools-85eff1b41447?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/85eff1b41447</guid>
            <category><![CDATA[configuration-management]]></category>
            <category><![CDATA[beginners-guide]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[puppet]]></category>
            <category><![CDATA[ansible]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Tue, 03 Sep 2019 17:07:49 GMT</pubDate>
            <atom:updated>2019-09-03T17:07:49.292Z</atom:updated>
            <content:encoded><![CDATA[<p>Once you understand the need and advantages of a configuration management tool, the first thing you will hear is pull or push based configuration management tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-chzBHbzBA1BbBQo7a-q3w.png" /><figcaption>Important to understand the advantages of Push &amp; Pull Configuration Management</figcaption></figure><h3>General architecture of a configuration management tool</h3><p>Every configuration management tool will have a machine where the configuration data is stored and some machines (nodes) whose configuration needs to be maintained. How the nodes get configuration from the main server depends on the type of configuration management tool used.</p><h3>Pull Based Configuration Management Tool</h3><p>In this type of configuration management tool, the nodes pull the configuration information from the server (hence, the name).</p><p>A small software (called agent or client) is installed on every node. This agent/client will:</p><ul><li>at regular intervals, get the configuration from the server</li><li>compare the configuration received from the server with the current configuration of the node</li><li>if there is any mis-match, take the steps required to match the configuration of the node with the configuration received from the server.</li></ul><p>This means that, its always the agent/client that initiates communication, not the main server.</p><p>Chef &amp; Puppet are good examples of such configuration management tools.</p><h3>Push Based Configuration Management Tool</h3><p>In this type of configuration management tool, the main server (where the configuration data is stored) pushes the configuration to the node (hence, the name). So, it is the main server that initiates communication, not the nodes. Which means that an agent/client may or may not be installed on each node.</p><p>Ansible is an example of a push based configuration management tool that doesn’t need an agent to be installed on the nodes. SaltStack is an example of a push based configuration management tool that needs an agent (minion) to be installed on the nodes. In both cases, its the main server that starts the communication and sends the configuration data to the nodes without the nodes asking for it.</p><h3>Push vs Pull — Which one to choose?</h3><p>Remember, both types of configuration management tools can do it all. So, the following comparison is based on the default features. I am not highlighting the disadvantages since, it should be pretty clear from the list of advantages and, frankly speaking, most of these “disadvantages” can be worked around.</p><h4>Advantages of Push based Configuration Management</h4><ul><li><strong>Control over the entire system: </strong>Since the main server (where you store the configuration information) pushes the configuration to the nodes, you have more control over what nodes need to be configured, the actions are more synchronous and error handling becomes much easier since you can immediately see &amp; correct the issues.</li><li><strong>Simpler to use: </strong>Push configuration management tools, like Ansible, are generally much easier to setup and get started. Also, since nodes do not pull any information from the main server, development is more straight forward as you can easily test your scripts without worrying about any node picking it up accidentally or changing any settings on the agents.</li></ul><h4>Advantages of Pull based Configuration Management</h4><ul><li><strong>Easier to bootstrap new nodes:</strong> As soon as a node is ready, agent/client that runs on the node can start pulling configuration from the main server. This means that a new machine configured automatically, when the server is ready to be configured (unlike push method where you have to check if the node is ready to be configured).</li><li><strong>Easier scalability: </strong>Since the nodes can be bootstrapped automatically and independent of other nodes, it means that scaling such a configuration is much easier.</li></ul><p>In summary, which tool should you use? The answer depends on what your fundamental need is and how much customisation are you willing to do. <br>A largely static infrastructure will benefit more from Push Based Configuration Management, while an extremely dynamic infrastructure will find Pull Based Configuration more suitable. <br>You could also use a combination of the two — use Pull for initial configuration setup and Push for application deployment.</p><p>Once you understand the advantages, the possibilities are endless.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85eff1b41447" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kubernetes Fundamentals: Common Terms]]></title>
            <link>https://gayatrisajith.medium.com/kubernetes-fundamentals-common-terms-4cc63bb4718d?source=rss-154641947ae6------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cc63bb4718d</guid>
            <category><![CDATA[kubernetes-beginner]]></category>
            <category><![CDATA[kubernetes-common-terms]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <category><![CDATA[kubernetes-fundamentals]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Gayatri S Ajith]]></dc:creator>
            <pubDate>Wed, 28 Aug 2019 10:47:17 GMT</pubDate>
            <atom:updated>2019-08-28T11:03:20.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NSwsVr-Mro8j_LcmMXT7uQ.png" /><figcaption>Container Orchestration with Kubernetes</figcaption></figure><p>Simply put, <a href="https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/">Kubernetes is a Container Orchestration tool</a>. This means that, with Kubernetes you don’t worry about the container — where they are created, keeping them alive, how to talk to them and so on. You think only in terms of services needed for your application. This makes application design, deployment &amp; scaling much easier.</p><p>Also with Kubernetes, the distinction between the Kubernetes cluster setup team &amp; Kubernetes configuration (the team that uses the Kubernetes cluster)becomes distinctly separate. No overlapping or grey areas. The expertise needed to setup a cluster is different from the expertise needed to use it.</p><p>Getting started with using Kubernetes is pretty easy provided you have a few fundamental terms clear. These terms can seem a little confusing at first because there are not many tools with similar concepts.</p><p>So, lets start understanding the common fundamental terms in simple language.</p><h3>Cluster</h3><ul><li>Its simply a collection of machines (also called nodes)</li><li>Every cluster will have some nodes that will work as master and some that work as worker nodes</li><li>Kubernetes recommends 3 masters per cluster</li><li>The short form for Kubernetes is K8S (8 alphabets between K and S hence, K8S)</li></ul><h3>Pod</h3><ul><li>Smallest unit that can be managed in Kubernetes</li><li>One pod can have 1 or more containers in it</li><li>1 pod should have only one purpose</li><li>Containers in a pod will be created on the same node on which the pod exists. This means that, if a Pod has 3 containers and the Pod is created on node1 then, all 3 containers of that Pod will be on node1 too</li><li>Containers in a pod will share resources of the node (since, they are always created on the same node)</li><li>Every Pod is assigned a Virtual IP within the cluster</li><li>By default, the ports exposed by the containers in the Pod are the ports exposed by the Pod</li><li><em>Pods are mortal. Never depend on the life of a Pod.</em></li></ul><h3>Deployment</h3><ul><li>Used by kubernetes to manage pods — scaling pods, restarting and so on</li></ul><h3>Replication Controller/Replica Set</h3><ul><li>Used by deployments to maintain the required number (that is, replicas) of a pod.</li><li>Its job is to ensure that the required replicas of a pods are always running (remember, in k8s you never talk in terms of containers — only in terms of pods)</li><li><em>Every time you create a deployment, a replica set is created for it</em></li><li>Originally, in Kubernetes there was only Replication Controller. Now, its being replaced by Replica Sets.</li><li>Replica Set and Replication Controller do almost the same thing — ensure that the specified replicas of a pod are running.</li><li>The main difference between Replication Controller &amp; Replica Set is that Replica Set supports “set based selectors” too [e.g. environment in (prod, test)] , while Replication Controller supports only “equality based selectors” [e.g. environment = prod]</li><li><em>Kubernetes uses deployments to manage pods; deployments use replica sets to maintain the number of replicas of a pod</em></li></ul><h3>Labels and Selectors</h3><ul><li>Labels are key-value pairs used to tag objects</li><li>Objects are the items that you create in a Kubernetes cluster (pods, deployments, replica sets, services, volumes etc)</li><li>Selectors are used to collect objects based on tags</li></ul><h3>Service</h3><ul><li>Allows clients to connect to Pods (remember, you don’t talk in terms of containers)</li><li>It behaves like an abstraction over Pods</li><li>Every service in Kubernetes is assigned a Virtual IP inside the cluster. This Virtual IP can be used only from inside the cluster</li><li>Pods are mortal — services ensure that clients are can connect to pods reliably always.</li><li><em>Services use collectors to decide which Pods to route traffic to — collecting Pods with matching labels.</em></li></ul><h3>Main Service Types</h3><h4>Cluster IP</h4><ul><li>Only has a Virtual IP (also called Cluster IP)</li><li><em>This service can be used within a cluster only</em></li><li>Acts like a traffic router to your Pods inside the cluster</li><li>Each port exposed by a pod will need a service if you want a client to talk to it via that port.</li><li>By default, the service port is the same as the port exposed by the Pod.</li><li><strong>Different methods to access this service:</strong></li><li>From any node inside the cluster: &lt;cluster IP&gt;:&lt;service port&gt;</li><li>From the node where a replica of the Pod is running: &lt;pod IP&gt;:&lt;pod port&gt;</li></ul><h4>Node Port</h4><ul><li>For this service, a physical port on the node is mapped to the service port and the service connects to the Pod via the pod port</li><li>Remember, this will also have a Virtual IP (i.e. cluster IP)</li><li><strong>Different methods to access this service:</strong></li><li>From outside the cluster, if any node in the cluster has a public IP: &lt;node public IP&gt;:&lt;node port&gt;</li><li>From any node inside the cluster: &lt;cluster IP&gt;:&lt;service port&gt;</li><li>From the node where a replica of the Pod is running: &lt;pod IP&gt;:&lt;pod port&gt;</li></ul><h4>Load Balancer</h4><ul><li>Giving public access to a node in your cluster is not a recommended method</li><li><em>When you want to give public access to a service, create a load balancer service </em>(not getting into ingress at this stage)</li><li>For each service that you want to give public access, you need to create a load balancer service</li><li>This type of service will generally work only in a cloud environment</li><li>Remember, this will also have a Virtual IP (i.e. cluster IP)</li><li>This service will have a node port too</li><li><strong>Different methods to access this service:</strong></li><li>From outside the cluster:&lt;load balancer dns&gt;:&lt;service port&gt;</li><li>From outside the cluster, if any node in the cluster has a public IP: &lt;node public IP&gt;:&lt;node port&gt;</li><li>From any node inside the cluster: &lt;cluster IP&gt;:&lt;service port&gt;</li><li>From the node where a replica of the Pod is running: &lt;pod IP&gt;:&lt;pod port&gt;</li></ul><p>Of course, in no way is this a complete list of terms in Kubernetes but, this should give you a head start in using the tool.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cc63bb4718d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>