<?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 Muhammad Imtiaz on Medium]]></title>
        <description><![CDATA[Stories by Muhammad Imtiaz on Medium]]></description>
        <link>https://medium.com/@imtiaz9832?source=rss-12ea94d2da7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4rbYL25bba78AjgXdySsvg.jpeg</url>
            <title>Stories by Muhammad Imtiaz on Medium</title>
            <link>https://medium.com/@imtiaz9832?source=rss-12ea94d2da7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 14:22:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@imtiaz9832/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[Sharing RDS Snapshots Across AWS Accounts]]></title>
            <link>https://medium.com/@imtiaz9832/sharing-rds-snapshots-across-aws-accounts-a4c8fa6d4156?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a4c8fa6d4156</guid>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Tue, 10 Dec 2024 11:06:28 GMT</pubDate>
            <atom:updated>2024-12-10T11:06:28.816Z</atom:updated>
            <content:encoded><![CDATA[<h3>Sharing RDS Snapshots Across Accounts Like a Pro!</h3><p>When working with AWS, you might encounter scenarios where you need to share RDS snapshots across accounts and regions — for instance, during cross-account migrations or disaster recovery setups. This blog outlines a practical solution to achieve this, covering the nuances of encryption, snapshot sharing, and re-encryption.</p><p>Follow the steps below to share encrypted RDS snapshots across accounts:</p><h4>1. Create a Snapshot</h4><p>Log in to the AWS <em>source account</em> and navigate to RDS. Select the DB instance, and click on <strong>Take DB Snapshot</strong>, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-_0dt5pV3RkuyUa0Ilagrg.png" /><figcaption>Taking DB Snapshot</figcaption></figure><blockquote><em>Once you create the snapshot, It will appear under </em><strong><em>Manual Snapshots</em></strong><em>.</em></blockquote><h4>2. Encrypt Snapshot using CMK</h4><p>It is important to note that <strong><em>“Snapshots encrypted with AWS-managed keys cannot be shared across accounts.</em></strong>” To enable sharing across accounts, it must be re-encrypted with a customer-managed key (CMK).</p><p>a. Go to the KMS in the source account and create a CMK with the following configs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yPuFck9rJXwMeiZK7-9s3w.png" /><figcaption>CMK Creation</figcaption></figure><p>b. Enable <strong>multi-Region Key </strong>for cross-region sharing (Optional).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y8jDu57Z9e9eopbCqfjMtA.png" /><figcaption>Regionality</figcaption></figure><p>c. Click on CMK, and Share it with <strong>Other AWS Account</strong>, as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYLb37lJz1522kh5iyVIvw.png" /><figcaption>Sharing CMK with other AWS account</figcaption></figure><p><em>Note: Please note that the CMK will not appear in the target account. If encryption is required in the target account, you’ll need to use the CMK’s ARN from the source account.</em></p><p>d. <strong>Copy the Snapshot </strong>and encrypt it using the CMK in the source account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*syprkldhMuKeh-o7W4H0jg.png" /><figcaption>Re-encrypting snapshot using CMK</figcaption></figure><p><em>After creating the encrypted snapshot using CMK, you can share it with other AWS account or region.</em></p><h4>3. Share the Snapshot across Region (Optional)</h4><p>If your original RDS snapshot is in one region (e.g. us-east-1) in the source account, and you want to share RDS snapshot to another region (e.g. us-east-2) in the target account, you must copy it in another region either in the source account or in the target account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_7XdB-KL_g1bwWjCx58DUQ.png" /><figcaption>Copying Snapshot in other region</figcaption></figure><h4>4. Share the Snapshot with the Target Account</h4><p>Select the snapshot, and click on <strong>Share snapshot</strong> with the target account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C94Z1mHcrmLXcsK1ln73Iw.png" /><figcaption>Sharing Snapshot with Target Region</figcaption></figure><p><em>Note: The shared snapshot will appear under the </em><strong><em>Shared with Me</em></strong><em> tab in the target account.</em></p><h4>5. Re-Encrypt the Snapshot in the Target Account</h4><p><em>You cannot directly spin up a database instance from a shared snapshot in the target account. Instead, </em><strong><em>you must re-encrypt it</em></strong><em> using</em><strong><em> </em></strong><em>either</em><strong><em> </em></strong><em>an AWS-managed key or a newly created CMK in the target account.</em></p><p>Click on <strong>Copy snapshot, </strong>and re-encrypt it with AWS managed key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WFLhVqfartr_Gdu3YEUI9Q.png" /><figcaption>Re-encrypting the snapshot in target account</figcaption></figure><h4>6. Restore the Snapshot in the Target Account</h4><p>Finally, restore the snapshot in the target account to create a new RDS instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q9pXPAzDz_pIQST6P_jB-g.png" /><figcaption>Restoring DB instance from Snapshot</figcaption></figure><h3>Conclusion</h3><p>By following these steps, you can securely and efficiently share RDS snapshots across AWS accounts and regions, addressing encryption challenges and streamlining your workflows.</p><p>Thanks for reading this blog — I hope it helps! If you use different strategies or have additional tips for cross-account sharing? Share your insights in the comments below! Happy reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a4c8fa6d4156" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing EKS Cluster with SSO User]]></title>
            <link>https://medium.com/emumba/accessing-eks-cluster-with-sso-user-2c9d9da246ec?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c9d9da246ec</guid>
            <category><![CDATA[eks-and-sso]]></category>
            <category><![CDATA[eks-cluster-via-sso-user]]></category>
            <category><![CDATA[kubernetes-security]]></category>
            <category><![CDATA[sso-with-aws]]></category>
            <category><![CDATA[eks-cluster-access]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Mon, 26 Aug 2024 05:56:31 GMT</pubDate>
            <atom:updated>2024-09-09T09:23:46.250Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to leverage SSO users for EKS cluster access via Kubectl? The duration of session validity and the steps required to refresh the session when it expires?</h4><p><strong>SSO (Single Sign-On)</strong> allows users to access multiple applications/cloud services with a <strong>single set of credentials</strong>, streamlining authentication and enhancing security. When applied to EKS clusters, SSO centralizes access control, reducing the risks associated with static credentials. Integrating SSO with EKS not only strengthens security but also enhances operational efficiency.</p><h4>So What’s the Problem 🤔?</h4><p>However, accessing EKS clusters viakubectl through SSO user entails additional complexity than using the traditional method( IAM User). In this blog, we&#39;ll explore:</p><ul><li><em>How to leverage SSO users for EKS cluster access via Kubectl?</em></li><li><em>The duration of session validity?</em></li><li><em>Steps required to refresh the session when it expires?</em></li></ul><h3>Prerequisites</h3><ul><li>Make sure you are logged into the SSO account.</li><li>You should have access to the AWS account via SSO User.</li><li><strong>AWS CLI</strong> <strong>&amp;</strong> <strong>Kubectl</strong> are installed on your machine.</li></ul><h4>1. Set Up AWS CLI</h4><p>Use the following commands to install AWS CLI on your machine.</p><pre>curl &quot;https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip&quot; -o &quot;awscliv2.zip&quot;<br>unzip awscliv2.zip<br>sudo ./aws/install</pre><p>Check the AWS CLI version</p><pre>aws --version</pre><h4>2. Set Up Kubectl</h4><p>Use the following command to install <strong>kubectl</strong> on your machine.</p><pre>sudo apt-get update<br>sudo apt-get install -y apt-transport-https ca-certificates curl<br>sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg<br>echo &quot;deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main&quot; | sudo tee /etc/apt/sources.list.d/kubernetes.list<br>sudo apt-get update<br>sudo apt-get install -y kubectl</pre><p>Check the <strong>kubectl </strong>version.</p><pre>kubectl version</pre><p>Create <strong>.kube </strong>directory, used to store <strong>kubeconfig</strong> file of the cluster.</p><pre>mkdir -p ~/.kube</pre><p>Once you’ve met all the prerequisites, It’s time to set up an SSO profile, and access EKS clusters …!</p><h3>Setting up SSO Profile via AWS CLI</h3><p>Create an SSO profile using the following AWS command.</p><pre>aws configure sso</pre><p>It will prompt for the following inputs:</p><pre>SSO session name (Recommended): imtiaz-sso<br>SSO start URL [None]: &lt;sso-url&gt;<br>SSO region [None]: us-east-1<br>SSO registration scopes: [sso:account:access]:</pre><ul><li><strong>SSO Session name</strong>: Put the name whatever you want, I used imtiaz-sso</li><li><strong>SSO Start URL:<em> </em></strong>Put SSO URL<em>.</em></li><li><strong>SSO region:<em> </em></strong>us-east-1</li><li><strong>SSO registration scopes</strong>: Press enter to go with the default SSO registration scopes</li></ul><blockquote><strong><em>Note: </em></strong>Remember the session name used above, as this will be reused.</blockquote><p>Once you press enter, it will show the following output on your terminal [right image], and also redirect you to the browser [left image].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cS-b4O2LVljvGKH4wIyqFw.png" /></figure><ul><li>You should see the same code on the terminal &amp; browser.</li><li>Confirm &amp; Continue.</li></ul><p>It will show a pop-up in the browser, as shown below. Click on <strong>Allow</strong>[right image].<strong> </strong>You’ll see the success message[left image]!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzdJxCNfbpTvGJzjPN55QA.png" /></figure><p>Once this is done, get back to the terminal and complete the required configurations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*knjzLqBNkdYmtPrle3OJzg.png" /></figure><ul><li>Use your CLI default region, in my case it is us-east-2</li><li>Use json as the default output format</li><li>Give the CLI profile name, whatever you want, <em>but as a best practice give it the same as the </em><strong>SSO Session name.</strong></li><li>Confirm that you can access buckets using the <strong>profile name<em>.</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*dxZ4RB8whmiIMuuX6AHVhA.png" /></figure><p>Yay.. you’re all done from the setup side.</p><h4>Build an ARN version of SSO USER</h4><p>Run the following command to build an ARN</p><blockquote>Make sure to use the <em>--profile</em> with the name you’ve set before.</blockquote><pre>ssorole=$(aws sts get-caller-identity --query Arn --output text --profile imtiaz-sso | cut -d/ -f2)<br>account=$(aws sts get-caller-identity --query Account --output text --profile  imtiaz-sso)<br>echo &quot;arn:aws:iam::$account:role/$ssorole&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZB88FkEpVoJ3DRj6hhBvQ.png" /></figure><p>This will output an ARN against your SSO user, something like this, as shown below</p><pre>arn:aws:iam::&lt;account-id&gt;/role/AWSReservedSSO_PowerUserAccess_3dde4585cb3da811</pre><p><strong>NOTE:</strong> <em>Provide the ARN to the </em><strong><em>Cluster Administrator</em></strong><em> to whitelist this SSO user in the EKS cluster.</em></p><h4>Accessing EKS clusters via SSO User</h4><p>Once your cluster administrator has whitelisted your SSO profile, you’re now ready to grab the <strong>EKS cluster’s kubeconfig</strong> file.</p><pre>aws eks update-kubeconfig --kubeconfig ~/.kube/&lt;cluster-name&gt; --profile &lt;imtiaz-sso&gt; --region &lt;region&gt; --name &lt;cluster-name&gt;</pre><ul><li>Make sure to use --profile with the name you’ve set before.</li><li>You can use any path &amp; file name --kubeconfig ~/.kube/&lt;kubeconfig-name&gt; to download the <strong>kubeconfig</strong> file.</li></ul><blockquote>After a successful run, It should create a <strong>config </strong>file inside <strong>~/.kube </strong>directory</blockquote><p>Activate the<strong> EKS configuration file </strong>and get the resources.</p><pre>export KUBECONFIG=~/.kube/&lt;kubeconfig-name&gt;</pre><p>Run the following command to confirm, if you have access to the EKS cluster.</p><pre>kubectl get pods</pre><blockquote><strong><em>NOTE:</em></strong> SSO credentials are short-lived and are valid for <strong>12 hours at max.</strong></blockquote><p>Since <em>Sign-On (SSO) users&#39; credentials are short-lived, hence </em>we need to renew access to the EKS cluster by following the outlined process.</p><h3>Renew Access to EKS Cluster</h3><p>When the token expires, you’ll see the following error message on either the terminal or on Lens ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*aRS4X2vFEhPcOZUnbQgyxA.png" /></figure><p>To renew access to the EKS cluster, follow the steps mentioned at <a href="https://cdpaas.atlassian.net/wiki/spaces/DEVOPS/pages/345145345/Accessing+EKS+clusters+via+SSO+Users#Setting-up-SSO-Profile-via-AWS-CLI">[Setting up SSO Profile via AWS CLI]</a>.</p><ul><li>Use the same <strong>Session &amp; Profile</strong> name that you’ve used while setting it up for the first time. Otherwise, you’ll lose the access to the EKS cluster.</li><li>For the 2nd time, when you run the following command, it will show the <strong>session information</strong> at the end of the terminal, as shown below.</li><li>Press enter, and complete the remaining steps describe above.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*OJYfbklH49-uGneqbXptvQ.png" /></figure><p>That’s all! 👏 🎉 I’d love to hear your feedback on this solution. Feel free to ask any questions or share your suggestions about the post.</p><p>Happy learning! 😊</p><h3>References</h3><ul><li><a href="https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html">https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html</a></li><li><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-native-package-management">https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/#install-using-native-package-management</a></li><li><a href="https://repost.aws/knowledge-center/eks-configure-sso-user">https://repost.aws/knowledge-center/eks-configure-sso-user</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c9d9da246ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/accessing-eks-cluster-with-sso-user-2c9d9da246ec">Accessing EKS Cluster with SSO User</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Edge Stack High Availability & Scalability in Kubernetes]]></title>
            <link>https://medium.com/@imtiaz9832/edge-stack-high-availability-scalability-in-kubernetes-a836c6e367cc?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a836c6e367cc</guid>
            <category><![CDATA[edgestack-scaling]]></category>
            <category><![CDATA[edge-stack-ha]]></category>
            <category><![CDATA[edge-stack-scaling]]></category>
            <category><![CDATA[ambassador-edge-stack]]></category>
            <category><![CDATA[ambassdor-in-k8s]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Sat, 24 Aug 2024 19:17:22 GMT</pubDate>
            <atom:updated>2024-09-08T16:36:15.686Z</atom:updated>
            <content:encoded><![CDATA[<h4>What is Edge Stack and what is it used for? Why HA &amp; scaling is important? How to run it in HA mode?</h4><p>Edge Stack is a key tool for managing and securing the edge of cloud-native applications. It serves as an <strong><em>ingress controller and API gateway</em></strong>, providing essential features like <strong>SSL termination, authentication, and load balancing</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m8_6lYO1-6leJ_PDpEW5Dg.png" /><figcaption>Image taken from Edge-stack Documentation</figcaption></figure><p>Ensuring high availability (HA) for Edge Stack is crucial, as it guarantees <strong><em>uninterrupted access to services, enhances resilience against failures, and supports consistent performance even under high traffic.</em></strong> By implementing HA, we avoid <em>single points of failure</em> and maintain reliable, secure communication between your microservices and external clients.</p><h4>Stateless Architecture — Explaining Scaling and Availability</h4><p>Ambassador Edge Stack operates on a <strong>Stateless Architecture</strong>, where each instance functions independently of others. This design allows it to avoid the complexities of maintaining a centralized, highly available control plane.</p><p>It leverages <strong>Kubernetes for scaling, high availability, and persistence</strong>. The configurations are stored directly in Kubernetes, eliminating the need for an external database.</p><blockquote>It is packaged as a single container with both the control plane and Envoy Proxy. It is deployed as a k8s <strong>deployment</strong>, making it easy to scale and manage alongside other deployments.</blockquote><h3>Edge Stack HA Implementation</h3><ol><li>Set up edge-stack deployment to run with 2 replicas.</li></ol><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: edge-stack<br>  namespace: ambassador<br>  labels:<br>    app.kubernetes.io/instance: edge-stack<br>    app.kubernetes.io/name: edge-stack<br>spec:<br>  replicas: 2</pre><p>2. Set up <strong>podAntiAffinity</strong> to enforce the scheduling of pods to run on different nodes.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: edge-stack<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec:<br>    podAntiAffinity:<br>        preferredDuringSchedulingIgnoredDuringExecution:<br>        - weight: 100<br>          podAffinityTerm:<br>            labelSelector:<br>              matchExpressions:<br>              - key: app<br>                operator: In<br>                values:<br>                - edge-stack<br>            topologyKey: kubernetes.io/hostname</pre><p>3. Optionally, add <strong>nodeAffinity </strong>to schedule the pods on dedicated nodes.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: edge-stack<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec: <br>    affinity:<br>      nodeAffinity:<br>        requiredDuringSchedulingIgnoredDuringExecution:<br>          nodeSelectorTerms:<br>            - matchExpressions:<br>                - key: dedicated<br>                  operator: In<br>                  values:<br>                    - edge-stack</pre><p>4. Enable Readiness &amp; Liveness probes</p><ul><li><strong>Readiness Probe:</strong> <em>Ensures a container is ready to serve traffic. If it fails, traffic is paused.</em></li><li><strong>Liveness Probe:</strong> <em>Checks if a container is alive. If it fails, K8s restarts it.</em></li></ul><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: edge-stack<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec:<br>    containers:<br>      - name: emissary-ingress<br>        image: docker.io/datawire/aes:2.2.1<br>        ... // additional configs truncated<br>        readinessProbe:<br>          httpGet:<br>            path: /ambassador/v0/check_ready<br>            port: admin<br>            scheme: HTTP<br>          initialDelaySeconds: 30<br>          timeoutSeconds: 1<br>          periodSeconds: 3<br>          successThreshold: 1<br>          failureThreshold: 3<br>        livenessProbe:<br>          httpGet:<br>            path: /ambassador/v0/check_alive<br>            port: admin<br>            scheme: HTTP<br>          initialDelaySeconds: 30<br>          timeoutSeconds: 1<br>          periodSeconds: 3<br>          successThreshold: 1<br>          failureThreshold: 3</pre><p>After making the changes in deployment, let’s apply it to the k8s cluster.</p><pre>kubectl apply -f edgestack-deployment.yaml</pre><h3>Verification of edge-stack HA</h3><p>1.You should see the two pods running in the k8s cluster</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/981/1*0lV-P_Mlk-9kGDSi67R_Yg.png" /></figure><p>2.Make sure to schedule them on different nodes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NFFR54EGBnKRDqrjs3__Ng.png" /></figure><p>3.Verify if Readiness &amp; liveness probes are also enabled.</p><p>Once you’ve implemented the changes, Edge Stack should continue to handle your requests seamlessly, even if some pods go down or are not running.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>That’s a wrap! 👏 🎉 I’d love to hear your feedback on this solution. Feel free to ask any questions or share your suggestions about the post.</p><p>Happy learning! 😊</p><h3>References</h3><ul><li><a href="https://www.getambassador.io/docs/edge-stack/latest/topics/concepts/architecture#scaling-and-availability">https://www.getambassador.io/docs/edge-stack/latest/topics/concepts/architecture#scaling-and-availability</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a836c6e367cc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak High Availability in Kubernetes: A Comprehensive Guide]]></title>
            <link>https://medium.com/emumba/keycloak-high-availability-in-kubernetes-a-comprehensive-guide-f81f35bcc7d8?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f81f35bcc7d8</guid>
            <category><![CDATA[high-availablity-in-k8s]]></category>
            <category><![CDATA[iam-with-keycloak]]></category>
            <category><![CDATA[keycloak-ha]]></category>
            <category><![CDATA[keycloak-in-k8s]]></category>
            <category><![CDATA[keycloak]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Sat, 24 Aug 2024 15:45:49 GMT</pubDate>
            <atom:updated>2024-09-09T07:35:31.621Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Keycloak</strong> <strong>stands as a prevalent Identity and Access Management (IAM) tool,</strong> frequently embraced by customers for its open-source nature and robust functionalities. It has evolved into an industry standard for clients preferring <em>self-hosted IAM solutions</em> over SaaS alternatives like Okta or Azure AD for their <strong><em>Single Sign-On (SSO)</em></strong> necessities.</p><p>Being a seasoned Kubernetes practitioner, what if we simply adjust the Keycloak deployment to have <strong><em>2 or more replicas</em></strong> to achieve HA? Shouldn’t it be pretty straightforward? — Umm .. Well, the answer is NO!</p><h3>Problem with Just Increasing the replicas?</h3><p>Out of the box, Keycloak isn’t configured to be deployed with <strong><em>multiple replicas</em></strong> in any environment, let alone in a Kubernetes cluster. By default, Keycloak assumes it’s a <strong>Standalone Instance </strong>without any knowledge of other Keycloak instances that may be running around it.</p><blockquote>It uses a <strong><em>backend database</em></strong> that stores user information and data about your organization, and you set Keycloak to pull from it. If an instance of Keycloak (pod) goes down, Kubernetes spins a new one up and it retrieves the information from the database as normal and keeps on going.</blockquote><p>While most data is stored in your backend database, there are a couple of pieces of important data that are stored in an internal<strong> Infinispan Cache </strong>inside each pod, like <strong><em>user</em> <em>authentication sessions</em></strong>. With our load balancer in front, if a user that was already authenticated was somehow directed to the other Keycloak pod, that <strong><em>pod would have no authentication data for them and force them to log in again.</em></strong></p><blockquote><strong><em>Infinispan</em></strong><em> is an open-source in-memory data grid that offers flexible deployment options and robust capabilities for storing, managing, and processing data. It provides a key/value data store that can hold all types of data, from Java objects to plain text, and also distributes your data across elastically scalable clusters to guarantee high availability and fault tolerance, whether you use Infinispan as a volatile cache or a persistent data store.</em></blockquote><h3>Setting up Keycloak High Availability</h3><h4>Multi-site deployments</h4><p>Keycloak supports deployment that consists of multiple Keycloak instances that connect to form<strong> </strong>a<strong> Standalone Cluster </strong><em>(multi-site deployment)</em><strong>, </strong>using its <strong>embedded Infinispan Cache; </strong>loadbalancer can distribute the load evenly across those instances. Those setups are intended for a transparent network on a single site, but it entails an additional effort in tailoring deployments to achieve HA.</p><h4>Deployment, Data storage, and Caching</h4><p>Two independent Keycloak instances running on different sites are connected with a low-latency network connection. Users, realms, clients, offline sessions, and other entities are stored in a database that is replicated synchronously across the two sites. The data is also cached in the Keycloak embedded Infinispan as local caches. When the data is changed in one Keycloak instance, that data is updated in the database, and an invalidation message is sent to the other site using the replicated work cache.</p><h4><strong>Architecture Diagram</strong></h4><p>Following is an architecture diagram to explain the setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*Vaa13xMn-7QhbcvwrfS3MQ.png" /></figure><p>Essentially, this setup allows multiple Keycloak instances to be made aware of each other so that the Infinispan Cache can be retrieved and shared by multiple instances of Keycloak. It has multiple ways of doing this:</p><ol><li><strong>DNS_PING</strong></li><li><strong>KUBE_PING</strong></li></ol><p><strong>Keycloak Clustering</strong> is based on the discovery protocols of <a href="http://jgroups.org/">JGroups</a> (Keycloak uses <a href="http://infinispan.org/">Infinispan</a> cache and Infinispan uses JGroups to discover nodes).</p><p>On the Kubernetes cluster, we are going to use <strong>KUBE_PING as JGroups discovery protocol</strong>. These will discover how many containers are running in that namespace. It will get pod details using JGroups properties and it will sync up with each pod and also cache between one container to another using <strong>Infinispan</strong> concepts.</p><h3>Steps to Make Keycloak HA</h3><p>The following steps allow us to make a Keycloak run in HA mode:</p><ul><li>Running Keycloak in Standalone clustered mode[Multi-site deployment]</li><li>Multiple replicas of deployment — to Tolerate pod(s) failure.</li><li>Scheduling of pods on different K8S Nodes</li><li>Enabling Readiness &amp; Liveness probes</li></ul><h3>Implementation</h3><ol><li>Set up Keycloak with 2 replicas.</li></ol><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: keycloak<br>  namespace: dev<br>  labels:<br>    app: keycloak<br>spec:<br>  replicas: 2</pre><p>2. Set up <strong>podAntiAffinity</strong> to enforce the scheduling of pods to run on different nodes.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: keycloak<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec:<br>    podAntiAffinity:<br>        preferredDuringSchedulingIgnoredDuringExecution:<br>        - weight: 100<br>          podAffinityTerm:<br>            labelSelector:<br>              matchExpressions:<br>              - key: app<br>                operator: In<br>                values:<br>                - keycloak<br>            topologyKey: kubernetes.io/hostname</pre><p>3. Optionally, add <strong>nodeAffinity </strong>to schedule the pods on dedicated nodes.</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: keycloak<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec: <br>    affinity:<br>      nodeAffinity:<br>        requiredDuringSchedulingIgnoredDuringExecution:<br>          nodeSelectorTerms:<br>            - matchExpressions:<br>                - key: dedicated<br>                  operator: In<br>                  values:<br>                    - keycloak</pre><p>4. Set the following environment variables in the Keycloak pod to run in <strong>Standalone Clustered Mode.</strong></p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: keycloak<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec:<br>    containers:<br>      - name: keycloak<br>        image: quay.io/keycloak/keycloak:15.0.2<br>        ... // additional configs truncated<br>        env:<br>          - name: JGROUPS_DISCOVERY_PROTOCOL<br>            value: &quot;kubernetes.KUBE_PING&quot;<br>          - name: JGROUPS_DISCOVERY_PROPERTIES<br>            value: &quot;dump_requests=false,namespace=dev&quot;<br>          - name: CACHE_OWNERS_COUNT<br>            value: &quot;2&quot;<br>          - name: CACHE_OWNERS_AUTH_SESSIONS_COUNT<br>            value: &quot;2&quot;  <br>          - name: KEYCLOAK_HTTP_PORT<br>            value: &quot;80&quot;<br>          - name: KEYCLOAK_HTTPS_PORT<br>            value: &quot;443&quot;</pre><p>5. Enable Readiness &amp; Liveness probes</p><pre><br>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: keycloak<br>spec:<br>  replicas: 2<br>  ... // additional configs truncated<br>  spec:<br>    containers:<br>      - name: keycloak<br>        image: quay.io/keycloak/keycloak:15.0.2<br>        ... // additional configs truncated<br>        readinessProbe:<br>          httpPath: &quot;/auth/realms/master&quot;<br>          port: http<br>          initialDelaySeconds: 40<br>          periodSeconds: 10<br>          timeoutSeconds: 10<br>          failureThreshold: 3<br>        livenessProbe:<br>          httpPath: &quot;/auth/&quot;<br>          port: http<br>          initialDelaySeconds: 40<br>          periodSeconds: 10<br>          timeoutSeconds: 10<br>          failureThreshold: 5</pre><p>After making the changes in deployment, let’s apply it to the k8s cluster.</p><pre>kubectl apply -f keycloak-deployment.yaml</pre><p>You should see the pods running in the mentioned namespace, as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1012/1*OswJpW03JwIuHSKBwnomlQ.png" /></figure><h3>Verification of Keycloak HA</h3><p>Here are the checks required to verify Keycloak is running in HA:</p><p>1. Pods running on different nodes</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0waGKbcH557ZvoOKmv04iw.png" /></figure><p>2.<strong>[Important]</strong> Look for the <em>following lines</em> in the pod’s logs to verify that Keycloak replicas are aware of each other while forming a <strong>CLUSTER.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4fXBxHH1zbe4D9E_1S30GQ.png" /></figure><p>3.<strong>[Important] </strong>Check the pod’s log to verify that Keycloak is running S<strong>tandalone-Clustered Mode.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A8XTWv5CABpQwhGPYwe3bw.png" /></figure><p>4.The new Keycloak node can join/leave the Keycloak cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7eB6Xdgxy34BlpWRXCRm0Q.png" /></figure><p>5.There is rebalancing happening between Keycloak pods</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8h1VSIvMQlET2qCPGXbF5w.png" /></figure><p>6.If the Keycloak primary instance goes down, It can fail over to the other instance, and vice versa.</p><p>7.Access the Keycloak UI, and make a session by logging into the account. Try restarting one of the Keycloak pods, and make sure the user session is still Valid.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>That’s all! You’ve made it to the end 👏 🎉… I’d love to hear your thoughts on this solution. Don’t hesitate to ask questions or share suggestions about the post.</p><p>Happy learning! 😊</p><h3>References</h3><ul><li><a href="https://www.keycloak.org/guides">https://www.keycloak.org/guides</a></li><li><a href="https://jimops.io/highly-available-keycloak-on-kubernetes">https://jimops.io/highly-available-keycloak-on-kubernetes</a></li><li><a href="https://www.keycloak.org/high-availability/introduction">https://www.keycloak.org/high-availability/introduction</a></li><li><a href="https://www.keycloak.org/high-availability/concepts-active-passive-sync">https://www.keycloak.org/high-availability/concepts-active-passive-sync</a></li><li><a href="https://www.keycloak.org/high-availability/bblocks-active-passive-sync">https://www.keycloak.org/high-availability/bblocks-active-passive-sync</a></li><li><a href="https://medium.com/@anuavinash1986/keycloak-cluster-high-availability-in-kubernetes-71d5b6baa6aa">https://medium.com/@anuavinash1986/keycloak-cluster-high-availability-in-kubernetes-71d5b6baa6aa</a></li><li><a href="https://blog.sighup.io/keycloak-ha-on-kubernetes/">https://blog.sighup.io/keycloak-ha-on-kubernetes/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f81f35bcc7d8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/keycloak-high-availability-in-kubernetes-a-comprehensive-guide-f81f35bcc7d8">Keycloak High Availability in Kubernetes: A Comprehensive Guide</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cutting Cloud Costs: Powering EKS Workloads with SPOT Instances]]></title>
            <link>https://medium.com/emumba/cutting-cloud-costs-powering-eks-workloads-with-spot-instances-0dc0b8714a5c?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/0dc0b8714a5c</guid>
            <category><![CDATA[spot-instances]]></category>
            <category><![CDATA[aws-spot]]></category>
            <category><![CDATA[cost-optimization]]></category>
            <category><![CDATA[eks-cluster]]></category>
            <category><![CDATA[kubernetes-cluster]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Thu, 22 Aug 2024 19:57:12 GMT</pubDate>
            <atom:updated>2024-09-09T07:35:03.942Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/907/1*X1cKrYTFu2CuIvDu2gpGqQ.png" /></figure><h4>How can utilizing SPOT Instances in EKS clusters help us cut cloud costs while maintaining the performance and availability of containerized workloads?</h4><p>— -</p><p>In the era of cloud computing, managing costs while maintaining performance is a constant challenge for businesses. <strong>Amazon EKS</strong> (Elastic Kubernetes Service) offers a powerful solution for running containerized applications at scale, but it can come with a hefty price tag.</p><p>Before diving into the use of SPOT Instances in EKS clusters, let’s address some key questions:</p><ul><li>What exactly SPOT Instances are, and their trade-offs?</li><li>Which types of workloads are best suited for SPOT Instances?</li><li>How can SPOT Instances be integrated into EKS workloads?</li><li>Comparison of Costs with On-Demand Instances?</li><li>Downtime associated with Spot Instances?</li><li>What are the best practices and recommendations for using them?</li></ul><h3>SPOT Instances</h3><p><strong>SPOT Instances</strong> are <strong><em>discounted, unused cloud resources</em></strong> offered by AWS, allowing you to run workloads at a significantly lower cost compared to On-Demand instances, with the <em>trade-off being that they can be reclaimed by AWS with short notice.</em></p><h3>Types of Workload best suited for SPOT Instances</h3><p>Spot instances in Kubernetes clusters are typically recommended for <strong><em>stateless, fault-tolerant, and non-critical workloads</em></strong> due to their inherently transient nature. Here are some workload types that are suitable for running on-spot instances in a Kubernetes cluster:</p><ol><li><strong>Batch Processing Jobs</strong>: Ideal for non-urgent, large-scale data tasks that can tolerate interruptions.</li><li><strong>Containerized Web Applications:</strong> Great for stateless apps that scale horizontally, with load balancers and auto-scaling ensuring availability despite instance terminations.</li><li><strong>Dev/Test Environments: </strong>Perfect for flexible, dynamic provisioning, offering significant cost savings for developers.</li><li><strong>Big Data Processing:</strong> Distributed frameworks like Apache Spark or Hadoop can efficiently utilize SPOT Instances, handling node failures gracefully.</li><li><strong>Containerized Stateful Applications with Replication:</strong> Suitable for stateful apps designed for replication, like distributed databases, that can tolerate node failures.</li><li><strong>Non-critical Backend Services:</strong> Good for non-essential services that can handle occasional disruptions without affecting core functionality.</li></ol><p>— — — — —</p><p>Enough of boring stuff? Hmm… Let’s jump straight into implementing SPOT Instances for EKS workloads in your cluster. Cool &amp; amazing stuff coming up, hunh!</p><h3>Spot Instances on EKS</h3><p>The following are the steps to use Spot Instance on EKS:</p><ol><li>To utilize spot instances in EKS, select capacity type as <strong>spot </strong>while creating a <strong>node group</strong>, shown below:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*1TllUDM8AcLOsVa0LwUVRw.png" /></figure><p>2. Select multiple subnets while utilizing all AZs of the region.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1002/1*eaqBS6Ej37wqmuzD5JXI8Q.png" /></figure><p>3. Review and create the node group with SPOT capacity type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*92QsxoB4oBUv5K2LNtpGEg.png" /></figure><p>There you go 🎉 .. That’s it. Isn’t it very easy to utilize spot instances in EKS clusters?</p><h3>Downtime with Spot Instance</h3><p>When using spot instances in EKS, One should remember that when EC2 needs the capacity back, the Spot Instance service arbitrarily sends Spot interruption notifications to instances within the associated Spot capacity pool. This Spot interruption notification lands in both the EC2 instance metadata and <a href="https://aws.amazon.com/eventbridge/">Eventbridge</a>.</p><blockquote><strong>Two minutes after the Spot interruption notification, the instance is reclaimed</strong></blockquote><h3>Cost Comparision with On-demand Instances</h3><p>Spot instances are very cheap, as compared to on-demand instances, and offer <strong>cost</strong> <strong><em>savings of up to 90%</em></strong>, making them a highly economical option for running flexible workloads.</p><h3>Best Practices</h3><p>Following are some best practices for using spot instances in EKS clusters:</p><ul><li>Use <strong>cluster-autoscaler</strong> as a node auto-scaling solution and run it on a separate node group.</li><li>Use diversified Spot Instance node groups i.e. multiple instance types.</li><li>Use a Capacity-optimized Spot allocation strategy for spot instances.</li><li>To mitigate the impact of potential Spot Instance interruptions, leverage the ‘<a href="https://github.com/aws/aws-node-termination-handler">node termination handler</a>’.</li><li>Use maximum Spot capacity pools to increase the stability and resilience of the application.</li></ul><blockquote><strong>Spot capacity pools = (Availability Zones) * (Instance Types)</strong></blockquote><p><strong>Congrats</strong>, you’ve made it to the end. I would like to hear your opinions about this solution. Feel free to ask questions or give suggestions about this post.</p><p>Happy learning :)!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0dc0b8714a5c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/cutting-cloud-costs-powering-eks-workloads-with-spot-instances-0dc0b8714a5c">Cutting Cloud Costs: Powering EKS Workloads with SPOT Instances</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Demystifying RBAC in Kubernetes: A Simple Explanation]]></title>
            <link>https://medium.com/emumba/demystifying-rbac-in-kubernetes-a-simple-explanation-85666454cdc2?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/85666454cdc2</guid>
            <category><![CDATA[devops-training]]></category>
            <category><![CDATA[role-based-access-control]]></category>
            <category><![CDATA[kubernetes-security]]></category>
            <category><![CDATA[kubernetes-rbac]]></category>
            <category><![CDATA[access-control-systems]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Mon, 19 Aug 2024 13:08:27 GMT</pubDate>
            <atom:updated>2024-09-09T07:34:22.693Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is RBAC? Why is it so important and how to implement it?</h3><p>Kubernetes is known for managing, scaling, and maintaining containerized workload, but its steep learning curve presents significant challenges. Moreover, implementing an additional layer of security through <strong>RBAC</strong> to restrict users’ access to resources within the k8s cluster, adds up another level of complexity.</p><p>In this blog post, I will demystify the RBAC (Role-Based Access Control) mechanism in Kubernetes, highlighting its use cases, and importance, and providing a practical guide using the following scenario.</p><h4><em>Scenario</em>:</h4><p>How can a Pod running inside the k8s cluster create and/or delete other k8s (pods, deployments, and jobs) resources?</p><p>This blog post covers the following:</p><ol><li>What is RBAC in k8s?</li><li>User vs Service account</li><li>Role vs RoleBinding — ClusterRole vs ClusterRoleBinding</li><li>RBAC DEMO</li><li>Best practices</li></ol><h3>What is RBAC?</h3><p>RBAC stands for <strong>Role Based Access Control</strong>, which simply means:</p><blockquote><strong>who can access what, in K8S cluster.</strong></blockquote><p>“As the number of cluster nodes, applications, and team members increase, you’ll want to limit the resources your team members and applications can access, as well as the actions they can take.”</p><p>Hence RBAC is a mechanism (security enforcement layer) that restricts users/applications to create, delete, and update resources (pods, namespaces, secretes, persistence storage, etc.) within K8S clusters. <strong>It allows cluster administrators to enforce</strong> <strong>fine-grained control over resources within a cluster. </strong>For example:</p><ul><li>Secure cluster by granting privileged operations (accessing secrets, deleting namespaces, for example) only to admin users.</li><li>Force user authentication in your cluster.</li><li>Limit resource creation (such as pods, persistent volumes, and deployments) to specific namespaces.</li><li>Have a user only see resources in their authorized namespace. This allows you to implement the multi-tenant-based architecture.</li></ul><p>Umm, that seems promising, to some extent, but how exactly that can be done? Before I could jump right into implementation, let me first define some of the Jorgans, related to RBAC.</p><h3>User vs Service account</h3><p>A <strong>User</strong> refers to a human being. However,</p><blockquote>It’s important to note that Kubernetes does not manage user accounts natively, meaning you cannot create or delete users using commands like kubectl create/delete user.</blockquote><p>Instead, user accounts are managed outside of Kubernetes clusters and are synced with corporate databases such as AWS IAM/Azure AD or Active Directory or LDAP.</p><p>On the other hand, a “<strong>Service account</strong>” is a type of Kubernetes resource that is created and managed using the Kubernetes API. They are intended to be used by entities within a Kubernetes cluster, such as Pods, to authenticate with the Kubernetes API server or external services. Some of the service account use cases are:</p><ul><li>Think about CI/CD access to the cluster</li><li>Pod-to-pod communication</li><li>Pods to Kubernetes API authentication</li></ul><p>The following table depicts the differences between both of them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*9DtGVeGgXbabG17Uk1mMHg.png" /></figure><h4>Role vs ClusterRole</h4><p>Think of <strong>Role </strong>as a policy document, that enlists actions allowed on resources. Role or ClusterRole are K8S resources that contain rules that represent a set of permissions. Permissions are purely additive (there are no “deny” rules).</p><blockquote>Roles grant access to resources within a single namespace while ClusterRoles are cluster-wide / cluster scoped.</blockquote><h4>RoleBinding and ClusterRoleBinding</h4><p>RoleBinding or ClusterRoleBinding binds role to subject. The following are three types of subjects:</p><ul><li>Users</li><li>Groups</li><li>Service accounts</li></ul><h4>Exhibiting the Scenario</h4><p>In some scenarios where we have to deploy k8s objects from running pods, e.g a pod creates another deployment, service, or job. This isn’t allowed by default as k8s pods can’t interact with k8s API service directly using a <strong><em>default service</em></strong> account, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*Cu3cP_yQymIy1LS9AgRVLQ.png" /></figure><p>As shown below, the <em>demo-app</em> pod isn’t allowed to create deployments, pods &amp; job objects from within itself.</p><blockquote>Kubectl offers <strong>“kubectl auth can-i”</strong> command to check if the pod is eligible to create k8s resources or not.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z2c5aPl49uukAMN8EbRe9g.png" /></figure><p>Umm... Let’s use the <strong>K8S RBAC</strong> mechanism to allow pod access to the k8s API, and create the Objects. For this purpose, we’ll be creating the following:</p><ol><li><strong>Service-Account</strong> used by the <em>demo-pod</em> to elevate its access.</li><li><strong>Role</strong> that enlists the required permissions</li><li><strong>Role-bindings</strong> that bind the role to the subject(service account).</li></ol><h4>1. Service account</h4><p>Let’s first create a service account in the demonamespace that will be used by the demo-appdeployment to launch other objects:</p><pre>apiVersion: v1<br>kind: ServiceAccount<br>metadata:<br>  name: demo-sa<br>  namespace: demo</pre><h4>2. Role</h4><p>This Role grants unrestricted access (‘*’) to manage deployments, pods, and jobs within the ‘demo’ namespace in Kubernetes.</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: Role<br>metadata:<br>  name: demo-role<br>  namespace: demo<br>rules:<br>  - verbs:<br>      - &#39;*&#39;<br>    apiGroups:<br>      - &#39;&#39;<br>      - apps<br>      - batch<br>    resources:<br>      - deployments<br>      - pods<br>      - jobs</pre><h4>3. Rolebinding</h4><p>This RoleBinding “<em>demo-role-binding</em>” associates the “<em>demo-sa</em>” service account in the “<em>demo</em>” namespace with the Role named “<em>demo-role”</em>. It allows the ServiceAccount to inherit the permissions defined in the Role for resource access control within the demo namespace.</p><pre>apiVersion: rbac.authorization.k8s.io/v1<br>kind: RoleBinding<br>metadata:<br>  name: demo-role-binding<br>  namespace: demo<br>subjects:<br>  - kind: ServiceAccount<br>    name: demo-sa<br>    namespace: demo<br>roleRef:<br>  apiGroup: rbac.authorization.k8s.io<br>  kind: Role<br>  name: demo-role</pre><h4>4. Deployment</h4><p>Update the “<em>demo-app</em>” deployment using “<em>demo-sa</em>” specified by the following tag: serviceAccount: demo-sa</p><pre>apiVersion: apps/v1<br>kind: Deployment<br>metadata:<br>  name: demo-app<br>  namespace: demo<br>  labels:<br>    app: demo-app<br>spec:<br>  replicas: 1<br>  selector:<br>    matchLabels:<br>      app: demo-app<br>  template:<br>    metadata:<br>      labels:<br>        app: demo-app<br>    spec:<br>      containers:<br>        - name: demo-app<br>          image: busybox:latest<br>          ports:<br>            - name: http<br>              containerPort: 80<br>              protocol: TCP<br>      serviceAccountName: demo-sa</pre><p>Let’s verify the created resources by <em>kubectl get command</em>, as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/866/1*uTmCJo6S2KSwJIeN6n6EVA.png" /></figure><h4>Verification of the Permissions</h4><p>Finally, let’s verify if <strong>demo-app </strong>pod can create pods/deployments/jobs. For this purpose, let’s issue the following commands by ssh-ing into the pod.</p><pre>kubectl exec -it demo-app-699df56b79-lwbpz -n demo bash<br>---<br>kubectl auth can-i create deployments<br>kubectl auth can-i create pods<br>kubectl auth can-i create jobs</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bHhqjs0xHdOK1ooVXj4R6A.png" /></figure><p>There you go 🎉 .. You’re able to create K8s objects (i.e. those only allowed in the Role) from the demo-app pod.</p><h4>Best practices around RBAC</h4><p>There are a few best practices that I want to share with you. Follow them while using RBAC</p><ul><li>Making the Most of Kubernetes RBAC</li><li>Follow the principle of Least Privileges</li><li>Avoid Default Service Accounts</li><li>Minimize API Server Flags</li><li>Update RBAC Policies Continuously</li></ul><p>— -</p><p><strong>Congrats</strong>, you’ve made it to the end. I would like to hear your opinions about this solution. Feel free to ask questions or give suggestions about this post.</p><p>Happy learning :)!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85666454cdc2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/emumba/demystifying-rbac-in-kubernetes-a-simple-explanation-85666454cdc2">Demystifying RBAC in Kubernetes: A Simple Explanation</a> was originally published in <a href="https://medium.com/emumba">Emumba</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simplify PostgreSQL Database Management: Automating Multiple Database Drop/Create Operations]]></title>
            <link>https://medium.com/@imtiaz9832/simplify-postgresql-database-management-automating-multiple-database-drop-create-operations-60b6a1e283c5?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/60b6a1e283c5</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[database-management]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[psql]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Wed, 31 May 2023 20:48:54 GMT</pubDate>
            <atom:updated>2023-05-31T20:48:54.566Z</atom:updated>
            <content:encoded><![CDATA[<p>Managing databases is an essential task for any database administrator or developer working with <strong>PostgreSQL</strong>. PostgreSQL offers a rich set of features and commands for creating and dropping individual databases.</p><p>The CREATE DATABASE and DROP DATABASEcommands in PostgreSQL is designed to create or drop one database at a time. However, <em>It lacks a built-in mechanism to create or drop multiple databases all at once. </em>If you need to create / drop multiple databases at once, you’ll need to execute the above command separately for each database.</p><p>Recognizing the need for efficient and streamlined workflows, I’ve created the following scripts to automate the <strong><em>creation or deletion of multiple PostgreSQL databases</em>,</strong> ultimately simplifying administrative tasks and saving valuable time.</p><p>Now that the prologue is over let’s get into action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*SQMf4wPqipQ2caANFvikZw.gif" /></figure><p>Before using these scripts, make sure to update the following variables in the both of these scripts.</p><ul><li><strong>DATABASES:</strong> <em>list of database names to be created!</em></li><li><strong>PGUSER:</strong> <em>postgres-user</em></li><li><strong>PGPASSWROD:</strong> <em>postgres-password</em></li><li><strong>PGHOST:</strong> <em>postgres-host</em></li></ul><p>The create-dbs.sh script is used to create multiple databases at once.</p><pre>DATABASES=(&quot;airbyte&quot; &quot;task_service&quot; &quot;user_service&quot; &quot;keycloak&quot; &quot;data_analysis_service&quot; &quot;data_product_service&quot; &quot;dbt_transformations_service&quot; &quot;ml_service&quot; &quot;pipeline_service&quot; &quot;product_service&quot; &quot;sql_transformations_service&quot; &quot;streaming_source_connector_service&quot; &quot;superset_service&quot;)<br><br># Update the credentials<br>export PGUSER=&#39;&lt;db-user&gt;&#39;;<br>export PGPASSWORD=&#39;&lt;password&gt;&#39;;<br>export PGHOST=&#39;&lt;db-host&gt;&#39;;<br><br>for db in ${DATABASES[@]};<br>do<br>  echo &quot;Creating database $db&quot;<br>  psql -U $USER -h $PGHOST -c &quot;create database $db&quot;;<br>done<br>echo &quot;Cheers! All done :)!&quot;</pre><p>Here the drop-dbs.sh script which is used to drop multiple databases at once.</p><pre>DATABASES=(&quot;airbyte&quot; &quot;task_service&quot; &quot;user_service&quot; &quot;keycloak&quot; &quot;data_analysis_service&quot; &quot;data_product_service&quot; &quot;dbt_transformations_service&quot; &quot;ml_service&quot; &quot;pipeline_service&quot; &quot;product_service&quot; &quot;sql_transformations_service&quot; &quot;streaming_source_connector_service&quot; &quot;superset_service&quot;)<br><br># Update the credentials<br>export PGUSER=&#39;&lt;db-user&gt;&#39;;<br>export PGPASSWORD=&#39;&lt;password&gt;&#39;;<br>export PGHOST=&#39;&lt;db-host&gt;&#39;;<br><br>for db in ${DATABASES[@]};<br>do<br>  echo &quot;Deleting database $db&quot;<br>  psql -U $USER -h $PGHOST -c &quot;drop database $db WITH (FORCE)&quot;;<br>done<br>echo &quot;Cheers! All done :)!&quot;</pre><blockquote><strong><em>Making the scripts executables</em><br></strong>Use the following commands to make the scripts executable:</blockquote><pre>chmod +x create-dbs.sh<br>chmod +x drop-dbs.sh</pre><blockquote>Use the following commands to run these scripts:</blockquote><pre>./create-dbs.sh<br>./drop-dbs.sh</pre><p><strong>Congrats</strong>, you’ve made it to the end. I would really like to hear your opinions about this solution. Feel free to ask questions or give suggestions about this post.</p><p>Happy learning :)!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60b6a1e283c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s Break the Bridge of Small Talks]]></title>
            <link>https://medium.com/@imtiaz9832/lets-break-the-bridge-of-small-talks-81bde8d0c975?source=rss-12ea94d2da7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/81bde8d0c975</guid>
            <category><![CDATA[life-lessons]]></category>
            <category><![CDATA[relationship-building]]></category>
            <category><![CDATA[meaningful-conversation]]></category>
            <category><![CDATA[avoiding-small-talks]]></category>
            <category><![CDATA[smalltalk]]></category>
            <dc:creator><![CDATA[Muhammad Imtiaz]]></dc:creator>
            <pubDate>Mon, 08 Oct 2018 10:48:43 GMT</pubDate>
            <atom:updated>2018-10-08T10:48:43.938Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*E0PMqLRTccTAJnOkQ6iHJw.jpeg" /></figure><p>In everyday, how often we have a chance to meet some unknown person? Ever we tried to know about him/her? Well, we start our conversation with questions like: what’s your name? Where you come from? What do you do? Do you ever wonder, these questions can lead us to know someone? Obviously not!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZpkMDoeSSoFKMJ6T" /><figcaption>“man and woman sitting on chairs” by <a href="https://unsplash.com/@rawpixel?utm_source=medium&amp;utm_medium=referral">rawpixel</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>There are 7 billions people in the world, everyone with an amazing and uniques stories to tell. That’s make 7 billions treasure boxes full of life lessons, wisdom and experiences. So, question may arises how to know each other?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZOPLTJyAPpovOd6nvwmIHA.png" /></figure><p>Just ask questions (True?). We may ask questions like: What quality that you like the most in your mother? What decisions made you regret? Does Pakistani education’s curriculum ever produce a Scientist in the society? Well, what’s the benefit of these questions? Yes, these make compel someone to think and answer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*YTxvWENZUCPufq5t2ceXOA.jpeg" /></figure><p>Asking such types of questions can lead us to a powerful and more meaningful conversations and lead us to life long relationships. We can have beautiful memories and experience that may help us to decide better and make our lives awesome.</p><blockquote>I hope you enjoyed it. Please be kind enough to like it and comment any of your doubts or query. I will make sure to reply it soon!and I will reply them at the earliest. Happy learning.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=81bde8d0c975" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>