<?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:hashnode="https://hashnode.com/rss"><channel><title><![CDATA[Saurabh Adhau's blog]]></title><description><![CDATA[Saurabh Adhau's blog]]></description><link>https://devopsvoyager.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 03 Dec 2024 08:19:50 GMT</lastBuildDate><atom:link href="https://devopsvoyager.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><atom:link rel="next" href="https://devopsvoyager.hashnode.dev/rss.xml?page=2"/><atom:link rel="previous" href="https://devopsvoyager.hashnode.dev/rss.xml"/><item><title><![CDATA[What is AWS Karpenter ?]]></title><description><![CDATA[Introduction
AWS Karpenter is an open-source, high-performance autoscaling solution for Kubernetes, designed to optimize resource management and improve application availability. It simplifies the process of provisioning nodes by directly interacting...]]></description><link>https://devopsvoyager.hashnode.dev/what-is-aws-karpenter</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/what-is-aws-karpenter</guid><category><![CDATA[aws karpenter]]></category><category><![CDATA[karpenter]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Mon, 28 Oct 2024 03:30:19 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;AWS Karpenter is an open-source, high-performance autoscaling solution for Kubernetes, designed to optimize resource management and improve application availability. It simplifies the process of provisioning nodes by directly interacting with the AWS EC2 fleet API, allowing for rapid scaling based on real-time workload demands.&lt;/p&gt;&lt;h2 id=&quot;heading-key-features-of-karpenter&quot;&gt;Key Features of Karpenter&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Node Provisioning&lt;/strong&gt;: Karpenter automatically provisions nodes in response to unscheduled pods, ensuring that applications have the necessary resources without overprovisioning.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intelligent Resource Allocation&lt;/strong&gt;: It intelligently selects the right instance types and sizes based on the specific requirements of applications, optimizing costs and performance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Provisioners&lt;/strong&gt;: Users can define custom resources called provisioners to manage how nodes are provisioned, allowing for flexibility in configurations based on workload characteristics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Efficiency&lt;/strong&gt;: By optimizing resource utilization and enabling the use of Spot instances, Karpenter helps reduce overall cloud expenses.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zone Awareness&lt;/strong&gt;: Karpenter provisions resources in the appropriate availability zones, improving application performance and reliability.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-benefits-of-karpenter&quot;&gt;Benefits of Karpenter&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimal Resource Utilization&lt;/strong&gt;: By provisioning nodes based on actual application needs, Karpenter prevents overprovisioning and underutilization.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customizable Scheduling&lt;/strong&gt;: Users can set specific criteria for scheduling workloads, enhancing efficiency.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Integration&lt;/strong&gt;: Karpenter integrates easily with existing Kubernetes workflows, making it a straightforward addition to cloud-based applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-limitations&quot;&gt;Limitations&lt;/h2&gt;&lt;p&gt;While Karpenter offers many advantages, it also has some limitations, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Existing Commitments Awareness&lt;/strong&gt;: Karpenter does not optimize spending based on existing commitments like Reserved Instances, which may lead to underutilization.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Complexity&lt;/strong&gt;: Initial setup can be complex and may require significant technical knowledge.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Short Notice for Spot Terminations&lt;/strong&gt;: Karpenter relies on AWSs 2-minute warning before Spot instances terminate, which may not provide sufficient time for some workloads to be optimally rescheduled.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;AWS Karpenter represents a significant advancement in Kubernetes autoscaling, providing a dynamic and efficient solution for managing cloud resources. Its intelligent provisioning capabilities, cost optimization strategies, and seamless integration make it a powerful tool for organizations looking to enhance the performance and efficiency of their Kubernetes workloads.&lt;/p&gt;&lt;p&gt;For more information, you can explore the following resources:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://karpenter.sh/docs/&quot;&gt;Karpenter Documentation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://aws.amazon.com/blogs/aws/introducing-karpenter-an-open-source-high-performance-kubernetes-cluster-autoscaler/&quot;&gt;Introducing Karpenter  An Open-Source High-Performance Kubernetes Cluster Autoscaler&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;AWS Karpenter is an open-source, high-performance autoscaling solution for Kubernetes, designed to optimize resource management and improve application availability. It simplifies the process of provisioning nodes by directly interacting with the AWS EC2 fleet API, allowing for rapid scaling based on real-time workload demands.&lt;/p&gt;&lt;h2 id=&quot;heading-key-features-of-karpenter&quot;&gt;Key Features of Karpenter&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Node Provisioning&lt;/strong&gt;: Karpenter automatically provisions nodes in response to unscheduled pods, ensuring that applications have the necessary resources without overprovisioning.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Intelligent Resource Allocation&lt;/strong&gt;: It intelligently selects the right instance types and sizes based on the specific requirements of applications, optimizing costs and performance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Custom Provisioners&lt;/strong&gt;: Users can define custom resources called provisioners to manage how nodes are provisioned, allowing for flexibility in configurations based on workload characteristics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Efficiency&lt;/strong&gt;: By optimizing resource utilization and enabling the use of Spot instances, Karpenter helps reduce overall cloud expenses.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zone Awareness&lt;/strong&gt;: Karpenter provisions resources in the appropriate availability zones, improving application performance and reliability.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-benefits-of-karpenter&quot;&gt;Benefits of Karpenter&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Optimal Resource Utilization&lt;/strong&gt;: By provisioning nodes based on actual application needs, Karpenter prevents overprovisioning and underutilization.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Customizable Scheduling&lt;/strong&gt;: Users can set specific criteria for scheduling workloads, enhancing efficiency.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Integration&lt;/strong&gt;: Karpenter integrates easily with existing Kubernetes workflows, making it a straightforward addition to cloud-based applications.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-limitations&quot;&gt;Limitations&lt;/h2&gt;&lt;p&gt;While Karpenter offers many advantages, it also has some limitations, including:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Existing Commitments Awareness&lt;/strong&gt;: Karpenter does not optimize spending based on existing commitments like Reserved Instances, which may lead to underutilization.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Complexity&lt;/strong&gt;: Initial setup can be complex and may require significant technical knowledge.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Short Notice for Spot Terminations&lt;/strong&gt;: Karpenter relies on AWSs 2-minute warning before Spot instances terminate, which may not provide sufficient time for some workloads to be optimally rescheduled.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;AWS Karpenter represents a significant advancement in Kubernetes autoscaling, providing a dynamic and efficient solution for managing cloud resources. Its intelligent provisioning capabilities, cost optimization strategies, and seamless integration make it a powerful tool for organizations looking to enhance the performance and efficiency of their Kubernetes workloads.&lt;/p&gt;&lt;p&gt;For more information, you can explore the following resources:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://karpenter.sh/docs/&quot;&gt;Karpenter Documentation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://aws.amazon.com/blogs/aws/introducing-karpenter-an-open-source-high-performance-kubernetes-cluster-autoscaler/&quot;&gt;Introducing Karpenter  An Open-Source High-Performance Kubernetes Cluster Autoscaler&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725938638637/34fe92eb-4806-41a8-b0ba-8a6b525e0fea.png</hashnode:coverImage></item><item><title><![CDATA[Understanding Cluster Autoscaler: Automating Kubernetes Resource Management]]></title><description><![CDATA[Introduction
In cloud-native applications, efficient resource management is crucial to maintain optimal performance and cost-effectiveness. One powerful tool that aids in this management is the Cluster Autoscaler. This article explores the Cluster Au...]]></description><link>https://devopsvoyager.hashnode.dev/understanding-cluster-autoscaler-automating-kubernetes-resource-management</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/understanding-cluster-autoscaler-automating-kubernetes-resource-management</guid><category><![CDATA[Kubernetes]]></category><category><![CDATA[clusterautoscaler]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Sat, 26 Oct 2024 03:30:13 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;In cloud-native applications, efficient resource management is crucial to maintain optimal performance and cost-effectiveness. One powerful tool that aids in this management is the Cluster Autoscaler. This article explores the Cluster Autoscaler, its functionality, benefits, and how it can be leveraged to enhance Kubernetes clusters.&lt;/p&gt;&lt;h3 id=&quot;heading-what-is-cluster-autoscaler&quot;&gt;What is Cluster Autoscaler?&lt;/h3&gt;&lt;p&gt;Cluster Autoscaler (CA) is a Kubernetes component that automatically adjusts the size of a cluster based on resource demands. It ensures that your cluster has the right amount of computing resources available by scaling the number of nodes up or down depending on the workload. This helps in maintaining performance while optimizing costs by only using the resources you need.&lt;/p&gt;&lt;h3 id=&quot;heading-how-does-cluster-autoscaler-work&quot;&gt;How Does Cluster Autoscaler Work?&lt;/h3&gt;&lt;p&gt;Cluster Autoscaler monitors the clusters resources and makes decisions to adjust the cluster size. Heres a high-level overview of how it functions:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitoring&lt;/strong&gt;: Cluster Autoscaler continuously monitors the cluster&apos;s health and resource utilization. It checks for unscheduled pods (pods that cannot be scheduled due to lack of resources) and identifies underutilized nodes (nodes that can be safely removed).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scaling Up&lt;/strong&gt;: When the Autoscaler detects that pods are pending due to insufficient resources, it triggers the provisioning of new nodes. This process involves interacting with the cloud provider&apos;s API to add more instances to the cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scaling Down&lt;/strong&gt;: Conversely, if the Autoscaler finds that certain nodes are underutilized and can be removed without disrupting running applications, it will terminate these nodes. This involves draining the nodes (i.e., moving the pods to other nodes) and then removing the nodes from the cluster.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-key-features-of-cluster-autoscaler&quot;&gt;Key Features of Cluster Autoscaler&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Scaling&lt;/strong&gt;: Automatically adjusts the number of nodes in the cluster based on current resource usage and demands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Efficiency&lt;/strong&gt;: Reduces operational costs by ensuring that nodes are only running when needed and that underutilized nodes are scaled down.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Integration&lt;/strong&gt;: Works with major cloud providers like AWS, Google Cloud Platform (GCP), and Microsoft Azure, leveraging their respective APIs to manage resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Scheduling&lt;/strong&gt;: Ensures that unscheduled pods are accommodated by provisioning additional resources when necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node Optimization&lt;/strong&gt;: Identifies and removes underutilized nodes while maintaining cluster stability.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-benefits-of-using-cluster-autoscaler&quot;&gt;Benefits of Using Cluster Autoscaler&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Savings&lt;/strong&gt;: By scaling down unused resources, Cluster Autoscaler helps in minimizing cloud costs. You pay for what you use, rather than over-provisioning resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Performance&lt;/strong&gt;: Automatic scaling ensures that your applications have the resources they need to perform efficiently, reducing the risk of performance bottlenecks due to resource shortages.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Operational Efficiency&lt;/strong&gt;: Reduces the need for manual intervention in managing cluster sizes, freeing up time for DevOps teams to focus on other critical tasks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Elasticity&lt;/strong&gt;: Provides the flexibility to handle varying workloads, from sudden spikes in demand to periods of low activity, ensuring that your cluster can adapt dynamically to changing conditions.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-configuring-cluster-autoscaler&quot;&gt;Configuring Cluster Autoscaler&lt;/h3&gt;&lt;p&gt;To set up Cluster Autoscaler in a Kubernetes cluster, follow these general steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Cluster Autoscaler&lt;/strong&gt;: Deploy the Cluster Autoscaler using a YAML configuration file or through Helm charts, tailored to your specific cloud provider.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure Cloud Provider Integration&lt;/strong&gt;: Ensure that Cluster Autoscaler has the necessary permissions and access to interact with your cloud provider&apos;s API for scaling operations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Auto-Scaling Policies&lt;/strong&gt;: Define policies and limits for scaling up and down, including thresholds for when to trigger scaling actions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Adjust&lt;/strong&gt;: Regularly monitor the performance and behavior of Cluster Autoscaler, and adjust configuration settings as needed to align with your operational requirements.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-challenges-and-considerations&quot;&gt;Challenges and Considerations&lt;/h3&gt;&lt;p&gt;While Cluster Autoscaler is a powerful tool, its essential to be aware of potential challenges:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Complexity&lt;/strong&gt;: Proper configuration is crucial to avoid issues such as excessive scaling or inadequate resource allocation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Disruption&lt;/strong&gt;: Scaling down nodes may lead to pod rescheduling, which can impact application performance if not managed correctly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloud Provider Limits&lt;/strong&gt;: Ensure that your cloud providers limits and quotas align with your scaling needs to prevent disruptions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;Cluster Autoscaler is a vital component for managing Kubernetes clusters efficiently. Automating the scaling of resources based on real-time demands helps in optimizing costs, improving performance, and enhancing operational efficiency. As cloud environments continue to evolve, leveraging tools like Cluster Autoscaler becomes increasingly important in maintaining a balance between resource utilization and cost-effectiveness.&lt;/p&gt;&lt;p&gt;For anyone managing Kubernetes clusters, understanding and implementing Cluster Autoscaler can lead to a more agile and responsive infrastructure, ultimately contributing to the success of your cloud-native applications.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;In cloud-native applications, efficient resource management is crucial to maintain optimal performance and cost-effectiveness. One powerful tool that aids in this management is the Cluster Autoscaler. This article explores the Cluster Autoscaler, its functionality, benefits, and how it can be leveraged to enhance Kubernetes clusters.&lt;/p&gt;&lt;h3 id=&quot;heading-what-is-cluster-autoscaler&quot;&gt;What is Cluster Autoscaler?&lt;/h3&gt;&lt;p&gt;Cluster Autoscaler (CA) is a Kubernetes component that automatically adjusts the size of a cluster based on resource demands. It ensures that your cluster has the right amount of computing resources available by scaling the number of nodes up or down depending on the workload. This helps in maintaining performance while optimizing costs by only using the resources you need.&lt;/p&gt;&lt;h3 id=&quot;heading-how-does-cluster-autoscaler-work&quot;&gt;How Does Cluster Autoscaler Work?&lt;/h3&gt;&lt;p&gt;Cluster Autoscaler monitors the clusters resources and makes decisions to adjust the cluster size. Heres a high-level overview of how it functions:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitoring&lt;/strong&gt;: Cluster Autoscaler continuously monitors the cluster&apos;s health and resource utilization. It checks for unscheduled pods (pods that cannot be scheduled due to lack of resources) and identifies underutilized nodes (nodes that can be safely removed).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scaling Up&lt;/strong&gt;: When the Autoscaler detects that pods are pending due to insufficient resources, it triggers the provisioning of new nodes. This process involves interacting with the cloud provider&apos;s API to add more instances to the cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scaling Down&lt;/strong&gt;: Conversely, if the Autoscaler finds that certain nodes are underutilized and can be removed without disrupting running applications, it will terminate these nodes. This involves draining the nodes (i.e., moving the pods to other nodes) and then removing the nodes from the cluster.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-key-features-of-cluster-autoscaler&quot;&gt;Key Features of Cluster Autoscaler&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Scaling&lt;/strong&gt;: Automatically adjusts the number of nodes in the cluster based on current resource usage and demands.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Efficiency&lt;/strong&gt;: Reduces operational costs by ensuring that nodes are only running when needed and that underutilized nodes are scaled down.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Integration&lt;/strong&gt;: Works with major cloud providers like AWS, Google Cloud Platform (GCP), and Microsoft Azure, leveraging their respective APIs to manage resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Scheduling&lt;/strong&gt;: Ensures that unscheduled pods are accommodated by provisioning additional resources when necessary.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Node Optimization&lt;/strong&gt;: Identifies and removes underutilized nodes while maintaining cluster stability.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-benefits-of-using-cluster-autoscaler&quot;&gt;Benefits of Using Cluster Autoscaler&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cost Savings&lt;/strong&gt;: By scaling down unused resources, Cluster Autoscaler helps in minimizing cloud costs. You pay for what you use, rather than over-provisioning resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Performance&lt;/strong&gt;: Automatic scaling ensures that your applications have the resources they need to perform efficiently, reducing the risk of performance bottlenecks due to resource shortages.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Operational Efficiency&lt;/strong&gt;: Reduces the need for manual intervention in managing cluster sizes, freeing up time for DevOps teams to focus on other critical tasks.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Elasticity&lt;/strong&gt;: Provides the flexibility to handle varying workloads, from sudden spikes in demand to periods of low activity, ensuring that your cluster can adapt dynamically to changing conditions.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-configuring-cluster-autoscaler&quot;&gt;Configuring Cluster Autoscaler&lt;/h3&gt;&lt;p&gt;To set up Cluster Autoscaler in a Kubernetes cluster, follow these general steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Cluster Autoscaler&lt;/strong&gt;: Deploy the Cluster Autoscaler using a YAML configuration file or through Helm charts, tailored to your specific cloud provider.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure Cloud Provider Integration&lt;/strong&gt;: Ensure that Cluster Autoscaler has the necessary permissions and access to interact with your cloud provider&apos;s API for scaling operations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Auto-Scaling Policies&lt;/strong&gt;: Define policies and limits for scaling up and down, including thresholds for when to trigger scaling actions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Adjust&lt;/strong&gt;: Regularly monitor the performance and behavior of Cluster Autoscaler, and adjust configuration settings as needed to align with your operational requirements.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-challenges-and-considerations&quot;&gt;Challenges and Considerations&lt;/h3&gt;&lt;p&gt;While Cluster Autoscaler is a powerful tool, its essential to be aware of potential challenges:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Complexity&lt;/strong&gt;: Proper configuration is crucial to avoid issues such as excessive scaling or inadequate resource allocation.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Disruption&lt;/strong&gt;: Scaling down nodes may lead to pod rescheduling, which can impact application performance if not managed correctly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cloud Provider Limits&lt;/strong&gt;: Ensure that your cloud providers limits and quotas align with your scaling needs to prevent disruptions.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;Cluster Autoscaler is a vital component for managing Kubernetes clusters efficiently. Automating the scaling of resources based on real-time demands helps in optimizing costs, improving performance, and enhancing operational efficiency. As cloud environments continue to evolve, leveraging tools like Cluster Autoscaler becomes increasingly important in maintaining a balance between resource utilization and cost-effectiveness.&lt;/p&gt;&lt;p&gt;For anyone managing Kubernetes clusters, understanding and implementing Cluster Autoscaler can lead to a more agile and responsive infrastructure, ultimately contributing to the success of your cloud-native applications.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725937830314/c9bd161e-c32d-431c-906e-8cbb859bb948.png</hashnode:coverImage></item><item><title><![CDATA[What is a stateful application?]]></title><description><![CDATA[In software applications, the term "stateful" frequently arises, but what does it mean? To clarify this concept, let’s explore it through a practical example: Trello, a popular project management tool. Here’s a Q&A-style article to help you understan...]]></description><link>https://devopsvoyager.hashnode.dev/what-is-a-stateful-application</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/what-is-a-stateful-application</guid><category><![CDATA[#StatefulApplications]]></category><category><![CDATA[Devops]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Fri, 25 Oct 2024 03:30:33 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;p&gt;In software applications, the term &quot;stateful&quot; frequently arises, but what does it mean? To clarify this concept, lets explore it through a practical example: Trello, a popular project management tool. Heres a Q&amp;amp;A-style article to help you understand stateful applications and their implications.&lt;/p&gt;&lt;h3 id=&quot;heading-q-what-is-a-stateful-application&quot;&gt;&lt;strong&gt;Q: What is a stateful application?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; A stateful application maintains state across multiple interactions or sessions. This means the application remembers information from previous interactions and uses it to provide a consistent and personalized experience. Unlike stateless applications, which treat each request independently and dont retain any prior data, stateful applications keep track of user data, preferences, and interactions over time.&lt;/p&gt;&lt;h3 id=&quot;heading-q-can-you-provide-a-real-world-example-of-a-stateful-application&quot;&gt;&lt;strong&gt;Q: Can you provide a real-world example of a stateful application?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Certainly! Trello, a project management tool, is an excellent example of a stateful application. Heres how Trello exemplifies statefulness:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Interaction&lt;/strong&gt;: When you log into Trello, you access a project board that displays lists like &quot;To Do,&quot; &quot;In Progress,&quot; and &quot;Done,&quot; along with various cards within these lists.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stateful Features&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Card Movement&lt;/strong&gt;: Trello remembers this change if you move a card from the &quot;To Do&quot; list to the &quot;In Progress&quot; list. When you return to the application later, the card will still be in the &quot;In Progress&quot; list, reflecting the updates you made previously.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Preferences&lt;/strong&gt;: Trello retains your preferred board view, filter settings, and notification preferences across sessions. This means you dont need to reconfigure these settings each time you log in.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaborative Updates&lt;/strong&gt;: Trello supports real-time collaboration. Changes made by you or your teammates, such as comments or status updates on cards, are instantly visible to everyone working on the board.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-q-how-does-trello-manage-and-preserve-the-state&quot;&gt;&lt;strong&gt;Q: How does Trello manage and preserve the state?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Trello manages state through backend databases that store and synchronize information. These databases keep track of:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Board Structures&lt;/strong&gt;: The layout and lists on each board.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Card Details&lt;/strong&gt;: Information about each card, including its position and any updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Settings&lt;/strong&gt;: Preferences and configurations set by users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-Time Updates&lt;/strong&gt;: Changes made by users are synchronized so that everyone has a consistent and up-to-date view of the project.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This management ensures that all users experience continuity and consistency, regardless of when or where they access Trello.&lt;/p&gt;&lt;h3 id=&quot;heading-q-what-are-the-benefits-and-challenges-of-stateful-applications-like-trello&quot;&gt;&lt;strong&gt;Q: What are the benefits and challenges of stateful applications like Trello?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; &lt;strong&gt;Benefits&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Experience&lt;/strong&gt;: Users experience a more cohesive and personalized interface since the application remembers their previous interactions and settings.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Collaboration&lt;/strong&gt;: Real-time updates and persistent state allow for effective teamwork and coordination, as all changes are immediately visible to all users.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Challenges&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complexity&lt;/strong&gt;: Managing and synchronizing state can add complexity to the application&apos;s design, especially in distributed systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Maintaining state across multiple sessions and ensuring real-time updates requires efficient data handling and performance optimization.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-q-why-is-it-important-to-understand-the-concept-of-stateful-applications&quot;&gt;&lt;strong&gt;Q: Why is it important to understand the concept of stateful applications?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Understanding stateful applications is crucial because it helps in designing and using software that provides a richer, more interactive user experience. It also aids in troubleshooting and optimizing applications, especially those involving complex data management and real-time collaboration.&lt;/p&gt;&lt;p&gt;In summary, Trello illustrates how stateful applications retain user data, preferences, and interactions to deliver a consistent and personalized experience. By remembering and managing state, applications like Trello enhance usability and collaboration, making them invaluable tools for project management and beyond.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;p&gt;In software applications, the term &quot;stateful&quot; frequently arises, but what does it mean? To clarify this concept, lets explore it through a practical example: Trello, a popular project management tool. Heres a Q&amp;amp;A-style article to help you understand stateful applications and their implications.&lt;/p&gt;&lt;h3 id=&quot;heading-q-what-is-a-stateful-application&quot;&gt;&lt;strong&gt;Q: What is a stateful application?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; A stateful application maintains state across multiple interactions or sessions. This means the application remembers information from previous interactions and uses it to provide a consistent and personalized experience. Unlike stateless applications, which treat each request independently and dont retain any prior data, stateful applications keep track of user data, preferences, and interactions over time.&lt;/p&gt;&lt;h3 id=&quot;heading-q-can-you-provide-a-real-world-example-of-a-stateful-application&quot;&gt;&lt;strong&gt;Q: Can you provide a real-world example of a stateful application?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Certainly! Trello, a project management tool, is an excellent example of a stateful application. Heres how Trello exemplifies statefulness:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Interaction&lt;/strong&gt;: When you log into Trello, you access a project board that displays lists like &quot;To Do,&quot; &quot;In Progress,&quot; and &quot;Done,&quot; along with various cards within these lists.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Stateful Features&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Card Movement&lt;/strong&gt;: Trello remembers this change if you move a card from the &quot;To Do&quot; list to the &quot;In Progress&quot; list. When you return to the application later, the card will still be in the &quot;In Progress&quot; list, reflecting the updates you made previously.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Preferences&lt;/strong&gt;: Trello retains your preferred board view, filter settings, and notification preferences across sessions. This means you dont need to reconfigure these settings each time you log in.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaborative Updates&lt;/strong&gt;: Trello supports real-time collaboration. Changes made by you or your teammates, such as comments or status updates on cards, are instantly visible to everyone working on the board.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-q-how-does-trello-manage-and-preserve-the-state&quot;&gt;&lt;strong&gt;Q: How does Trello manage and preserve the state?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Trello manages state through backend databases that store and synchronize information. These databases keep track of:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Board Structures&lt;/strong&gt;: The layout and lists on each board.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Card Details&lt;/strong&gt;: Information about each card, including its position and any updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;User Settings&lt;/strong&gt;: Preferences and configurations set by users.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Real-Time Updates&lt;/strong&gt;: Changes made by users are synchronized so that everyone has a consistent and up-to-date view of the project.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This management ensures that all users experience continuity and consistency, regardless of when or where they access Trello.&lt;/p&gt;&lt;h3 id=&quot;heading-q-what-are-the-benefits-and-challenges-of-stateful-applications-like-trello&quot;&gt;&lt;strong&gt;Q: What are the benefits and challenges of stateful applications like Trello?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; &lt;strong&gt;Benefits&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Seamless Experience&lt;/strong&gt;: Users experience a more cohesive and personalized interface since the application remembers their previous interactions and settings.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Collaboration&lt;/strong&gt;: Real-time updates and persistent state allow for effective teamwork and coordination, as all changes are immediately visible to all users.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Challenges&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complexity&lt;/strong&gt;: Managing and synchronizing state can add complexity to the application&apos;s design, especially in distributed systems.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Performance&lt;/strong&gt;: Maintaining state across multiple sessions and ensuring real-time updates requires efficient data handling and performance optimization.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-q-why-is-it-important-to-understand-the-concept-of-stateful-applications&quot;&gt;&lt;strong&gt;Q: Why is it important to understand the concept of stateful applications?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;A:&lt;/strong&gt; Understanding stateful applications is crucial because it helps in designing and using software that provides a richer, more interactive user experience. It also aids in troubleshooting and optimizing applications, especially those involving complex data management and real-time collaboration.&lt;/p&gt;&lt;p&gt;In summary, Trello illustrates how stateful applications retain user data, preferences, and interactions to deliver a consistent and personalized experience. By remembering and managing state, applications like Trello enhance usability and collaboration, making them invaluable tools for project management and beyond.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725787124825/41880633-2ea5-423d-b421-4fbdac1d00bf.png</hashnode:coverImage></item><item><title><![CDATA[How can you store persistent data for a Kubernetes application running on EKS?]]></title><description><![CDATA[Scenario:
You are deploying a Kubernetes-based web application on Amazon EKS that includes a database for storing user data and configurations. The database needs to maintain its data across pod restarts and re-scheduling, requiring persistent storag...]]></description><link>https://devopsvoyager.hashnode.dev/how-can-you-store-persistent-data-for-a-kubernetes-application-running-on-eks</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/how-can-you-store-persistent-data-for-a-kubernetes-application-running-on-eks</guid><category><![CDATA[AWS]]></category><category><![CDATA[EKS]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[PVC ]]></category><category><![CDATA[pv]]></category><category><![CDATA[storage class]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Thu, 24 Oct 2024 03:30:41 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h3 id=&quot;heading-scenario&quot;&gt;Scenario:&lt;/h3&gt;&lt;p&gt;You are deploying a Kubernetes-based web application on Amazon EKS that includes a database for storing user data and configurations. The database needs to maintain its data across pod restarts and re-scheduling, requiring persistent storage.&lt;/p&gt;&lt;h3 id=&quot;heading-solution-breakdown&quot;&gt;Solution Breakdown:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Choosing the Storage Solution:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;strong&gt;AWS EBS (Elastic Block Store)&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Why EBS?&lt;/strong&gt;: AWS EBS provides block-level storage volumes that are durable and high-performance, suitable for persistent storage needs. EBS volumes can be dynamically provisioned using Kubernetes &lt;code&gt;StorageClass&lt;/code&gt;, making them a good fit for applications requiring reliable storage that persists beyond the lifecycle of individual pods.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting Up Persistent Storage:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define a StorageClass:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A &lt;code&gt;StorageClass&lt;/code&gt; defines the provisioning and configuration parameters for storage in Kubernetes. It specifies the storage provider and characteristics such as performance, encryption, and volume types. For AWS EBS, you can define a &lt;code&gt;StorageClass&lt;/code&gt; to use the EBS CSI (Container Storage Interface) driver.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;        &lt;strong&gt;Example&lt;/strong&gt; &lt;code&gt;StorageClass&lt;/code&gt; YAML (&lt;code&gt;ebs-sc.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;storage.k8s.io/v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;StorageClass&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-sc&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;provisioner:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs.csi.aws.com&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeBindingMode:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;WaitForFirstConsumer&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;parameters:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;csi.storage.k8s.io/fstype:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;xfs&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;io1&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;iopsPerGB:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;50&quot;&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;encrypted:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;true&quot;&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;allowedTopologies:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;matchLabelExpressions:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;key:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;topology.kubernetes.io/zone&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;values:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;us-east-2c&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define a PersistentVolume (PV) and PersistentVolumeClaim (PVC):&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;PersistentVolume (PV)&lt;/strong&gt;: Represents the actual storage resource and defines its attributes. PVs can be either pre-provisioned manually or dynamically provisioned by Kubernetes based on the &lt;code&gt;StorageClass&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;PersistentVolumeClaim (PVC)&lt;/strong&gt;: Requests storage from a &lt;code&gt;StorageClass&lt;/code&gt; and binds to a PV. It specifies the amount of storage and access modes required by your application.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;        &lt;strong&gt;Example PV YAML (&lt;/strong&gt;&lt;code&gt;ebs-pv.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PersistentVolume&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-pv&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;capacity:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;storage:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;10Gi&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;accessModes:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ReadWriteOnce&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;storageClassName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-sc&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;hostPath:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/mnt/data&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;        &lt;strong&gt;Example PVC YAML (&lt;/strong&gt;&lt;code&gt;ebs-pvc.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PersistentVolumeClaim&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-pvc&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;accessModes:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ReadWriteOnce&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;resources:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;requests:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;storage:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;10Gi&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;storageClassName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-sc&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Provisioning&lt;/strong&gt;: If you use a &lt;code&gt;StorageClass&lt;/code&gt; for dynamic provisioning, you typically do not need to manually create &lt;code&gt;PersistentVolume&lt;/code&gt; resources. Kubernetes will automatically create and manage the &lt;code&gt;PersistentVolume&lt;/code&gt; based on the &lt;code&gt;StorageClass&lt;/code&gt; and &lt;code&gt;PersistentVolumeClaim&lt;/code&gt;.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Use PVC in a Pod:&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Modify your pod or deployment manifest to mount the PVC, making the storage available to your application.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;        &lt;strong&gt;Example Deployment YAML (&lt;/strong&gt;&lt;code&gt;app-deployment.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;              &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app-container&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app-image:latest&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;                &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/data&lt;/span&gt;                  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app-storage&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;              &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app-storage&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;persistentVolumeClaim:&lt;/span&gt;                  &lt;span class=&quot;hljs-attr&quot;&gt;claimName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-pvc&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&quot;3&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;StorageClass&lt;/code&gt;: Defines how storage should be dynamically provisioned and configured. It specifies parameters like volume type, filesystem, and encryption.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;PersistentVolume (PV)&lt;/code&gt;: Represents an actual storage resource. When using dynamic provisioning, you do not need to manually create PVs; Kubernetes will handle it based on the &lt;code&gt;StorageClass&lt;/code&gt; and &lt;code&gt;PersistentVolumeClaim&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;PersistentVolumeClaim (PVC)&lt;/code&gt;: Requests storage from a &lt;code&gt;StorageClass&lt;/code&gt; and binds to a PV. It ensures your application gets the storage it needs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Usage&lt;/strong&gt;: Pods mount the storage defined by the PVC to persist data across pod restarts and re-scheduling.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By using a &lt;code&gt;StorageClass&lt;/code&gt; to dynamically provision EBS volumes and defining &lt;code&gt;PersistentVolumeClaim&lt;/code&gt; resources, you ensure that your Kubernetes application on EKS has reliable, scalable, and persistent storage that meets its performance and security needs. If you opt for dynamic provisioning, manual creation of &lt;code&gt;PersistentVolume&lt;/code&gt; resources is optional, as Kubernetes handles this automatically.&lt;/p&gt;&lt;p&gt;Reference:&lt;/p&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes/storageclass&quot;&gt;https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes/storageclass&lt;/a&gt;&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h3 id=&quot;heading-scenario&quot;&gt;Scenario:&lt;/h3&gt;&lt;p&gt;You are deploying a Kubernetes-based web application on Amazon EKS that includes a database for storing user data and configurations. The database needs to maintain its data across pod restarts and re-scheduling, requiring persistent storage.&lt;/p&gt;&lt;h3 id=&quot;heading-solution-breakdown&quot;&gt;Solution Breakdown:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Choosing the Storage Solution:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;strong&gt;AWS EBS (Elastic Block Store)&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Why EBS?&lt;/strong&gt;: AWS EBS provides block-level storage volumes that are durable and high-performance, suitable for persistent storage needs. EBS volumes can be dynamically provisioned using Kubernetes &lt;code&gt;StorageClass&lt;/code&gt;, making them a good fit for applications requiring reliable storage that persists beyond the lifecycle of individual pods.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting Up Persistent Storage:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define a StorageClass:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A &lt;code&gt;StorageClass&lt;/code&gt; defines the provisioning and configuration parameters for storage in Kubernetes. It specifies the storage provider and characteristics such as performance, encryption, and volume types. For AWS EBS, you can define a &lt;code&gt;StorageClass&lt;/code&gt; to use the EBS CSI (Container Storage Interface) driver.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;        &lt;strong&gt;Example&lt;/strong&gt; &lt;code&gt;StorageClass&lt;/code&gt; YAML (&lt;code&gt;ebs-sc.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;storage.k8s.io/v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;StorageClass&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-sc&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;provisioner:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs.csi.aws.com&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeBindingMode:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;WaitForFirstConsumer&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;parameters:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;csi.storage.k8s.io/fstype:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;xfs&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;io1&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;iopsPerGB:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;50&quot;&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;encrypted:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;true&quot;&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;allowedTopologies:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;matchLabelExpressions:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;key:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;topology.kubernetes.io/zone&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;values:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;us-east-2c&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define a PersistentVolume (PV) and PersistentVolumeClaim (PVC):&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;PersistentVolume (PV)&lt;/strong&gt;: Represents the actual storage resource and defines its attributes. PVs can be either pre-provisioned manually or dynamically provisioned by Kubernetes based on the &lt;code&gt;StorageClass&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;PersistentVolumeClaim (PVC)&lt;/strong&gt;: Requests storage from a &lt;code&gt;StorageClass&lt;/code&gt; and binds to a PV. It specifies the amount of storage and access modes required by your application.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;        &lt;strong&gt;Example PV YAML (&lt;/strong&gt;&lt;code&gt;ebs-pv.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PersistentVolume&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-pv&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;capacity:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;storage:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;10Gi&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;accessModes:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ReadWriteOnce&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;storageClassName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-sc&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;hostPath:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/mnt/data&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;        &lt;strong&gt;Example PVC YAML (&lt;/strong&gt;&lt;code&gt;ebs-pvc.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PersistentVolumeClaim&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-pvc&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;accessModes:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ReadWriteOnce&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;resources:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;requests:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;storage:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;10Gi&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;storageClassName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-sc&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Dynamic Provisioning&lt;/strong&gt;: If you use a &lt;code&gt;StorageClass&lt;/code&gt; for dynamic provisioning, you typically do not need to manually create &lt;code&gt;PersistentVolume&lt;/code&gt; resources. Kubernetes will automatically create and manage the &lt;code&gt;PersistentVolume&lt;/code&gt; based on the &lt;code&gt;StorageClass&lt;/code&gt; and &lt;code&gt;PersistentVolumeClaim&lt;/code&gt;.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Use PVC in a Pod:&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Modify your pod or deployment manifest to mount the PVC, making the storage available to your application.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;        &lt;strong&gt;Example Deployment YAML (&lt;/strong&gt;&lt;code&gt;app-deployment.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;              &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app-container&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app-image:latest&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;                &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/data&lt;/span&gt;                  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app-storage&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;              &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app-storage&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;persistentVolumeClaim:&lt;/span&gt;                  &lt;span class=&quot;hljs-attr&quot;&gt;claimName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ebs-pvc&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ol start=&quot;3&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Summary:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;StorageClass&lt;/code&gt;: Defines how storage should be dynamically provisioned and configured. It specifies parameters like volume type, filesystem, and encryption.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;PersistentVolume (PV)&lt;/code&gt;: Represents an actual storage resource. When using dynamic provisioning, you do not need to manually create PVs; Kubernetes will handle it based on the &lt;code&gt;StorageClass&lt;/code&gt; and &lt;code&gt;PersistentVolumeClaim&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;PersistentVolumeClaim (PVC)&lt;/code&gt;: Requests storage from a &lt;code&gt;StorageClass&lt;/code&gt; and binds to a PV. It ensures your application gets the storage it needs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Usage&lt;/strong&gt;: Pods mount the storage defined by the PVC to persist data across pod restarts and re-scheduling.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By using a &lt;code&gt;StorageClass&lt;/code&gt; to dynamically provision EBS volumes and defining &lt;code&gt;PersistentVolumeClaim&lt;/code&gt; resources, you ensure that your Kubernetes application on EKS has reliable, scalable, and persistent storage that meets its performance and security needs. If you opt for dynamic provisioning, manual creation of &lt;code&gt;PersistentVolume&lt;/code&gt; resources is optional, as Kubernetes handles this automatically.&lt;/p&gt;&lt;p&gt;Reference:&lt;/p&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes/storageclass&quot;&gt;https://github.com/kubernetes-sigs/aws-ebs-csi-driver/tree/master/examples/kubernetes/storageclass&lt;/a&gt;&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725383169020/9cee1a74-9d63-4b19-9586-6f5645016485.png</hashnode:coverImage></item><item><title><![CDATA[How do you deploy a web application on AWS using Amazon EKS and expose it to the internet?]]></title><description><![CDATA[Scenario:
You’ve developed a simple web application consisting of a React frontend and a Node.js backend. You want to deploy this application using Kubernetes on AWS, and ensure it is accessible over the internet.
Solution Breakdown:

Choosing the AW...]]></description><link>https://devopsvoyager.hashnode.dev/how-do-you-deploy-a-web-application-on-aws-using-amazon-eks-and-expose-it-to-the-internet</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/how-do-you-deploy-a-web-application-on-aws-using-amazon-eks-and-expose-it-to-the-internet</guid><category><![CDATA[AWS]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[EKS]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Wed, 23 Oct 2024 03:30:49 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h3 id=&quot;heading-scenario&quot;&gt;Scenario:&lt;/h3&gt;&lt;p&gt;Youve developed a simple web application consisting of a React frontend and a Node.js backend. You want to deploy this application using Kubernetes on AWS, and ensure it is accessible over the internet.&lt;/p&gt;&lt;h3 id=&quot;heading-solution-breakdown&quot;&gt;Solution Breakdown:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Choosing the AWS Service:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;strong&gt;Amazon EKS (Elastic Kubernetes Service)&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Why EKS?&lt;/strong&gt;: Amazon EKS is a managed Kubernetes service that simplifies the deployment and management of Kubernetes clusters on AWS. With EKS, AWS handles the management of the Kubernetes control plane, providing high availability, scalability, and integrated security features.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploying Your Application:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an EKS Cluster:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Go to the AWS Management Console and navigate to Amazon EKS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a new EKS cluster by specifying the cluster name, Kubernetes version, and networking settings (VPC, subnets, etc.).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create or select a managed node group which consists of EC2 instances to run your application pods.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure kubectl:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;After creating the cluster, configure &lt;code&gt;kubectl&lt;/code&gt; (the Kubernetes CLI) to interact with your EKS cluster using AWS CLI or &lt;code&gt;aws-iam-authenticator&lt;/code&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prepare and Apply Kubernetes Manifests:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;  &lt;strong&gt;Example Kubernetes Manifests:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backend API Deployment (&lt;/strong&gt;&lt;code&gt;backend-deployment.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;your-docker-repo/backend-api:latest&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;8080&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backend API Service (&lt;/strong&gt;&lt;code&gt;backend-service.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api-service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;8080&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;LoadBalancer&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frontend Deployment (&lt;/strong&gt;&lt;code&gt;frontend-deployment.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;your-docker-repo/frontend:latest&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frontend Service (&lt;/strong&gt;&lt;code&gt;frontend-service.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend-service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3000&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;LoadBalancer&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy to EKS:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use &lt;code&gt;kubectl&lt;/code&gt; to apply the manifests:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl apply -f backend-deployment.yaml  kubectl apply -f backend-service.yaml  kubectl apply -f frontend-deployment.yaml  kubectl apply -f frontend-service.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exposing the Application to the Internet:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frontend Exposure:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The &lt;code&gt;frontend-service&lt;/code&gt; is defined with &lt;code&gt;type: LoadBalancer&lt;/code&gt;. Kubernetes will provision an AWS Elastic Load Balancer (ELB) for this service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;After deployment, retrieve the ELB&apos;s public DNS name using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl get services&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;code&gt;EXTERNAL-IP&lt;/code&gt; field for &lt;code&gt;frontend-service&lt;/code&gt; will show the public DNS name of the ELB. This DNS name allows users to access your web application over the internet.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backend Exposure:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The &lt;code&gt;backend-service&lt;/code&gt; is also of &lt;code&gt;type: LoadBalancer&lt;/code&gt;, but it is generally not exposed directly to the internet. It is intended to be accessed internally by the frontend service. If needed, you can similarly get its external address for testing or other purposes.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-summary&quot;&gt;Summary:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Amazon EKS&lt;/strong&gt;: Create an EKS cluster and configure &lt;code&gt;kubectl&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Application&lt;/strong&gt;: Create and apply Kubernetes manifests for your frontend and backend applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expose to the Internet&lt;/strong&gt;: Use a LoadBalancer Service type for the front end to provision an AWS Elastic Load Balancer (ELB), making the application accessible over the Internet.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By following these steps, you effectively leverage Amazon EKS to manage your Kubernetes deployment and AWS services to ensure your application is scalable and accessible to users.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h3 id=&quot;heading-scenario&quot;&gt;Scenario:&lt;/h3&gt;&lt;p&gt;Youve developed a simple web application consisting of a React frontend and a Node.js backend. You want to deploy this application using Kubernetes on AWS, and ensure it is accessible over the internet.&lt;/p&gt;&lt;h3 id=&quot;heading-solution-breakdown&quot;&gt;Solution Breakdown:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Choosing the AWS Service:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;strong&gt;Amazon EKS (Elastic Kubernetes Service)&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Why EKS?&lt;/strong&gt;: Amazon EKS is a managed Kubernetes service that simplifies the deployment and management of Kubernetes clusters on AWS. With EKS, AWS handles the management of the Kubernetes control plane, providing high availability, scalability, and integrated security features.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploying Your Application:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an EKS Cluster:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Go to the AWS Management Console and navigate to Amazon EKS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a new EKS cluster by specifying the cluster name, Kubernetes version, and networking settings (VPC, subnets, etc.).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create or select a managed node group which consists of EC2 instances to run your application pods.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure kubectl:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;After creating the cluster, configure &lt;code&gt;kubectl&lt;/code&gt; (the Kubernetes CLI) to interact with your EKS cluster using AWS CLI or &lt;code&gt;aws-iam-authenticator&lt;/code&gt;.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prepare and Apply Kubernetes Manifests:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;  &lt;strong&gt;Example Kubernetes Manifests:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backend API Deployment (&lt;/strong&gt;&lt;code&gt;backend-deployment.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;your-docker-repo/backend-api:latest&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;8080&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backend API Service (&lt;/strong&gt;&lt;code&gt;backend-service.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api-service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend-api&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;8080&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;LoadBalancer&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frontend Deployment (&lt;/strong&gt;&lt;code&gt;frontend-deployment.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;your-docker-repo/frontend:latest&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frontend Service (&lt;/strong&gt;&lt;code&gt;frontend-service.yaml&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend-service&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3000&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;LoadBalancer&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy to EKS:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use &lt;code&gt;kubectl&lt;/code&gt; to apply the manifests:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl apply -f backend-deployment.yaml  kubectl apply -f backend-service.yaml  kubectl apply -f frontend-deployment.yaml  kubectl apply -f frontend-service.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exposing the Application to the Internet:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Frontend Exposure:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The &lt;code&gt;frontend-service&lt;/code&gt; is defined with &lt;code&gt;type: LoadBalancer&lt;/code&gt;. Kubernetes will provision an AWS Elastic Load Balancer (ELB) for this service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;After deployment, retrieve the ELB&apos;s public DNS name using:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl get services&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;The &lt;code&gt;EXTERNAL-IP&lt;/code&gt; field for &lt;code&gt;frontend-service&lt;/code&gt; will show the public DNS name of the ELB. This DNS name allows users to access your web application over the internet.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backend Exposure:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;The &lt;code&gt;backend-service&lt;/code&gt; is also of &lt;code&gt;type: LoadBalancer&lt;/code&gt;, but it is generally not exposed directly to the internet. It is intended to be accessed internally by the frontend service. If needed, you can similarly get its external address for testing or other purposes.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-summary&quot;&gt;Summary:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Amazon EKS&lt;/strong&gt;: Create an EKS cluster and configure &lt;code&gt;kubectl&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Application&lt;/strong&gt;: Create and apply Kubernetes manifests for your frontend and backend applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Expose to the Internet&lt;/strong&gt;: Use a LoadBalancer Service type for the front end to provision an AWS Elastic Load Balancer (ELB), making the application accessible over the Internet.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;By following these steps, you effectively leverage Amazon EKS to manage your Kubernetes deployment and AWS services to ensure your application is scalable and accessible to users.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725381226275/672d4661-58ac-4c7c-823f-f5803a7ddf86.png</hashnode:coverImage></item><item><title><![CDATA[How do you manage Kubernetes cluster upgrades on Amazon EKS?]]></title><description><![CDATA[Upgrading a Kubernetes cluster on Amazon EKS (Elastic Kubernetes Service) involves updating both the control plane and the worker nodes to a new Kubernetes version. Managing upgrades carefully is crucial to ensuring minimal downtime and maintaining t...]]></description><link>https://devopsvoyager.hashnode.dev/how-do-you-manage-kubernetes-cluster-upgrades-on-amazon-eks</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/how-do-you-manage-kubernetes-cluster-upgrades-on-amazon-eks</guid><category><![CDATA[eks upgrade]]></category><category><![CDATA[EKS]]></category><category><![CDATA[EKS cluster]]></category><category><![CDATA[AWS]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Kubernetes]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Tue, 22 Oct 2024 03:30:10 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;p&gt;Upgrading a Kubernetes cluster on Amazon EKS (Elastic Kubernetes Service) involves updating both the control plane and the worker nodes to a new Kubernetes version. Managing upgrades carefully is crucial to ensuring minimal downtime and maintaining the stability of your applications. Here&apos;s a detailed guide on the process and best practices for upgrading an EKS cluster:&lt;/p&gt;&lt;h3 id=&quot;heading-step-by-step-process-for-upgrading-an-eks-cluster&quot;&gt;Step-by-Step Process for Upgrading an EKS Cluster&lt;/h3&gt;&lt;h4 id=&quot;heading-1-preparation-and-planning&quot;&gt;1. &lt;strong&gt;Preparation and Planning&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Review Release Notes:&lt;/strong&gt; Check the &lt;a target=&quot;_blank&quot; href=&quot;https://kubernetes.io/docs/setup/release/notes/&quot;&gt;Kubernetes release notes&lt;/a&gt; and &lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html&quot;&gt;EKS documentation&lt;/a&gt; for the target version to understand new features, deprecations, and changes that might impact your workloads.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Compatibility:&lt;/strong&gt; Ensure that your add-ons, tools (e.g., Helm, kubectl), and custom resources are compatible with the new Kubernetes version.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Back Up Cluster Data:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Take a backup of your application data, including any stateful data stored in persistent volumes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Export current cluster configurations using &lt;code&gt;kubectl get &amp;lt;resource&amp;gt; -o yaml &amp;gt; &amp;lt;resource&amp;gt;.yaml&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-2-upgrade-the-eks-control-plane&quot;&gt;2. &lt;strong&gt;Upgrade the EKS Control Plane&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use AWS Management Console, AWS CLI, or eksctl:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using AWS Management Console:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Go to the Amazon EKS console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select your cluster and click on &quot;Update now&quot; in the Kubernetes version section.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose the target Kubernetes version and start the update process.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using AWS CLI:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  aws eks update-cluster-version --name &amp;lt;cluster-name&amp;gt; --kubernetes-version &amp;lt;new-version&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using eksctl:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  eksctl upgrade cluster --name &amp;lt;cluster-name&amp;gt; --version &amp;lt;new-version&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Control Plane Upgrade:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Confirm that the control plane is upgraded by checking the cluster version:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl get nodes&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-3-upgrade-managed-node-groups-or-self-managed-nodes&quot;&gt;3. &lt;strong&gt;Upgrade Managed Node Groups or Self-Managed Nodes&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade Managed Node Groups:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Node Group Version:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In the EKS console, navigate to the &quot;Compute&quot; tab, select your managed node group, and click &quot;Update version.&quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose the Kubernetes version that matches your control plane.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rolling Update:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;EKS performs a rolling update, creating new nodes with the updated version and draining old nodes one by one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that new nodes are ready and joined the cluster before old nodes are terminated.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade Self-Managed Nodes:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Launch New AMIs:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use the latest EKS optimized AMI for the target Kubernetes version.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Update your autoscaling group to use the new AMI ID and set the desired capacity to a higher number to start creating new nodes.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Drain Old Nodes:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Once new nodes are available, gracefully drain old nodes to ensure that workloads are shifted properly:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl drain &amp;lt;old-node-name&amp;gt; --ignore-daemonsets --delete-emptydir-data&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terminate Old Nodes:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;After draining, you can terminate the old nodes manually or reduce the autoscaling group&apos;s desired capacity.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-4-upgrade-add-ons-and-custom-resources&quot;&gt;4. &lt;strong&gt;Upgrade Add-ons and Custom Resources&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade EKS Add-ons:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Upgrade EKS add-ons like CoreDNS, kube-proxy, and the AWS VPC CNI plugin to versions compatible with the new Kubernetes version.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use AWS CLI or eksctl to update add-ons:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  eksctl utils update-kube-proxy --cluster &amp;lt;cluster-name&amp;gt; --approve  eksctl utils update-coredns --cluster &amp;lt;cluster-name&amp;gt; --approve  eksctl utils update-aws-node --cluster &amp;lt;cluster-name&amp;gt; --approve&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade Custom Add-ons:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update custom add-ons like Prometheus, Grafana, or Ingress controllers using Helm or kubectl to ensure compatibility.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-5-test-and-validate&quot;&gt;5. &lt;strong&gt;Test and Validate&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run Application Tests:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy test workloads or run smoke tests to validate that applications are functioning correctly after the upgrade.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Logs and Metrics:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use monitoring tools (e.g., CloudWatch, Prometheus) to check for any errors or performance issues during and after the upgrade.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-6-roll-back-if-necessary&quot;&gt;6. &lt;strong&gt;Roll Back if Necessary&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Revert Control Plane:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If there are major issues, consider rolling back by restoring from backups or re-creating the cluster with the previous Kubernetes version.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Revert Node Groups:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;For managed node groups, downgrade the version or roll back to a previous AMI version for self-managed nodes.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-best-practices-for-minimal-downtime&quot;&gt;Best Practices for Minimal Downtime&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Managed Node Groups:&lt;/strong&gt; Leveraging managed node groups simplifies the upgrade process with automated rolling updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Perform Upgrades During Maintenance Windows:&lt;/strong&gt; Schedule upgrades during low-traffic periods to minimize the impact on production workloads.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Blue-Green or Canary Deployments:&lt;/strong&gt; For critical services, consider using Blue-Green or Canary deployments to test the upgraded environment before fully committing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Health and Roll Back Quickly if Needed:&lt;/strong&gt; Continuously monitor the health of the cluster and be prepared to roll back if there are critical issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You can upgrade your EKS cluster with minimal downtime, ensuring a smooth transition to the new Kubernetes version.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html&lt;/a&gt;&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;p&gt;Upgrading a Kubernetes cluster on Amazon EKS (Elastic Kubernetes Service) involves updating both the control plane and the worker nodes to a new Kubernetes version. Managing upgrades carefully is crucial to ensuring minimal downtime and maintaining the stability of your applications. Here&apos;s a detailed guide on the process and best practices for upgrading an EKS cluster:&lt;/p&gt;&lt;h3 id=&quot;heading-step-by-step-process-for-upgrading-an-eks-cluster&quot;&gt;Step-by-Step Process for Upgrading an EKS Cluster&lt;/h3&gt;&lt;h4 id=&quot;heading-1-preparation-and-planning&quot;&gt;1. &lt;strong&gt;Preparation and Planning&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Review Release Notes:&lt;/strong&gt; Check the &lt;a target=&quot;_blank&quot; href=&quot;https://kubernetes.io/docs/setup/release/notes/&quot;&gt;Kubernetes release notes&lt;/a&gt; and &lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/kubernetes-versions.html&quot;&gt;EKS documentation&lt;/a&gt; for the target version to understand new features, deprecations, and changes that might impact your workloads.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Compatibility:&lt;/strong&gt; Ensure that your add-ons, tools (e.g., Helm, kubectl), and custom resources are compatible with the new Kubernetes version.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Back Up Cluster Data:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Take a backup of your application data, including any stateful data stored in persistent volumes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Export current cluster configurations using &lt;code&gt;kubectl get &amp;lt;resource&amp;gt; -o yaml &amp;gt; &amp;lt;resource&amp;gt;.yaml&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-2-upgrade-the-eks-control-plane&quot;&gt;2. &lt;strong&gt;Upgrade the EKS Control Plane&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use AWS Management Console, AWS CLI, or eksctl:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using AWS Management Console:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Go to the Amazon EKS console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select your cluster and click on &quot;Update now&quot; in the Kubernetes version section.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose the target Kubernetes version and start the update process.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using AWS CLI:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  aws eks update-cluster-version --name &amp;lt;cluster-name&amp;gt; --kubernetes-version &amp;lt;new-version&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using eksctl:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  eksctl upgrade cluster --name &amp;lt;cluster-name&amp;gt; --version &amp;lt;new-version&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Control Plane Upgrade:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Confirm that the control plane is upgraded by checking the cluster version:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl get nodes&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-3-upgrade-managed-node-groups-or-self-managed-nodes&quot;&gt;3. &lt;strong&gt;Upgrade Managed Node Groups or Self-Managed Nodes&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade Managed Node Groups:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update Node Group Version:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In the EKS console, navigate to the &quot;Compute&quot; tab, select your managed node group, and click &quot;Update version.&quot;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Choose the Kubernetes version that matches your control plane.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rolling Update:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;EKS performs a rolling update, creating new nodes with the updated version and draining old nodes one by one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that new nodes are ready and joined the cluster before old nodes are terminated.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade Self-Managed Nodes:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Launch New AMIs:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use the latest EKS optimized AMI for the target Kubernetes version.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Update your autoscaling group to use the new AMI ID and set the desired capacity to a higher number to start creating new nodes.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Drain Old Nodes:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Once new nodes are available, gracefully drain old nodes to ensure that workloads are shifted properly:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl drain &amp;lt;old-node-name&amp;gt; --ignore-daemonsets --delete-emptydir-data&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Terminate Old Nodes:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;After draining, you can terminate the old nodes manually or reduce the autoscaling group&apos;s desired capacity.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-4-upgrade-add-ons-and-custom-resources&quot;&gt;4. &lt;strong&gt;Upgrade Add-ons and Custom Resources&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade EKS Add-ons:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Upgrade EKS add-ons like CoreDNS, kube-proxy, and the AWS VPC CNI plugin to versions compatible with the new Kubernetes version.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Use AWS CLI or eksctl to update add-ons:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  eksctl utils update-kube-proxy --cluster &amp;lt;cluster-name&amp;gt; --approve  eksctl utils update-coredns --cluster &amp;lt;cluster-name&amp;gt; --approve  eksctl utils update-aws-node --cluster &amp;lt;cluster-name&amp;gt; --approve&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Upgrade Custom Add-ons:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update custom add-ons like Prometheus, Grafana, or Ingress controllers using Helm or kubectl to ensure compatibility.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-5-test-and-validate&quot;&gt;5. &lt;strong&gt;Test and Validate&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run Application Tests:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy test workloads or run smoke tests to validate that applications are functioning correctly after the upgrade.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Logs and Metrics:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use monitoring tools (e.g., CloudWatch, Prometheus) to check for any errors or performance issues during and after the upgrade.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-6-roll-back-if-necessary&quot;&gt;6. &lt;strong&gt;Roll Back if Necessary&lt;/strong&gt;&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Revert Control Plane:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;If there are major issues, consider rolling back by restoring from backups or re-creating the cluster with the previous Kubernetes version.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Revert Node Groups:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;For managed node groups, downgrade the version or roll back to a previous AMI version for self-managed nodes.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-best-practices-for-minimal-downtime&quot;&gt;Best Practices for Minimal Downtime&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Managed Node Groups:&lt;/strong&gt; Leveraging managed node groups simplifies the upgrade process with automated rolling updates.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Perform Upgrades During Maintenance Windows:&lt;/strong&gt; Schedule upgrades during low-traffic periods to minimize the impact on production workloads.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use Blue-Green or Canary Deployments:&lt;/strong&gt; For critical services, consider using Blue-Green or Canary deployments to test the upgraded environment before fully committing.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Health and Roll Back Quickly if Needed:&lt;/strong&gt; Continuously monitor the health of the cluster and be prepared to roll back if there are critical issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;You can upgrade your EKS cluster with minimal downtime, ensuring a smooth transition to the new Kubernetes version.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Reference:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/update-cluster.html&lt;/a&gt;&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725377123430/7da4ccd1-6df5-4a89-8447-84b58674cac5.png</hashnode:coverImage></item><item><title><![CDATA[Multi-AZ EKS Cluster Setup with Service for Pod Communication Verification]]></title><description><![CDATA[Introduction
To create an Amazon EKS (Elastic Kubernetes Service) cluster in a Multi-AZ (Availability Zone) configuration and ensure that pods can communicate with each other across different AZs, you need to follow a detailed step-by-step process. T...]]></description><link>https://devopsvoyager.hashnode.dev/multi-az-eks-cluster-setup-with-service-for-pod-communication-verification</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/multi-az-eks-cluster-setup-with-service-for-pod-communication-verification</guid><category><![CDATA[EKS]]></category><category><![CDATA[EKS cluster]]></category><category><![CDATA[eksctl]]></category><category><![CDATA[AWS]]></category><category><![CDATA[aws cli]]></category><category><![CDATA[awscli]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[kubernetes-pods]]></category><category><![CDATA[k8s]]></category><category><![CDATA[#k8scluster]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Mon, 21 Oct 2024 03:30:33 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;To create an Amazon EKS (Elastic Kubernetes Service) cluster in a Multi-AZ (Availability Zone) configuration and ensure that pods can communicate with each other across different AZs, you need to follow a detailed step-by-step process. This involves setting up an EKS cluster across multiple AZs, deploying an example application, and verifying cross-pod communication. This setup will also demonstrate high availability, resilience, and redundancy across different AZs.&lt;/p&gt;&lt;h4 id=&quot;heading-step-1-prerequisites&quot;&gt;&lt;strong&gt;Step 1: Prerequisites&lt;/strong&gt;&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS Account&lt;/strong&gt;: Ensure you have an AWS account with sufficient permissions to create and manage EKS resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS CLI&lt;/strong&gt;: Install the AWS CLI and configure it with your AWS credentials.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; aws configure&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;kubectl&lt;/strong&gt;: Install &lt;code&gt;kubectl&lt;/code&gt; to interact with the Kubernetes cluster.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -LO &lt;span class=&quot;hljs-string&quot;&gt;&quot;https://dl.k8s.io/release/&lt;span class=&quot;hljs-subst&quot;&gt;$(curl -L -s https://dl.k8s.io/release/stable.txt)&lt;/span&gt;/bin/linux/amd64/kubectl&quot;&lt;/span&gt; chmod +x kubectl sudo mv kubectl /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin/&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;eksctl&lt;/strong&gt;: Install &lt;code&gt;eksctl&lt;/code&gt;, a command-line tool for managing EKS clusters.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl --silent --location &lt;span class=&quot;hljs-string&quot;&gt;&quot;https://github.com/weaveworks/eksctl/releases/download/0.140.0/eksctl_&lt;span class=&quot;hljs-subst&quot;&gt;$(uname -s)&lt;/span&gt;_&lt;span class=&quot;hljs-subst&quot;&gt;$(uname -m)&lt;/span&gt;.tar.gz&quot;&lt;/span&gt; | tar xz -C /tmp sudo mv /tmp/eksctl /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-2-create-an-eks-cluster-across-multiple-availability-zones&quot;&gt;&lt;strong&gt;Step 2: Create an EKS Cluster Across Multiple Availability Zones&lt;/strong&gt;&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create the EKS Cluster using&lt;/strong&gt; &lt;code&gt;eksctl&lt;/code&gt;:&lt;/p&gt;&lt;p&gt; The following command creates an EKS cluster named &lt;code&gt;multi-az-cluster&lt;/code&gt; with nodes distributed across three different AZs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; eksctl create cluster \   --name multi-az-cluster \   --region ap-northeast-1 \   --zones ap-northeast-1a,ap-northeast-1d \   --nodegroup-name multi-az-nodes \   --node-type t2.micro \   --nodes 2 \   --nodes-min 2 \   --nodes-max 4&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--region ap-northeast-1&lt;/code&gt;: Specifies the AWS region.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--zones ap-northeast-1a,ap-northeast-1d&lt;/code&gt;: Specifies the AZs for the cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--nodegroup-name multi-az-nodes&lt;/code&gt;: Names the node group.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--nodes 2&lt;/code&gt;: Specifies the initial number of nodes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--nodes-min 2&lt;/code&gt; and &lt;code&gt;--nodes-max 4&lt;/code&gt; : Configures the autoscaling range for the node group.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;After applying the above command you can see the output like this:&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;    &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020197000/4ab769f1-18ce-47f6-984d-04bef9efd966.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ol start=&quot;2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Cluster Creation&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Once the cluster is created, verify its status:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; eksctl get cluster --name multi-az-cluster&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Check the nodes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get nodes --show-labels&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; This command will display the nodes along with their AZ labels.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-3-deploy-an-example-application-and-service&quot;&gt;&lt;strong&gt;Step 3: Deploy an Example Application and Service&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;To test pod-to-pod communication across AZs, we&apos;ll deploy a simple &lt;strong&gt;nginx&lt;/strong&gt; application with multiple replicas and create a Kubernetes Service to expose these pods.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Deployment YAML File&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Create a file named &lt;code&gt;nginx-deployment.yaml&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt; &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx-deployment&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;affinity:&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;podAntiAffinity:&lt;/span&gt;           &lt;span class=&quot;hljs-attr&quot;&gt;requiredDuringSchedulingIgnoredDuringExecution:&lt;/span&gt;             &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;labelSelector:&lt;/span&gt;                 &lt;span class=&quot;hljs-attr&quot;&gt;matchExpressions:&lt;/span&gt;                   &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;key:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app&lt;/span&gt;                     &lt;span class=&quot;hljs-attr&quot;&gt;operator:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;In&lt;/span&gt;                     &lt;span class=&quot;hljs-attr&quot;&gt;values:&lt;/span&gt;                       &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;               &lt;span class=&quot;hljs-attr&quot;&gt;topologyKey:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;topology.kubernetes.io/zone&quot;&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;       &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx:latest&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;         &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Affinity Rules&lt;/strong&gt;: The &lt;code&gt;podAntiAffinity&lt;/code&gt; rule ensures that the nginx pods are spread across different AZs for high availability.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Service YAML File&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Create a file named &lt;code&gt;nginx-service.yaml&lt;/code&gt; to expose the &lt;code&gt;nginx&lt;/code&gt; pods.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt; &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx-service&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ClusterIP&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;kind: Service&lt;/code&gt;: Defines the Kubernetes Service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;selector&lt;/code&gt;: Matches the &lt;code&gt;nginx&lt;/code&gt; pods created by the deployment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;type: ClusterIP&lt;/code&gt;: Creates an internal service within the cluster that other pods can access.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Application and Service&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Apply the deployment and service to the cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl apply -f nginx-deployment.yaml kubectl apply -f nginx-service.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Deployment and Service&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Check that the pods are running and spread across different AZs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get pods -o wide&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Check the service status and get its Cluster IP:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get svc&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; You should see an entry for &lt;code&gt;nginx-service&lt;/code&gt; with its internal &lt;code&gt;ClusterIP&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020467598/c68ebc30-62bd-4ec0-a932-86e90b68c7f7.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h4 id=&quot;heading-step-4-verify-pod-communication-across-availability-zones&quot;&gt;&lt;strong&gt;Step 4: Verify Pod Communication Across Availability Zones&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;To ensure that pods can communicate across AZs, we&apos;ll use a &lt;code&gt;busybox&lt;/code&gt; pod to test communication with the &lt;code&gt;nginx&lt;/code&gt; pods.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy a&lt;/strong&gt; &lt;code&gt;busybox&lt;/code&gt; Pod:&lt;/p&gt;&lt;p&gt; Run the following command to create a &lt;code&gt;busybox&lt;/code&gt; pod:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl run busybox --image=busybox --restart=Never -- sleep 3600&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; This pod will run for 3600 seconds (1 hour) to allow you time to perform the communication test.&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020523430/8492d978-bd82-454d-91d8-c022fa08aa9c.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test Communication with Nginx Pods via the Service&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Use the &lt;code&gt;kubectl exec&lt;/code&gt; command to log into the &lt;code&gt;busybox&lt;/code&gt; pod and test communication with the &lt;code&gt;nginx&lt;/code&gt; service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl &lt;span class=&quot;hljs-built_in&quot;&gt;exec&lt;/span&gt; -it busybox -- /bin/sh&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Inside the &lt;code&gt;busybox&lt;/code&gt; pod, test communication with the &lt;code&gt;nginx&lt;/code&gt; service by its service name, there are multiple ways to do it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; wget --spider --timeout=1 nginx-service wget --spider --timeout=1 http://&amp;lt;nginx-pod-ip&amp;gt; wget --spider --timeout=1 http://nginx-service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; If the service is reachable, you should get a response indicating that the service is available.&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020668272/dbae87f7-8c8a-48d1-9df9-9555b70b839c.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-5-verify-high-availability-of-the-eks-cluster&quot;&gt;&lt;strong&gt;Step 5: Verify High Availability of the EKS Cluster&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;To ensure the EKS cluster is highly available across multiple AZs:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Node Availability&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Verify that your nodes are running in different AZs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get nodes --show-labels&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Look for the &lt;a target=&quot;_blank&quot; href=&quot;http://topology.kubernetes.io/zone&quot;&gt;&lt;code&gt;topology.kubernetes.io/zone&lt;/code&gt;&lt;/a&gt; label to confirm nodes are distributed across AZs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simulate an AZ Failure&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Simulate a failure by manually terminating an instance in one AZ through the AWS Management Console.&lt;/p&gt;&lt;p&gt; &lt;strong&gt;Monitor Pod Rescheduling&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Use the following command to monitor the pods:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get pods -o wide --watch&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Kubernetes should reschedule the pods from the terminated instance to the remaining healthy nodes in other AZs. You can see the activity in the below images:&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020759731/dd5ca49d-63f5-4dd7-a938-85a69739156e.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020770104/a33c6385-05b6-4f38-b0e3-53ec8c938dc6.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020786324/bf8b901a-f16b-49df-ac08-6f47fc575b91.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020793724/d0015603-2e71-440d-bccb-dc2370689021.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Application Availability&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Confirm that the application is still available by accessing the Nginx service through a &lt;code&gt;LoadBalancer&lt;/code&gt; or &lt;code&gt;NodePort&lt;/code&gt;.&lt;/p&gt;&lt;p&gt; If you&apos;ve set up a service with a &lt;code&gt;LoadBalancer&lt;/code&gt; type, you can get the external IP and check access:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get svc&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Access the external IP in your browser to verify that the application is still accessible.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020904117/7cbfa0fb-10fe-44a4-a850-fc2c5cdbb452.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h4 id=&quot;heading-step-6-clean-up-resources&quot;&gt;&lt;strong&gt;Step 6: Clean Up Resources&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;Once you have verified the communication and high availability, clean up the resources to avoid unnecessary charges:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;eksctl delete cluster --name multi-az-cluster&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;By following these updated steps, you&apos;ve created an EKS cluster across multiple Availability Zones, deployed an example application, and verified that pods can communicate across AZs using a Kubernetes Service, ensuring high availability and resilience. This setup helps maintain service continuity even when failures occur in one AZ.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;To create an Amazon EKS (Elastic Kubernetes Service) cluster in a Multi-AZ (Availability Zone) configuration and ensure that pods can communicate with each other across different AZs, you need to follow a detailed step-by-step process. This involves setting up an EKS cluster across multiple AZs, deploying an example application, and verifying cross-pod communication. This setup will also demonstrate high availability, resilience, and redundancy across different AZs.&lt;/p&gt;&lt;h4 id=&quot;heading-step-1-prerequisites&quot;&gt;&lt;strong&gt;Step 1: Prerequisites&lt;/strong&gt;&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS Account&lt;/strong&gt;: Ensure you have an AWS account with sufficient permissions to create and manage EKS resources.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS CLI&lt;/strong&gt;: Install the AWS CLI and configure it with your AWS credentials.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; aws configure&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;kubectl&lt;/strong&gt;: Install &lt;code&gt;kubectl&lt;/code&gt; to interact with the Kubernetes cluster.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -LO &lt;span class=&quot;hljs-string&quot;&gt;&quot;https://dl.k8s.io/release/&lt;span class=&quot;hljs-subst&quot;&gt;$(curl -L -s https://dl.k8s.io/release/stable.txt)&lt;/span&gt;/bin/linux/amd64/kubectl&quot;&lt;/span&gt; chmod +x kubectl sudo mv kubectl /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin/&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;eksctl&lt;/strong&gt;: Install &lt;code&gt;eksctl&lt;/code&gt;, a command-line tool for managing EKS clusters.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl --silent --location &lt;span class=&quot;hljs-string&quot;&gt;&quot;https://github.com/weaveworks/eksctl/releases/download/0.140.0/eksctl_&lt;span class=&quot;hljs-subst&quot;&gt;$(uname -s)&lt;/span&gt;_&lt;span class=&quot;hljs-subst&quot;&gt;$(uname -m)&lt;/span&gt;.tar.gz&quot;&lt;/span&gt; | tar xz -C /tmp sudo mv /tmp/eksctl /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-2-create-an-eks-cluster-across-multiple-availability-zones&quot;&gt;&lt;strong&gt;Step 2: Create an EKS Cluster Across Multiple Availability Zones&lt;/strong&gt;&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create the EKS Cluster using&lt;/strong&gt; &lt;code&gt;eksctl&lt;/code&gt;:&lt;/p&gt;&lt;p&gt; The following command creates an EKS cluster named &lt;code&gt;multi-az-cluster&lt;/code&gt; with nodes distributed across three different AZs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; eksctl create cluster \   --name multi-az-cluster \   --region ap-northeast-1 \   --zones ap-northeast-1a,ap-northeast-1d \   --nodegroup-name multi-az-nodes \   --node-type t2.micro \   --nodes 2 \   --nodes-min 2 \   --nodes-max 4&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--region ap-northeast-1&lt;/code&gt;: Specifies the AWS region.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--zones ap-northeast-1a,ap-northeast-1d&lt;/code&gt;: Specifies the AZs for the cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--nodegroup-name multi-az-nodes&lt;/code&gt;: Names the node group.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--nodes 2&lt;/code&gt;: Specifies the initial number of nodes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;--nodes-min 2&lt;/code&gt; and &lt;code&gt;--nodes-max 4&lt;/code&gt; : Configures the autoscaling range for the node group.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;After applying the above command you can see the output like this:&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;    &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020197000/4ab769f1-18ce-47f6-984d-04bef9efd966.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ol start=&quot;2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Cluster Creation&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Once the cluster is created, verify its status:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; eksctl get cluster --name multi-az-cluster&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Check the nodes:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get nodes --show-labels&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; This command will display the nodes along with their AZ labels.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-3-deploy-an-example-application-and-service&quot;&gt;&lt;strong&gt;Step 3: Deploy an Example Application and Service&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;To test pod-to-pod communication across AZs, we&apos;ll deploy a simple &lt;strong&gt;nginx&lt;/strong&gt; application with multiple replicas and create a Kubernetes Service to expose these pods.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Deployment YAML File&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Create a file named &lt;code&gt;nginx-deployment.yaml&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt; &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx-deployment&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;4&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;affinity:&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;podAntiAffinity:&lt;/span&gt;           &lt;span class=&quot;hljs-attr&quot;&gt;requiredDuringSchedulingIgnoredDuringExecution:&lt;/span&gt;             &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;labelSelector:&lt;/span&gt;                 &lt;span class=&quot;hljs-attr&quot;&gt;matchExpressions:&lt;/span&gt;                   &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;key:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app&lt;/span&gt;                     &lt;span class=&quot;hljs-attr&quot;&gt;operator:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;In&lt;/span&gt;                     &lt;span class=&quot;hljs-attr&quot;&gt;values:&lt;/span&gt;                       &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;               &lt;span class=&quot;hljs-attr&quot;&gt;topologyKey:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;topology.kubernetes.io/zone&quot;&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;       &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx:latest&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;         &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Affinity Rules&lt;/strong&gt;: The &lt;code&gt;podAntiAffinity&lt;/code&gt; rule ensures that the nginx pods are spread across different AZs for high availability.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Service YAML File&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Create a file named &lt;code&gt;nginx-service.yaml&lt;/code&gt; to expose the &lt;code&gt;nginx&lt;/code&gt; pods.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt; &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx-service&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ClusterIP&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;kind: Service&lt;/code&gt;: Defines the Kubernetes Service.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;selector&lt;/code&gt;: Matches the &lt;code&gt;nginx&lt;/code&gt; pods created by the deployment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;code&gt;type: ClusterIP&lt;/code&gt;: Creates an internal service within the cluster that other pods can access.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Application and Service&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Apply the deployment and service to the cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl apply -f nginx-deployment.yaml kubectl apply -f nginx-service.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Deployment and Service&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Check that the pods are running and spread across different AZs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get pods -o wide&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Check the service status and get its Cluster IP:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get svc&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; You should see an entry for &lt;code&gt;nginx-service&lt;/code&gt; with its internal &lt;code&gt;ClusterIP&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020467598/c68ebc30-62bd-4ec0-a932-86e90b68c7f7.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h4 id=&quot;heading-step-4-verify-pod-communication-across-availability-zones&quot;&gt;&lt;strong&gt;Step 4: Verify Pod Communication Across Availability Zones&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;To ensure that pods can communicate across AZs, we&apos;ll use a &lt;code&gt;busybox&lt;/code&gt; pod to test communication with the &lt;code&gt;nginx&lt;/code&gt; pods.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy a&lt;/strong&gt; &lt;code&gt;busybox&lt;/code&gt; Pod:&lt;/p&gt;&lt;p&gt; Run the following command to create a &lt;code&gt;busybox&lt;/code&gt; pod:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl run busybox --image=busybox --restart=Never -- sleep 3600&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; This pod will run for 3600 seconds (1 hour) to allow you time to perform the communication test.&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020523430/8492d978-bd82-454d-91d8-c022fa08aa9c.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Test Communication with Nginx Pods via the Service&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Use the &lt;code&gt;kubectl exec&lt;/code&gt; command to log into the &lt;code&gt;busybox&lt;/code&gt; pod and test communication with the &lt;code&gt;nginx&lt;/code&gt; service:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl &lt;span class=&quot;hljs-built_in&quot;&gt;exec&lt;/span&gt; -it busybox -- /bin/sh&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Inside the &lt;code&gt;busybox&lt;/code&gt; pod, test communication with the &lt;code&gt;nginx&lt;/code&gt; service by its service name, there are multiple ways to do it:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; wget --spider --timeout=1 nginx-service wget --spider --timeout=1 http://&amp;lt;nginx-pod-ip&amp;gt; wget --spider --timeout=1 http://nginx-service&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; If the service is reachable, you should get a response indicating that the service is available.&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020668272/dbae87f7-8c8a-48d1-9df9-9555b70b839c.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-5-verify-high-availability-of-the-eks-cluster&quot;&gt;&lt;strong&gt;Step 5: Verify High Availability of the EKS Cluster&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;To ensure the EKS cluster is highly available across multiple AZs:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Node Availability&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Verify that your nodes are running in different AZs:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get nodes --show-labels&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Look for the &lt;a target=&quot;_blank&quot; href=&quot;http://topology.kubernetes.io/zone&quot;&gt;&lt;code&gt;topology.kubernetes.io/zone&lt;/code&gt;&lt;/a&gt; label to confirm nodes are distributed across AZs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simulate an AZ Failure&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Simulate a failure by manually terminating an instance in one AZ through the AWS Management Console.&lt;/p&gt;&lt;p&gt; &lt;strong&gt;Monitor Pod Rescheduling&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Use the following command to monitor the pods:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get pods -o wide --watch&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Kubernetes should reschedule the pods from the terminated instance to the remaining healthy nodes in other AZs. You can see the activity in the below images:&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020759731/dd5ca49d-63f5-4dd7-a938-85a69739156e.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020770104/a33c6385-05b6-4f38-b0e3-53ec8c938dc6.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020786324/bf8b901a-f16b-49df-ac08-6f47fc575b91.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt; &lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020793724/d0015603-2e71-440d-bccb-dc2370689021.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Application Availability&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt; Confirm that the application is still available by accessing the Nginx service through a &lt;code&gt;LoadBalancer&lt;/code&gt; or &lt;code&gt;NodePort&lt;/code&gt;.&lt;/p&gt;&lt;p&gt; If you&apos;ve set up a service with a &lt;code&gt;LoadBalancer&lt;/code&gt; type, you can get the external IP and check access:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl get svc&lt;/code&gt;&lt;/pre&gt;&lt;p&gt; Access the external IP in your browser to verify that the application is still accessible.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1725020904117/7cbfa0fb-10fe-44a4-a850-fc2c5cdbb452.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h4 id=&quot;heading-step-6-clean-up-resources&quot;&gt;&lt;strong&gt;Step 6: Clean Up Resources&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;Once you have verified the communication and high availability, clean up the resources to avoid unnecessary charges:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;eksctl delete cluster --name multi-az-cluster&lt;/code&gt;&lt;/pre&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;By following these updated steps, you&apos;ve created an EKS cluster across multiple Availability Zones, deployed an example application, and verified that pods can communicate across AZs using a Kubernetes Service, ensuring high availability and resilience. This setup helps maintain service continuity even when failures occur in one AZ.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1725021428397/d9896386-222b-4a93-8bf6-bdd2bf529a5e.png</hashnode:coverImage></item><item><title><![CDATA[How can you securely configure a Kubernetes pod to access an Amazon S3 bucket using IAM Roles for Service Accounts (IRSA) in an EKS cluster?]]></title><description><![CDATA[Question: How can you securely configure a Kubernetes pod to access an Amazon S3 bucket using IAM Roles for Service Accounts (IRSA) in an EKS cluster, and how can you verify that the pod is accessing the bucket correctly?
Answer:
To securely configur...]]></description><link>https://devopsvoyager.hashnode.dev/how-can-you-securely-configure-a-kubernetes-pod-to-access-an-amazon-s3-bucket-using-iam-roles-for-service-accounts-irsa-in-an-eks-cluster</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/how-can-you-securely-configure-a-kubernetes-pod-to-access-an-amazon-s3-bucket-using-iam-roles-for-service-accounts-irsa-in-an-eks-cluster</guid><category><![CDATA[EKS]]></category><category><![CDATA[irsa]]></category><category><![CDATA[IAM]]></category><category><![CDATA[S3]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Sun, 20 Oct 2024 03:30:47 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h2 id=&quot;heading-question-how-can-you-securely-configure-a-kubernetes-pod-to-access-an-amazon-s3-bucket-using-iam-roles-for-service-accounts-irsa-in-an-eks-cluster-and-how-can-you-verify-that-the-pod-is-accessing-the-bucket-correctly&quot;&gt;Question: How can you securely configure a Kubernetes pod to access an Amazon S3 bucket using IAM Roles for Service Accounts (IRSA) in an EKS cluster, and how can you verify that the pod is accessing the bucket correctly?&lt;/h2&gt;&lt;h3 id=&quot;heading-answer&quot;&gt;Answer:&lt;/h3&gt;&lt;p&gt;To securely configure a Kubernetes pod to access an Amazon S3 bucket using IAM Roles for Service Accounts (IRSA) in an Amazon EKS (Elastic Kubernetes Service) cluster, and to verify the access, follow these steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up an EKS Cluster:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Ensure you have an Amazon EKS cluster running. IRSA is a feature specific to EKS and requires the cluster to have an OpenID Connect (OIDC) provider configured. This OIDC provider allows the Kubernetes service account to obtain temporary AWS credentials.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an S3 Bucket:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Ensure you have an Amazon S3 bucket created that you want the pod to access and at least one file should be there. You will need the bucket name to configure IAM policies and roles.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an IAM Policy:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Define an IAM policy that includes the permissions required for the S3 operations you intend to perform (e.g., &lt;code&gt;s3:GetObject&lt;/code&gt;, &lt;code&gt;s3:PutObject&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Example policy JSON:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-json&quot;&gt;  {    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;&lt;/span&gt;: [      {        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;&lt;/span&gt;: [          &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:GetObject&quot;&lt;/span&gt;,          &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:PutObject&quot;&lt;/span&gt;        ],        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Resource&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:s3:::your-bucket-name/*&quot;&lt;/span&gt;      }    ]  }&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an IAM Role:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create an IAM role and attach the policy created in step 3.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure the IAM role with a trust relationship that allows the EKS cluster to assume the role. The trust relationship policy typically looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-json&quot;&gt;  {    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;&lt;/span&gt;: [      {        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Principal&quot;&lt;/span&gt;: {          &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Federated&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:iam::account-id:oidc-provider/oidc.eks.region.amazonaws.com/id/eks-cluster-id&quot;&lt;/span&gt;        },        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;sts:AssumeRoleWithWebIdentity&quot;&lt;/span&gt;,        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Condition&quot;&lt;/span&gt;: {          &lt;span class=&quot;hljs-attr&quot;&gt;&quot;StringEquals&quot;&lt;/span&gt;: {            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;oidc.eks.region.amazonaws.com/id/eks-cluster-id:sub&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;system:serviceaccount:namespace:service-account-name&quot;&lt;/span&gt;          }        }      }    ]  }&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Annotate the Kubernetes Service Account:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Annotate the Kubernetes service account with the IAM role ARN to link the service account with the IAM role.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Example annotation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl annotate serviceaccount service-account-name eks.amazonaws.com/role-arn=arn:aws:iam::account-id:role/role-name -n namespace&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update the Pod Deployment:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Modify your pod deployment to use the service account annotated in step 5.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Example deployment snippet:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;serviceAccountName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;service-account-name&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-container&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ubuntu:latest&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;command:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;/bin/bash&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;-c&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;sleep infinity&quot;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify Access to the S3 Bucket:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Pod Logs:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Verify that your application inside the pod can perform the expected S3 operations (e.g., listing objects, and uploading files).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You can check the logs of the pod to see if there are any errors related to S3 access.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;        kubectl logs pod-name&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run a Test Command Inside the Pod:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You can use an interactive shell to manually test access to the S3 bucket from within the pod. For example, use the &lt;code&gt;aws&lt;/code&gt; CLI to list the contents of the bucket.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;        kubectl &lt;span class=&quot;hljs-built_in&quot;&gt;exec&lt;/span&gt; -it pod-name -- /bin/sh        &lt;span class=&quot;hljs-comment&quot;&gt;# Inside the pod shell&lt;/span&gt;        aws s3 ls s3://your-bucket-name --region your-region&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use a Test Application:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy a test application or script that performs operations on the S3 bucket (e.g., uploading and downloading a file). Verify that the operations succeed and the expected files are in the bucket.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By completing these steps and &lt;strong&gt;verifying, you can ensure that your EKS pod securely accesses&lt;/strong&gt; the S3 bucket using the IAM role associated with its Kubernetes service account. This setup leverages temporary credentials provided by AWS, enhancing security by avoiding using long-term credentials.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h2 id=&quot;heading-question-how-can-you-securely-configure-a-kubernetes-pod-to-access-an-amazon-s3-bucket-using-iam-roles-for-service-accounts-irsa-in-an-eks-cluster-and-how-can-you-verify-that-the-pod-is-accessing-the-bucket-correctly&quot;&gt;Question: How can you securely configure a Kubernetes pod to access an Amazon S3 bucket using IAM Roles for Service Accounts (IRSA) in an EKS cluster, and how can you verify that the pod is accessing the bucket correctly?&lt;/h2&gt;&lt;h3 id=&quot;heading-answer&quot;&gt;Answer:&lt;/h3&gt;&lt;p&gt;To securely configure a Kubernetes pod to access an Amazon S3 bucket using IAM Roles for Service Accounts (IRSA) in an Amazon EKS (Elastic Kubernetes Service) cluster, and to verify the access, follow these steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up an EKS Cluster:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Ensure you have an Amazon EKS cluster running. IRSA is a feature specific to EKS and requires the cluster to have an OpenID Connect (OIDC) provider configured. This OIDC provider allows the Kubernetes service account to obtain temporary AWS credentials.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an S3 Bucket:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Ensure you have an Amazon S3 bucket created that you want the pod to access and at least one file should be there. You will need the bucket name to configure IAM policies and roles.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an IAM Policy:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Define an IAM policy that includes the permissions required for the S3 operations you intend to perform (e.g., &lt;code&gt;s3:GetObject&lt;/code&gt;, &lt;code&gt;s3:PutObject&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Example policy JSON:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-json&quot;&gt;  {    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;&lt;/span&gt;: [      {        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;&lt;/span&gt;: [          &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:GetObject&quot;&lt;/span&gt;,          &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:PutObject&quot;&lt;/span&gt;        ],        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Resource&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:s3:::your-bucket-name/*&quot;&lt;/span&gt;      }    ]  }&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create an IAM Role:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create an IAM role and attach the policy created in step 3.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Configure the IAM role with a trust relationship that allows the EKS cluster to assume the role. The trust relationship policy typically looks like:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-json&quot;&gt;  {    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;&lt;/span&gt;: [      {        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Principal&quot;&lt;/span&gt;: {          &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Federated&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:iam::account-id:oidc-provider/oidc.eks.region.amazonaws.com/id/eks-cluster-id&quot;&lt;/span&gt;        },        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;sts:AssumeRoleWithWebIdentity&quot;&lt;/span&gt;,        &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Condition&quot;&lt;/span&gt;: {          &lt;span class=&quot;hljs-attr&quot;&gt;&quot;StringEquals&quot;&lt;/span&gt;: {            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;oidc.eks.region.amazonaws.com/id/eks-cluster-id:sub&quot;&lt;/span&gt;: &lt;span class=&quot;hljs-string&quot;&gt;&quot;system:serviceaccount:namespace:service-account-name&quot;&lt;/span&gt;          }        }      }    ]  }&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Annotate the Kubernetes Service Account:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Annotate the Kubernetes service account with the IAM role ARN to link the service account with the IAM role.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Example annotation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  kubectl annotate serviceaccount service-account-name eks.amazonaws.com/role-arn=arn:aws:iam::account-id:role/role-name -n namespace&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update the Pod Deployment:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Modify your pod deployment to use the service account annotated in step 5.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Example deployment snippet:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;serviceAccountName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;service-account-name&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-container&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ubuntu:latest&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;command:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;/bin/bash&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;-c&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;sleep infinity&quot;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify Access to the S3 Bucket:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Check Pod Logs:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Verify that your application inside the pod can perform the expected S3 operations (e.g., listing objects, and uploading files).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;You can check the logs of the pod to see if there are any errors related to S3 access.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;        kubectl logs pod-name&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Run a Test Command Inside the Pod:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;You can use an interactive shell to manually test access to the S3 bucket from within the pod. For example, use the &lt;code&gt;aws&lt;/code&gt; CLI to list the contents of the bucket.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;        kubectl &lt;span class=&quot;hljs-built_in&quot;&gt;exec&lt;/span&gt; -it pod-name -- /bin/sh        &lt;span class=&quot;hljs-comment&quot;&gt;# Inside the pod shell&lt;/span&gt;        aws s3 ls s3://your-bucket-name --region your-region&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use a Test Application:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy a test application or script that performs operations on the S3 bucket (e.g., uploading and downloading a file). Verify that the operations succeed and the expected files are in the bucket.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By completing these steps and &lt;strong&gt;verifying, you can ensure that your EKS pod securely accesses&lt;/strong&gt; the S3 bucket using the IAM role associated with its Kubernetes service account. This setup leverages temporary credentials provided by AWS, enhancing security by avoiding using long-term credentials.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1724840504214/2b812287-c002-4955-a9a0-51eeebbbe6db.png</hashnode:coverImage></item><item><title><![CDATA[How can you configure a Multi-AZ Deployment in Kubernetes to ensure high availability?]]></title><description><![CDATA[Question: How can you configure a Multi-AZ Deployment in Kubernetes to ensure high availability?
Answer:
To configure a Multi-AZ Deployment for high availability in Kubernetes, follow these detailed steps:
1. Why Multi-AZ Deployment is Useful
Objecti...]]></description><link>https://devopsvoyager.hashnode.dev/how-can-you-configure-a-multi-az-deployment-in-kubernetes-to-ensure-high-availability</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/how-can-you-configure-a-multi-az-deployment-in-kubernetes-to-ensure-high-availability</guid><category><![CDATA[EKS]]></category><category><![CDATA[EKS cluster]]></category><category><![CDATA[AWS]]></category><category><![CDATA[#MultiAvailabilityZoneDeployment]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Sat, 19 Oct 2024 03:30:26 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h3 id=&quot;heading-question-how-can-you-configure-a-multi-az-deployment-in-kubernetes-to-ensure-high-availability&quot;&gt;&lt;strong&gt;Question: How can you configure a Multi-AZ Deployment in Kubernetes to ensure high availability?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;To configure a Multi-AZ Deployment for high availability in Kubernetes, follow these detailed steps:&lt;/p&gt;&lt;h3 id=&quot;heading-1-why-multi-az-deployment-is-useful&quot;&gt;&lt;strong&gt;1. Why Multi-AZ Deployment is Useful&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Objective:&lt;/strong&gt; Distribute Kubernetes nodes and pods across multiple Availability Zones (AZs) to enhance fault tolerance and availability.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fault Tolerance:&lt;/strong&gt; If one AZ experiences issues, other AZs continue to operate, ensuring your application remains available.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Reliability:&lt;/strong&gt; Distributing workloads across multiple AZs reduces the risk of downtime due to a single point of failure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Resilience:&lt;/strong&gt; In case of network, power, or hardware failures in one AZ, other AZs can handle the load, leading to a more resilient infrastructure.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-2-implementation-steps&quot;&gt;&lt;strong&gt;2. Implementation Steps&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Example Platform:&lt;/strong&gt; AWS EKS (Elastic Kubernetes Service)&lt;/p&gt;&lt;h4 id=&quot;heading-step-1-configure-node-groups-across-multiple-azs&quot;&gt;&lt;strong&gt;Step 1: Configure Node Groups Across Multiple AZs&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;Why:&lt;/strong&gt; Ensures that your Kubernetes nodes are distributed across different AZs, improving fault tolerance.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Node Group with Multiple AZs:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS EKS Console:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Go to the EKS cluster in the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigate to the Node Groups section.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click Add Node Group and follow the setup wizard.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When configuring the node group, select multiple AZs in the Subnets section.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using AWS CLI:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  aws eks create-nodegroup \    --cluster-name my-cluster \    --nodegroup-name my-nodegroup \    --subnets subnet-abcde123 subnet-bcdef234 \    --instance-types t3.medium \    --scaling-config minSize=2,maxSize=10,desiredSize=3 \    --region us-west-2&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Considerations:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Choose subnets in different AZs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure your VPC has subnets spanning multiple AZs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-2-configure-pod-distribution-using-affinity-and-anti-affinity-rules&quot;&gt;&lt;strong&gt;Step 2: Configure Pod Distribution Using Affinity and Anti-Affinity Rules&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;Why:&lt;/strong&gt; Ensures that pods are spread across multiple AZs to avoid concentration in a single AZ, which can be a point of failure.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define Affinity and Anti-Affinity Rules in Your Pod Specifications:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Affinity:&lt;/strong&gt; Ensures pods are scheduled in the same AZ or node based on certain labels.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Anti-Affinity:&lt;/strong&gt; Ensures pods are spread across different nodes or AZs to avoid placing multiple instances of the same application in the same AZ.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;    &lt;strong&gt;Example Deployment YAML with Anti-Affinity Rules:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;affinity:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;antiAffinity:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;requiredDuringSchedulingIgnoredDuringExecution:&lt;/span&gt;              &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;labelSelector:&lt;/span&gt;                  &lt;span class=&quot;hljs-attr&quot;&gt;matchExpressions:&lt;/span&gt;                  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;key:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app&lt;/span&gt;                    &lt;span class=&quot;hljs-attr&quot;&gt;operator:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;In&lt;/span&gt;                    &lt;span class=&quot;hljs-attr&quot;&gt;values:&lt;/span&gt;                    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;topologyKey:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;topology.kubernetes.io/zone&quot;&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Ensures distribution across AZs&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app-container&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app-image&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Topology Key:&lt;/strong&gt; &lt;code&gt;&quot;&lt;/code&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://topology.kubernetes.io/zone&quot;&gt;&lt;code&gt;topology.kubernetes.io/zone&lt;/code&gt;&lt;/a&gt;&lt;code&gt;&quot;&lt;/code&gt; is used to spread pods across different AZs.&lt;/li&gt;&lt;/ul&gt;&lt;ol start=&quot;2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Apply Your Configuration:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;strong&gt;Command:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl apply -f deployment.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-summary&quot;&gt;&lt;strong&gt;Summary:&lt;/strong&gt;&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure Node Groups:&lt;/strong&gt; Ensure your node groups span multiple AZs to avoid having all nodes in a single AZ.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Affinity and Anti-Affinity Rules:&lt;/strong&gt; Use these rules in your pod specifications to control how pods are distributed across different AZs.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-why-this-approach-is-beneficial&quot;&gt;&lt;strong&gt;Why This Approach is Beneficial:&lt;/strong&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;High Availability:&lt;/strong&gt; By spreading nodes and pods across multiple AZs, your application is protected against failures in any single AZ.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fault Tolerance:&lt;/strong&gt; Ensures that even if one AZ fails, your application can continue operating normally from other AZs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Performance and Reliability:&lt;/strong&gt; Load is distributed, and your application can handle traffic spikes more efficiently.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Implementing Multi-AZ deployments ensures that your Kubernetes applications are resilient and can continue to function in the face of infrastructure issues, providing higher reliability and availability.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h3 id=&quot;heading-question-how-can-you-configure-a-multi-az-deployment-in-kubernetes-to-ensure-high-availability&quot;&gt;&lt;strong&gt;Question: How can you configure a Multi-AZ Deployment in Kubernetes to ensure high availability?&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Answer:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;To configure a Multi-AZ Deployment for high availability in Kubernetes, follow these detailed steps:&lt;/p&gt;&lt;h3 id=&quot;heading-1-why-multi-az-deployment-is-useful&quot;&gt;&lt;strong&gt;1. Why Multi-AZ Deployment is Useful&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Objective:&lt;/strong&gt; Distribute Kubernetes nodes and pods across multiple Availability Zones (AZs) to enhance fault tolerance and availability.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Benefits:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fault Tolerance:&lt;/strong&gt; If one AZ experiences issues, other AZs continue to operate, ensuring your application remains available.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Reliability:&lt;/strong&gt; Distributing workloads across multiple AZs reduces the risk of downtime due to a single point of failure.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Resilience:&lt;/strong&gt; In case of network, power, or hardware failures in one AZ, other AZs can handle the load, leading to a more resilient infrastructure.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-2-implementation-steps&quot;&gt;&lt;strong&gt;2. Implementation Steps&lt;/strong&gt;&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Example Platform:&lt;/strong&gt; AWS EKS (Elastic Kubernetes Service)&lt;/p&gt;&lt;h4 id=&quot;heading-step-1-configure-node-groups-across-multiple-azs&quot;&gt;&lt;strong&gt;Step 1: Configure Node Groups Across Multiple AZs&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;Why:&lt;/strong&gt; Ensures that your Kubernetes nodes are distributed across different AZs, improving fault tolerance.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Node Group with Multiple AZs:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;AWS EKS Console:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Go to the EKS cluster in the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Navigate to the Node Groups section.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click Add Node Group and follow the setup wizard.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;When configuring the node group, select multiple AZs in the Subnets section.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Using AWS CLI:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;  aws eks create-nodegroup \    --cluster-name my-cluster \    --nodegroup-name my-nodegroup \    --subnets subnet-abcde123 subnet-bcdef234 \    --instance-types t3.medium \    --scaling-config minSize=2,maxSize=10,desiredSize=3 \    --region us-west-2&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Considerations:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Choose subnets in different AZs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure your VPC has subnets spanning multiple AZs.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-step-2-configure-pod-distribution-using-affinity-and-anti-affinity-rules&quot;&gt;&lt;strong&gt;Step 2: Configure Pod Distribution Using Affinity and Anti-Affinity Rules&lt;/strong&gt;&lt;/h4&gt;&lt;p&gt;&lt;strong&gt;Why:&lt;/strong&gt; Ensures that pods are spread across multiple AZs to avoid concentration in a single AZ, which can be a point of failure.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Steps:&lt;/strong&gt;&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Define Affinity and Anti-Affinity Rules in Your Pod Specifications:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Affinity:&lt;/strong&gt; Ensures pods are scheduled in the same AZ or node based on certain labels.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Anti-Affinity:&lt;/strong&gt; Ensures pods are spread across different nodes or AZs to avoid placing multiple instances of the same application in the same AZ.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;    &lt;strong&gt;Example Deployment YAML with Anti-Affinity Rules:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;affinity:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;antiAffinity:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;requiredDuringSchedulingIgnoredDuringExecution:&lt;/span&gt;              &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;labelSelector:&lt;/span&gt;                  &lt;span class=&quot;hljs-attr&quot;&gt;matchExpressions:&lt;/span&gt;                  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;key:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;app&lt;/span&gt;                    &lt;span class=&quot;hljs-attr&quot;&gt;operator:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;In&lt;/span&gt;                    &lt;span class=&quot;hljs-attr&quot;&gt;values:&lt;/span&gt;                    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;                &lt;span class=&quot;hljs-attr&quot;&gt;topologyKey:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;topology.kubernetes.io/zone&quot;&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Ensures distribution across AZs&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app-container&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app-image&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Topology Key:&lt;/strong&gt; &lt;code&gt;&quot;&lt;/code&gt;&lt;a target=&quot;_blank&quot; href=&quot;http://topology.kubernetes.io/zone&quot;&gt;&lt;code&gt;topology.kubernetes.io/zone&lt;/code&gt;&lt;/a&gt;&lt;code&gt;&quot;&lt;/code&gt; is used to spread pods across different AZs.&lt;/li&gt;&lt;/ul&gt;&lt;ol start=&quot;2&quot;&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Apply Your Configuration:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt; &lt;strong&gt;Command:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl apply -f deployment.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-summary&quot;&gt;&lt;strong&gt;Summary:&lt;/strong&gt;&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure Node Groups:&lt;/strong&gt; Ensure your node groups span multiple AZs to avoid having all nodes in a single AZ.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Affinity and Anti-Affinity Rules:&lt;/strong&gt; Use these rules in your pod specifications to control how pods are distributed across different AZs.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-why-this-approach-is-beneficial&quot;&gt;&lt;strong&gt;Why This Approach is Beneficial:&lt;/strong&gt;&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;High Availability:&lt;/strong&gt; By spreading nodes and pods across multiple AZs, your application is protected against failures in any single AZ.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fault Tolerance:&lt;/strong&gt; Ensures that even if one AZ fails, your application can continue operating normally from other AZs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Performance and Reliability:&lt;/strong&gt; Load is distributed, and your application can handle traffic spikes more efficiently.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Implementing Multi-AZ deployments ensures that your Kubernetes applications are resilient and can continue to function in the face of infrastructure issues, providing higher reliability and availability.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1724856726105/92c9ddad-b06e-4a70-a268-f0ced4733645.png</hashnode:coverImage></item><item><title><![CDATA[Configuring OIDC Provider with AWS Account to Access S3 Bucket from a Kubernetes Pod Using AWS Management Console]]></title><description><![CDATA[Introduction
Accessing AWS resources securely from applications running in Kubernetes is a common requirement. By using AWS IAM Roles for Service Accounts (IRSA) and OpenID Connect (OIDC), you can grant fine-grained permissions to your Kubernetes pod...]]></description><link>https://devopsvoyager.hashnode.dev/configuring-oidc-provider-with-aws-account-to-access-s3-bucket-from-a-kubernetes-pod-using-aws-management-console</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/configuring-oidc-provider-with-aws-account-to-access-s3-bucket-from-a-kubernetes-pod-using-aws-management-console</guid><category><![CDATA[AWS]]></category><category><![CDATA[OIDC]]></category><category><![CDATA[EKS]]></category><category><![CDATA[EKS cluster]]></category><category><![CDATA[IAM]]></category><category><![CDATA[roles]]></category><category><![CDATA[irsa]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Fri, 18 Oct 2024 03:30:22 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;Accessing AWS resources securely from applications running in Kubernetes is a common requirement. By using AWS IAM Roles for Service Accounts (IRSA) and OpenID Connect (OIDC), you can grant fine-grained permissions to your Kubernetes pods without hardcoding AWS credentials. This guide will show you how to set up this configuration using the AWS Management Console.&lt;/p&gt;&lt;h3 id=&quot;heading-prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;AWS Account with necessary permissions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes cluster (EKS or self-managed) with version 1.13 or later.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An existing S3 bucket or the ability to create a new one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access to the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;kubectl is configured to manage your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-step-1-set-up-the-oidc-provider-in-the-aws-management-console&quot;&gt;Step 1: Set Up the OIDC Provider in the AWS Management Console&lt;/h3&gt;&lt;h4 id=&quot;heading-11-identify-the-oidc-url-for-your-cluster&quot;&gt;1.1 Identify the OIDC URL for Your Cluster&lt;/h4&gt;&lt;p&gt;If you&apos;re using an Amazon EKS cluster, AWS automatically creates an OIDC provider. To find the OIDC URL:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Go to the &lt;strong&gt;Amazon EKS&lt;/strong&gt; service in the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select your cluster from the list.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;Overview&lt;/strong&gt; tab, find the &lt;strong&gt;Cluster details&lt;/strong&gt; section. The &lt;strong&gt;OIDC provider&lt;/strong&gt; URL will be listed there.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655456575/0ac27e59-db04-4761-8fc3-2a45a01f508c.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;For self-managed Kubernetes clusters, you&apos;ll need to manually retrieve the OIDC URL, usually in the format &lt;code&gt;https://&amp;lt;cluster-dns&amp;gt;/openid/v1/id&lt;/code&gt;.&lt;/p&gt;&lt;h4 id=&quot;heading-12-create-oidc-identity-provider&quot;&gt;1.2 Create OIDC Identity Provider&lt;/h4&gt;&lt;p&gt;If you&apos;re using a self-managed Kubernetes cluster, you&apos;ll need to create the OIDC provider manually:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open the &lt;strong&gt;IAM&lt;/strong&gt; service in the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the left-hand menu, click on &lt;strong&gt;Identity providers&lt;/strong&gt; under &lt;strong&gt;Access management&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Add provider&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;OpenID Connect&lt;/strong&gt; as the provider type.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enter the OIDC URL you retrieved earlier.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add &lt;a target=&quot;_blank&quot; href=&quot;http://sts.amazonaws.com&quot;&gt;&lt;code&gt;sts.amazonaws.com&lt;/code&gt;&lt;/a&gt; as the &lt;strong&gt;Audience&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Add provider&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655491968/a913d970-2107-42ed-8d0a-e8dab55dce4a.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655501211/f7938952-27e9-4886-a7d1-a2582bad7f32.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h3 id=&quot;heading-step-2-create-an-iam-role-with-a-trust-policy&quot;&gt;Step 2: Create an IAM Role with a Trust Policy&lt;/h3&gt;&lt;p&gt;Next, youll create an IAM policies, role. This role will have permission to access the S3 bucket.&lt;/p&gt;&lt;h4 id=&quot;heading-21-create-a-new-policy&quot;&gt;2.1 Create a New Policy&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;IAM&lt;/strong&gt; service in the AWS Management Console, click &lt;strong&gt;Policies&lt;/strong&gt; in the left-hand menu.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create Policy&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655675690/0cd2a206-f892-42a5-8aaf-b5ca775a83f4.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724656751476/8a62cafd-ccfa-42e6-b721-be0f05fa8428.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724656766494/568dac5d-c71a-4d72-b459-27f2aea7c58d.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Service&lt;/strong&gt; as EKS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Keeping in mind that your bucket is created and at least one file should be there as you can see here&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724657121178/319ba35b-3e25-422d-ad41-7553f210e679.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Choose the JSON Editor and Paste below Policy.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;{    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;:&lt;/span&gt; [        {            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Sid&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;Statement1&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;:&lt;/span&gt; [                &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:GetObject&quot;&lt;/span&gt;,                &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:PutObject&quot;&lt;/span&gt;,                &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:ListBucket&quot;&lt;/span&gt;            ],            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Resource&quot;:&lt;/span&gt; [                &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:s3:::Your_bucket_name&quot;&lt;/span&gt;            ]        }    ]}&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-22-attach-trust-relationship-to-the-iam-role&quot;&gt;2.2 Attach Trust Relationship to the IAM Role&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create an IAM role and attach the below policy to it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a file called &lt;code&gt;trust-policy.json&lt;/code&gt; Enter the below policy. (Modify accordingly)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;{    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;:&lt;/span&gt; [        {            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Principal&quot;:&lt;/span&gt; {                &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Federated&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:iam::&amp;lt;aws_account_id&amp;gt;:oidc-provider/oidc.eks.your-region.amazonaws.com/id/your-cluster-id&quot;&lt;/span&gt;            },            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;sts:AssumeRoleWithWebIdentity&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Condition&quot;:&lt;/span&gt; {                &lt;span class=&quot;hljs-attr&quot;&gt;&quot;StringEquals&quot;:&lt;/span&gt; {                    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;oidc.eks.your-region.amazonaws.com/id/your-cluster-id:sub&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;system:serviceaccount:default:s3-access-sa&quot;&lt;/span&gt;,                    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;oidc.eks.ap-northeast-1.amazonaws.com/id/F6929AF6CAC1605B0FB86ECA2954A0F1:aud&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;sts.amazonaws.com&quot;&lt;/span&gt;                }            }        }    ]}&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;Create an IAM Role along with the above policy.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;aws&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;iam&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;create-role&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--role-name&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-eks-role&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--assume-role-policy-document&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;file://trust-policy.json&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;Go to IAM Roles and go to the Trust Relationships section, then you can see this.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724657880286/8d9bf903-26fd-4841-9a46-e3d28a2c83bd.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Attach the Policy that you created earlier.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;aws&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;iam&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;attach-role-policy&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--role-name&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-eks-role&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--policy-arn&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;lt;arn_of_the_policy&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724658351204/7a91ce28-bb66-49f0-a93e-b6164d6c7b54.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Go to the Permissions section in the Roles then you can see that policy&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724658568978/484f7d4f-be78-474f-b556-f53b602426ee.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h3 id=&quot;heading-step-3-associate-iam-role-with-kubernetes-service-account&quot;&gt;Step 3: Associate IAM Role with Kubernetes Service Account&lt;/h3&gt;&lt;p&gt;To allow the Kubernetes service account to assume the IAM role:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In the Kubernetes cluster, we will create a service account and Annotate the service account with the IAM role ARN&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create &lt;code&gt;service-account.yaml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ServiceAccount&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;s3-access-sa&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Name of the service account&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;annotations:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;eks.amazonaws.com/role-arn:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;lt;arn_of_your_IAM_role&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f service-account.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-step-4-deploy-a-pod-to-access-s3&quot;&gt;Step 4: Deploy a Pod to Access S3&lt;/h3&gt;&lt;p&gt;Create and deploy a pod that uses the service account associated with the IAM role.&lt;/p&gt;&lt;h4 id=&quot;heading-41-create-a-kubernetes-deployment&quot;&gt;4.1 Create a Kubernetes Deployment&lt;/h4&gt;&lt;p&gt;Create a deployment YAML file that specifies the service account:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-deployment&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Name of the deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;        &lt;span class=&quot;hljs-comment&quot;&gt;# Namespace where the deployment will be created&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;              &lt;span class=&quot;hljs-comment&quot;&gt;# Number of replicas/pods&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-app&lt;/span&gt;    &lt;span class=&quot;hljs-comment&quot;&gt;# Label selector to match pods&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-app&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Labels for the pod&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;serviceAccountName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;s3-access-sa&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Specify the service account here&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-container&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;amazon/aws-cli:latest&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Container image&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;command:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;sleep&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;3600&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-comment&quot;&gt;# Keeps the container running for testing&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Apply the deployment using &lt;code&gt;kubectl&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f s3-access-deployment.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-42-access-the-pod-and-s3-bucket&quot;&gt;4.2 Access the Pod and S3 Bucket&lt;/h4&gt;&lt;p&gt;After the pod is running, access the pod and use the AWS CLI to interact with the S3 bucket:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl &lt;span class=&quot;hljs-built_in&quot;&gt;exec&lt;/span&gt; -it &amp;lt;pod-name&amp;gt; -- bash&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;List the contents of the S3 bucket:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;aws s3 ls s3://&amp;lt;bucket-name&amp;gt;/&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724658920831/c1b22b73-68d3-4557-a2df-4a2099db4918.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Using the AWS Management Console, youve successfully configured an OIDC provider with your AWS account and set up a Kubernetes pod to securely access an S3 bucket. This method enhances security by eliminating the need for hardcoded credentials and using IAM roles tied to specific Kubernetes service accounts.&lt;/p&gt;&lt;h3 id=&quot;heading-references&quot;&gt;References:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/pod-configuration.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/pod-configuration.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-association.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-association.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-configure-pods.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-configure-pods.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;###&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/h1&gt;&lt;p&gt;Accessing AWS resources securely from applications running in Kubernetes is a common requirement. By using AWS IAM Roles for Service Accounts (IRSA) and OpenID Connect (OIDC), you can grant fine-grained permissions to your Kubernetes pods without hardcoding AWS credentials. This guide will show you how to set up this configuration using the AWS Management Console.&lt;/p&gt;&lt;h3 id=&quot;heading-prerequisites&quot;&gt;Prerequisites&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;AWS Account with necessary permissions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Kubernetes cluster (EKS or self-managed) with version 1.13 or later.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;An existing S3 bucket or the ability to create a new one.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access to the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;kubectl is configured to manage your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-step-1-set-up-the-oidc-provider-in-the-aws-management-console&quot;&gt;Step 1: Set Up the OIDC Provider in the AWS Management Console&lt;/h3&gt;&lt;h4 id=&quot;heading-11-identify-the-oidc-url-for-your-cluster&quot;&gt;1.1 Identify the OIDC URL for Your Cluster&lt;/h4&gt;&lt;p&gt;If you&apos;re using an Amazon EKS cluster, AWS automatically creates an OIDC provider. To find the OIDC URL:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Go to the &lt;strong&gt;Amazon EKS&lt;/strong&gt; service in the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select your cluster from the list.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;Overview&lt;/strong&gt; tab, find the &lt;strong&gt;Cluster details&lt;/strong&gt; section. The &lt;strong&gt;OIDC provider&lt;/strong&gt; URL will be listed there.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655456575/0ac27e59-db04-4761-8fc3-2a45a01f508c.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;For self-managed Kubernetes clusters, you&apos;ll need to manually retrieve the OIDC URL, usually in the format &lt;code&gt;https://&amp;lt;cluster-dns&amp;gt;/openid/v1/id&lt;/code&gt;.&lt;/p&gt;&lt;h4 id=&quot;heading-12-create-oidc-identity-provider&quot;&gt;1.2 Create OIDC Identity Provider&lt;/h4&gt;&lt;p&gt;If you&apos;re using a self-managed Kubernetes cluster, you&apos;ll need to create the OIDC provider manually:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Open the &lt;strong&gt;IAM&lt;/strong&gt; service in the AWS Management Console.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;In the left-hand menu, click on &lt;strong&gt;Identity providers&lt;/strong&gt; under &lt;strong&gt;Access management&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click on &lt;strong&gt;Add provider&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;OpenID Connect&lt;/strong&gt; as the provider type.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Enter the OIDC URL you retrieved earlier.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Add &lt;a target=&quot;_blank&quot; href=&quot;http://sts.amazonaws.com&quot;&gt;&lt;code&gt;sts.amazonaws.com&lt;/code&gt;&lt;/a&gt; as the &lt;strong&gt;Audience&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Add provider&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655491968/a913d970-2107-42ed-8d0a-e8dab55dce4a.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655501211/f7938952-27e9-4886-a7d1-a2582bad7f32.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h3 id=&quot;heading-step-2-create-an-iam-role-with-a-trust-policy&quot;&gt;Step 2: Create an IAM Role with a Trust Policy&lt;/h3&gt;&lt;p&gt;Next, youll create an IAM policies, role. This role will have permission to access the S3 bucket.&lt;/p&gt;&lt;h4 id=&quot;heading-21-create-a-new-policy&quot;&gt;2.1 Create a New Policy&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In the &lt;strong&gt;IAM&lt;/strong&gt; service in the AWS Management Console, click &lt;strong&gt;Policies&lt;/strong&gt; in the left-hand menu.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click &lt;strong&gt;Create Policy&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724655675690/0cd2a206-f892-42a5-8aaf-b5ca775a83f4.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724656751476/8a62cafd-ccfa-42e6-b721-be0f05fa8428.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724656766494/568dac5d-c71a-4d72-b459-27f2aea7c58d.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Select &lt;strong&gt;Service&lt;/strong&gt; as EKS.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Keeping in mind that your bucket is created and at least one file should be there as you can see here&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724657121178/319ba35b-3e25-422d-ad41-7553f210e679.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Choose the JSON Editor and Paste below Policy.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;{    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;:&lt;/span&gt; [        {            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Sid&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;Statement1&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;:&lt;/span&gt; [                &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:GetObject&quot;&lt;/span&gt;,                &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:PutObject&quot;&lt;/span&gt;,                &lt;span class=&quot;hljs-string&quot;&gt;&quot;s3:ListBucket&quot;&lt;/span&gt;            ],            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Resource&quot;:&lt;/span&gt; [                &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:s3:::Your_bucket_name&quot;&lt;/span&gt;            ]        }    ]}&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-22-attach-trust-relationship-to-the-iam-role&quot;&gt;2.2 Attach Trust Relationship to the IAM Role&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create an IAM role and attach the below policy to it.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create a file called &lt;code&gt;trust-policy.json&lt;/code&gt; Enter the below policy. (Modify accordingly)&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;{    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Version&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;2012-10-17&quot;&lt;/span&gt;,    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Statement&quot;:&lt;/span&gt; [        {            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Effect&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;Allow&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Principal&quot;:&lt;/span&gt; {                &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Federated&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;arn:aws:iam::&amp;lt;aws_account_id&amp;gt;:oidc-provider/oidc.eks.your-region.amazonaws.com/id/your-cluster-id&quot;&lt;/span&gt;            },            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Action&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;sts:AssumeRoleWithWebIdentity&quot;&lt;/span&gt;,            &lt;span class=&quot;hljs-attr&quot;&gt;&quot;Condition&quot;:&lt;/span&gt; {                &lt;span class=&quot;hljs-attr&quot;&gt;&quot;StringEquals&quot;:&lt;/span&gt; {                    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;oidc.eks.your-region.amazonaws.com/id/your-cluster-id:sub&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;system:serviceaccount:default:s3-access-sa&quot;&lt;/span&gt;,                    &lt;span class=&quot;hljs-attr&quot;&gt;&quot;oidc.eks.ap-northeast-1.amazonaws.com/id/F6929AF6CAC1605B0FB86ECA2954A0F1:aud&quot;:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;sts.amazonaws.com&quot;&lt;/span&gt;                }            }        }    ]}&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;Create an IAM Role along with the above policy.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;aws&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;iam&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;create-role&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--role-name&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-eks-role&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--assume-role-policy-document&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;file://trust-policy.json&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;Go to IAM Roles and go to the Trust Relationships section, then you can see this.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724657880286/8d9bf903-26fd-4841-9a46-e3d28a2c83bd.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Attach the Policy that you created earlier.&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;aws&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;iam&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;attach-role-policy&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--role-name&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-eks-role&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--policy-arn&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;lt;arn_of_the_policy&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724658351204/7a91ce28-bb66-49f0-a93e-b6164d6c7b54.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Go to the Permissions section in the Roles then you can see that policy&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724658568978/484f7d4f-be78-474f-b556-f53b602426ee.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h3 id=&quot;heading-step-3-associate-iam-role-with-kubernetes-service-account&quot;&gt;Step 3: Associate IAM Role with Kubernetes Service Account&lt;/h3&gt;&lt;p&gt;To allow the Kubernetes service account to assume the IAM role:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;In the Kubernetes cluster, we will create a service account and Annotate the service account with the IAM role ARN&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create &lt;code&gt;service-account.yaml&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ServiceAccount&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;s3-access-sa&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Name of the service account&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;annotations:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;eks.amazonaws.com/role-arn:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&amp;lt;arn_of_your_IAM_role&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f service-account.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-step-4-deploy-a-pod-to-access-s3&quot;&gt;Step 4: Deploy a Pod to Access S3&lt;/h3&gt;&lt;p&gt;Create and deploy a pod that uses the service account associated with the IAM role.&lt;/p&gt;&lt;h4 id=&quot;heading-41-create-a-kubernetes-deployment&quot;&gt;4.1 Create a Kubernetes Deployment&lt;/h4&gt;&lt;p&gt;Create a deployment YAML file that specifies the service account:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-deployment&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Name of the deployment&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;        &lt;span class=&quot;hljs-comment&quot;&gt;# Namespace where the deployment will be created&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;              &lt;span class=&quot;hljs-comment&quot;&gt;# Number of replicas/pods&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-app&lt;/span&gt;    &lt;span class=&quot;hljs-comment&quot;&gt;# Label selector to match pods&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-app&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Labels for the pod&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;serviceAccountName:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;s3-access-sa&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Specify the service account here&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;aws-cli-container&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;amazon/aws-cli:latest&lt;/span&gt;  &lt;span class=&quot;hljs-comment&quot;&gt;# Container image&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;command:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;sleep&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;3600&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-comment&quot;&gt;# Keeps the container running for testing&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Apply the deployment using &lt;code&gt;kubectl&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f s3-access-deployment.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-42-access-the-pod-and-s3-bucket&quot;&gt;4.2 Access the Pod and S3 Bucket&lt;/h4&gt;&lt;p&gt;After the pod is running, access the pod and use the AWS CLI to interact with the S3 bucket:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl &lt;span class=&quot;hljs-built_in&quot;&gt;exec&lt;/span&gt; -it &amp;lt;pod-name&amp;gt; -- bash&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;List the contents of the S3 bucket:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;aws s3 ls s3://&amp;lt;bucket-name&amp;gt;/&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1724658920831/c1b22b73-68d3-4557-a2df-4a2099db4918.png&quot; alt class=&quot;image--center mx-auto&quot; /&gt;&lt;/p&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Using the AWS Management Console, youve successfully configured an OIDC provider with your AWS account and set up a Kubernetes pod to securely access an S3 bucket. This method enhances security by eliminating the need for hardcoded credentials and using IAM roles tied to specific Kubernetes service accounts.&lt;/p&gt;&lt;h3 id=&quot;heading-references&quot;&gt;References:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/pod-configuration.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/pod-configuration.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-association.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-association.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-configure-pods.html&quot;&gt;https://docs.aws.amazon.com/eks/latest/userguide/pod-id-configure-pods.html&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;###&lt;/p&gt;]]&gt;</hashnode:content></item><item><title><![CDATA[A/B Testing in Kubernetes]]></title><description><![CDATA[🎯 Learning Objective
Understand how to perform A/B testing in Kubernetes to test different versions of your application simultaneously and determine which performs better.
📖 Scenario
You need to test two different versions of your application at th...]]></description><link>https://devopsvoyager.hashnode.dev/ab-testing-in-kubernetes</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/ab-testing-in-kubernetes</guid><category><![CDATA[A/B Testing Strategy]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><category><![CDATA[ab testing]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Thu, 17 Oct 2024 03:30:45 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h2&gt;&lt;p&gt;Understand how to perform A/B testing in Kubernetes to test different versions of your application simultaneously and determine which performs better.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h2&gt;&lt;p&gt;You need to test two different versions of your application at the same time to find out which one performs better and meets user requirements more effectively.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;📘 Explanation&lt;/h2&gt;&lt;p&gt;A/B testing involves running two or more versions of an application simultaneously and directing a portion of the traffic to each version. This helps in comparing the performance and user experience of different versions to make data-driven decisions.&lt;/p&gt;&lt;h2 id=&quot;heading-key-concepts&quot;&gt;🔑 Key Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-ab-testing&quot;&gt;A/B Testing&lt;/h3&gt;&lt;p&gt;A method for comparing two versions of an application to determine which performs better.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-splitting&quot;&gt;Traffic Splitting&lt;/h3&gt;&lt;p&gt;Dividing incoming traffic between different versions to facilitate testing.&lt;/p&gt;&lt;h3 id=&quot;heading-istio&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;An open-source service mesh that provides advanced traffic management features useful for A/B testing.&lt;/p&gt;&lt;h2 id=&quot;heading-ab-testing-setup-with-istio&quot;&gt;📄 A/B Testing Setup with Istio&lt;/h2&gt;&lt;h3 id=&quot;heading-install-istio&quot;&gt;Install Istio&lt;/h3&gt;&lt;p&gt;First, install Istio to manage traffic effectively.&lt;/p&gt;&lt;h4 id=&quot;heading-download-and-install-istio-cli&quot;&gt;Download and Install Istio CLI&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;curl -L https://istio.io/downloadIstio | sh -&lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.*&lt;span class=&quot;hljs-built_in&quot;&gt;export&lt;/span&gt; PATH=&lt;span class=&quot;hljs-variable&quot;&gt;$PWD&lt;/span&gt;/bin:&lt;span class=&quot;hljs-variable&quot;&gt;$PATH&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-install-istio-in-your-cluster&quot;&gt;Install Istio in Your Cluster&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-label-the-namespace-for-istio-injection&quot;&gt;Label the Namespace for Istio Injection&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl label namespace default istio-injection=enabled&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-deploy-two-versions-of-application&quot;&gt;Deploy Two Versions of Application&lt;/h3&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-version-a&quot;&gt;Deployment YAML for Version A&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-version-b&quot;&gt;Deployment YAML for Version B&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-traffic-splitting-with-istio&quot;&gt;Traffic Splitting with Istio&lt;/h3&gt;&lt;h4 id=&quot;heading-virtualservice-for-ab-testing&quot;&gt;VirtualService for A/B Testing&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;50&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;50&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-destinationrule-for-ab-testing&quot;&gt;DestinationRule for A/B Testing&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DestinationRule&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;subsets:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-implement-ab-testing&quot;&gt;🛠 Steps to Implement A/B Testing&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Follow the steps above to install Istio and enable injection.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Two Versions of Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for both versions (v1 and v2).&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Traffic Splitting with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply a VirtualService and a DestinationRule to manage traffic between the two versions.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Analyze Results&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Monitor the performance and user experience of both versions to determine which performs better.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-explanation&quot;&gt;🔍 Detailed Example Explanation&lt;/h2&gt;&lt;h3 id=&quot;heading-ab-testing-1&quot;&gt;A/B Testing&lt;/h3&gt;&lt;p&gt;Running two versions simultaneously allows for direct comparisons in performance and user experience, with traffic split to gather meaningful data.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-splitting-1&quot;&gt;Traffic Splitting&lt;/h3&gt;&lt;p&gt;Using Istios VirtualService and DestinationRule facilitates fine-grained control over traffic routing between different versions of an application.&lt;/p&gt;&lt;h2 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data-Driven Decisions&lt;/strong&gt;: Provides concrete data to inform which version is superior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved User Experience&lt;/strong&gt;: Helps identify which version offers a better user experience.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Controlled Testing&lt;/strong&gt;: Allows testing of new features without impacting the entire user base.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-additional-concepts-and-examples&quot;&gt;📚 Additional Concepts and Examples&lt;/h2&gt;&lt;h3 id=&quot;heading-adjusting-traffic-split&quot;&gt;Adjusting Traffic Split&lt;/h3&gt;&lt;p&gt;You can modify the traffic distribution based on testing requirements to favor one version over the other.&lt;/p&gt;&lt;h4 id=&quot;heading-example&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;30&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;70&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-monitoring-with-istio&quot;&gt;Monitoring with Istio&lt;/h3&gt;&lt;p&gt;Utilize Istios telemetry features to track the performance and user experience of each version during the A/B testing phase.&lt;/p&gt;&lt;h4 id=&quot;heading-example-1&quot;&gt;Example&lt;/h4&gt;&lt;p&gt;Configure Prometheus and Grafana to visualize Istio metrics and monitor application performance.&lt;/p&gt;&lt;h2 id=&quot;heading-hands-on-activity&quot;&gt;🧪 Hands-on Activity&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Follow the installation steps provided earlier.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Two Versions of Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply the deployment YAML for version A (v1) and version B (v2).&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Traffic Splitting with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply a VirtualService and a DestinationRule for traffic splitting.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Analyze Results&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Monitor both versions performance and analyze results to determine the better-performing version.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adjust Traffic Split&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the VirtualService as needed to change the traffic distribution based on testing outcomes.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use the following commands to check your setup:&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;    kubectl get services    kubectl describe services myapp    istioctl proxy-status&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-engage-and-reflect&quot;&gt;🤝 Engage and Reflect&lt;/h2&gt;&lt;p&gt;Understanding and implementing A/B testing is crucial for making data-driven decisions and improving user experience in your applications.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;💬 Engage With Us&lt;/strong&gt;: How do you plan to implement A/B testing in your Kubernetes projects? What challenges did you face while setting them up? Share your experiences and thoughts!&lt;/p&gt;&lt;p&gt;👉 Stay tuned for more learning opportunities and keep refining your Kubernetes knowledge to stay ahead in the ever-evolving tech landscape. Lets continue to explore, innovate, and automate!&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h2&gt;&lt;p&gt;Understand how to perform A/B testing in Kubernetes to test different versions of your application simultaneously and determine which performs better.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h2&gt;&lt;p&gt;You need to test two different versions of your application at the same time to find out which one performs better and meets user requirements more effectively.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;📘 Explanation&lt;/h2&gt;&lt;p&gt;A/B testing involves running two or more versions of an application simultaneously and directing a portion of the traffic to each version. This helps in comparing the performance and user experience of different versions to make data-driven decisions.&lt;/p&gt;&lt;h2 id=&quot;heading-key-concepts&quot;&gt;🔑 Key Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-ab-testing&quot;&gt;A/B Testing&lt;/h3&gt;&lt;p&gt;A method for comparing two versions of an application to determine which performs better.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-splitting&quot;&gt;Traffic Splitting&lt;/h3&gt;&lt;p&gt;Dividing incoming traffic between different versions to facilitate testing.&lt;/p&gt;&lt;h3 id=&quot;heading-istio&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;An open-source service mesh that provides advanced traffic management features useful for A/B testing.&lt;/p&gt;&lt;h2 id=&quot;heading-ab-testing-setup-with-istio&quot;&gt;📄 A/B Testing Setup with Istio&lt;/h2&gt;&lt;h3 id=&quot;heading-install-istio&quot;&gt;Install Istio&lt;/h3&gt;&lt;p&gt;First, install Istio to manage traffic effectively.&lt;/p&gt;&lt;h4 id=&quot;heading-download-and-install-istio-cli&quot;&gt;Download and Install Istio CLI&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;curl -L https://istio.io/downloadIstio | sh -&lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.*&lt;span class=&quot;hljs-built_in&quot;&gt;export&lt;/span&gt; PATH=&lt;span class=&quot;hljs-variable&quot;&gt;$PWD&lt;/span&gt;/bin:&lt;span class=&quot;hljs-variable&quot;&gt;$PATH&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-install-istio-in-your-cluster&quot;&gt;Install Istio in Your Cluster&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-label-the-namespace-for-istio-injection&quot;&gt;Label the Namespace for Istio Injection&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl label namespace default istio-injection=enabled&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-deploy-two-versions-of-application&quot;&gt;Deploy Two Versions of Application&lt;/h3&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-version-a&quot;&gt;Deployment YAML for Version A&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-version-b&quot;&gt;Deployment YAML for Version B&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-traffic-splitting-with-istio&quot;&gt;Traffic Splitting with Istio&lt;/h3&gt;&lt;h4 id=&quot;heading-virtualservice-for-ab-testing&quot;&gt;VirtualService for A/B Testing&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;50&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;50&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-destinationrule-for-ab-testing&quot;&gt;DestinationRule for A/B Testing&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DestinationRule&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;subsets:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-implement-ab-testing&quot;&gt;🛠 Steps to Implement A/B Testing&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Follow the steps above to install Istio and enable injection.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Two Versions of Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for both versions (v1 and v2).&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Traffic Splitting with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply a VirtualService and a DestinationRule to manage traffic between the two versions.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Analyze Results&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Monitor the performance and user experience of both versions to determine which performs better.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-explanation&quot;&gt;🔍 Detailed Example Explanation&lt;/h2&gt;&lt;h3 id=&quot;heading-ab-testing-1&quot;&gt;A/B Testing&lt;/h3&gt;&lt;p&gt;Running two versions simultaneously allows for direct comparisons in performance and user experience, with traffic split to gather meaningful data.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-splitting-1&quot;&gt;Traffic Splitting&lt;/h3&gt;&lt;p&gt;Using Istios VirtualService and DestinationRule facilitates fine-grained control over traffic routing between different versions of an application.&lt;/p&gt;&lt;h2 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data-Driven Decisions&lt;/strong&gt;: Provides concrete data to inform which version is superior.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved User Experience&lt;/strong&gt;: Helps identify which version offers a better user experience.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Controlled Testing&lt;/strong&gt;: Allows testing of new features without impacting the entire user base.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-additional-concepts-and-examples&quot;&gt;📚 Additional Concepts and Examples&lt;/h2&gt;&lt;h3 id=&quot;heading-adjusting-traffic-split&quot;&gt;Adjusting Traffic Split&lt;/h3&gt;&lt;p&gt;You can modify the traffic distribution based on testing requirements to favor one version over the other.&lt;/p&gt;&lt;h4 id=&quot;heading-example&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;30&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;70&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-monitoring-with-istio&quot;&gt;Monitoring with Istio&lt;/h3&gt;&lt;p&gt;Utilize Istios telemetry features to track the performance and user experience of each version during the A/B testing phase.&lt;/p&gt;&lt;h4 id=&quot;heading-example-1&quot;&gt;Example&lt;/h4&gt;&lt;p&gt;Configure Prometheus and Grafana to visualize Istio metrics and monitor application performance.&lt;/p&gt;&lt;h2 id=&quot;heading-hands-on-activity&quot;&gt;🧪 Hands-on Activity&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Follow the installation steps provided earlier.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Two Versions of Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply the deployment YAML for version A (v1) and version B (v2).&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Traffic Splitting with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply a VirtualService and a DestinationRule for traffic splitting.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Analyze Results&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Monitor both versions performance and analyze results to determine the better-performing version.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adjust Traffic Split&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the VirtualService as needed to change the traffic distribution based on testing outcomes.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use the following commands to check your setup:&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;    kubectl get services    kubectl describe services myapp    istioctl proxy-status&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-engage-and-reflect&quot;&gt;🤝 Engage and Reflect&lt;/h2&gt;&lt;p&gt;Understanding and implementing A/B testing is crucial for making data-driven decisions and improving user experience in your applications.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;💬 Engage With Us&lt;/strong&gt;: How do you plan to implement A/B testing in your Kubernetes projects? What challenges did you face while setting them up? Share your experiences and thoughts!&lt;/p&gt;&lt;p&gt;👉 Stay tuned for more learning opportunities and keep refining your Kubernetes knowledge to stay ahead in the ever-evolving tech landscape. Lets continue to explore, innovate, and automate!&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1721138150787/b2e66c0d-38e5-4284-9986-a99f77c820c3.png</hashnode:coverImage></item><item><title><![CDATA[Blue-Green Deployments in Kubernetes]]></title><description><![CDATA[🎯 Learning Objective
Understand how to perform blue-green deployments in Kubernetes to minimize downtime and risk during application updates.
📖 Scenario
You need to update your application in a Kubernetes cluster while ensuring minimal downtime and...]]></description><link>https://devopsvoyager.hashnode.dev/blue-green-deployments-in-kubernetes</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/blue-green-deployments-in-kubernetes</guid><category><![CDATA[Blue/Green deployment]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Wed, 16 Oct 2024 03:30:41 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h2&gt;&lt;p&gt;Understand how to perform blue-green deployments in Kubernetes to minimize downtime and risk during application updates.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h2&gt;&lt;p&gt;You need to update your application in a Kubernetes cluster while ensuring minimal downtime and risk by maintaining two identical environments: one for the current version (blue) and one for the new version (green).&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;📘 Explanation&lt;/h2&gt;&lt;p&gt;Blue-green deployments involve running two identical production environments, where the blue environment serves the current traffic and the green environment hosts the new version. After validating the new version, traffic is switched from blue to green, enabling a seamless update.&lt;/p&gt;&lt;h2 id=&quot;heading-key-concepts&quot;&gt;🔑 Key Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-blue-green-deployment&quot;&gt;Blue-Green Deployment&lt;/h3&gt;&lt;p&gt;A strategy that allows for zero-downtime deployments by using two identical environments.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-switching&quot;&gt;Traffic Switching&lt;/h3&gt;&lt;p&gt;Switching traffic between blue and green environments to promote the new version.&lt;/p&gt;&lt;h3 id=&quot;heading-rollback&quot;&gt;Rollback&lt;/h3&gt;&lt;p&gt;Reverting traffic back to the blue environment if issues are detected in the green environment.&lt;/p&gt;&lt;h2 id=&quot;heading-blue-green-deployment-setup&quot;&gt;📄 Blue-Green Deployment Setup&lt;/h2&gt;&lt;h3 id=&quot;heading-initial-setup-for-blue-environment&quot;&gt;Initial Setup for Blue Environment&lt;/h3&gt;&lt;p&gt;Deploy the initial version of your application in the blue environment.&lt;/p&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-blue-environment&quot;&gt;Deployment YAML for Blue Environment&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;hljs-meta&quot;&gt;---&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-deploy-new-version-in-green-environment&quot;&gt;Deploy New Version in Green Environment&lt;/h3&gt;&lt;p&gt;Deploy the new version of your application in the green environment.&lt;/p&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-green-environment&quot;&gt;Deployment YAML for Green Environment&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-green&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-traffic-management-with-service-selector&quot;&gt;Traffic Management with Service Selector&lt;/h3&gt;&lt;p&gt;Use Kubernetes services to switch traffic between the blue and green environments.&lt;/p&gt;&lt;h4 id=&quot;heading-update-service-selector-to-switch-traffic&quot;&gt;Update Service Selector to Switch Traffic&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-implement-blue-green-deployments&quot;&gt;🛠 Steps to Implement Blue-Green Deployments&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up the Blue Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Apply the deployment YAML for the blue environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure the service selector points to the blue environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Apply the deployment YAML for the green environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that the green environment is running correctly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Switch Traffic to the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Update the service selector to point to the green environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that traffic is being served by the green environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Verify&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Monitor the green environment for any issues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Roll back to the blue environment if necessary by updating the service selector.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-explanation&quot;&gt;🔍 Detailed Example Explanation&lt;/h2&gt;&lt;h3 id=&quot;heading-blue-green-deployment-1&quot;&gt;Blue-Green Deployment&lt;/h3&gt;&lt;p&gt;Running two identical environments ensures zero downtime during updates. Traffic is switched from blue to green after verifying the new version.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-switching-1&quot;&gt;Traffic Switching&lt;/h3&gt;&lt;p&gt;Updating the service selector enables seamless traffic switching between blue and green environments.&lt;/p&gt;&lt;h2 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zero Downtime&lt;/strong&gt;: Ensures updates are deployed with minimal or no downtime.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Risk Mitigation&lt;/strong&gt;: Allows thorough testing of the new version before traffic switch.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easy Rollback&lt;/strong&gt;: Simplifies reverting to the previous version if issues are detected.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-additional-concepts&quot;&gt;📚 Additional Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-rollback-to-blue-environment&quot;&gt;Rollback to Blue Environment&lt;/h3&gt;&lt;p&gt;If issues are detected in the green environment, update the service selector to revert to the blue environment.&lt;/p&gt;&lt;h4 id=&quot;heading-example&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-using-ingress-for-traffic-management&quot;&gt;Using Ingress for Traffic Management&lt;/h3&gt;&lt;p&gt;An ingress controller can manage traffic between the blue and green environments.&lt;/p&gt;&lt;h4 id=&quot;heading-example-1&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-ingress&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;rules:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp.example.com&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;paths:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;pathType:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Prefix&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;backend:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;service:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;number:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-hands-on-activity&quot;&gt;🧪 Hands-on Activity&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up the Blue Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply the deployment YAML for the blue environment, ensuring the service selector points to it.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply the deployment YAML for the green environment and verify it is running correctly.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Switch Traffic to the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the service selector to point to the green environment and verify traffic is served by it.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Verify&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Monitor the green environment for any issues and roll back to the blue environment if necessary.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Ingress for Traffic Management&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply an ingress resource to manage traffic between the environments.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use the following commands to verify the setup:&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;    kubectl get services    kubectl describe services myapp    kubectl get ingress&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-pros-and-cons-of-blue-green-deployments&quot;&gt;👍 Pros and 👎 Cons of Blue-Green Deployments&lt;/h2&gt;&lt;h3 id=&quot;heading-pros&quot;&gt;Pros&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zero Downtime&lt;/strong&gt;: Provides seamless transitions between application versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple Rollbacks&lt;/strong&gt;: Easy to revert to a stable version in case of issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-cons&quot;&gt;Cons&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resource Intensive&lt;/strong&gt;: Requires double the resources to run two environments simultaneously.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complexity&lt;/strong&gt;: The management of two environments can add complexity to the deployment process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-engage-and-reflect&quot;&gt;🤝 Engage and Reflect&lt;/h2&gt;&lt;p&gt;Understanding and implementing blue-green deployments is crucial for ensuring zero-downtime updates and minimizing risk during application deployments.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;💬 Engage With Us&lt;/strong&gt;: How do you plan to implement blue-green deployments in your Kubernetes projects? What challenges did you face while setting them up? Share your experiences and thoughts!&lt;/p&gt;&lt;p&gt;👉 Stay tuned for more learning opportunities and keep refining your Kubernetes knowledge to stay ahead in the ever-evolving tech landscape. Lets continue to explore, innovate, and automate together!&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h2&gt;&lt;p&gt;Understand how to perform blue-green deployments in Kubernetes to minimize downtime and risk during application updates.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h2&gt;&lt;p&gt;You need to update your application in a Kubernetes cluster while ensuring minimal downtime and risk by maintaining two identical environments: one for the current version (blue) and one for the new version (green).&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;📘 Explanation&lt;/h2&gt;&lt;p&gt;Blue-green deployments involve running two identical production environments, where the blue environment serves the current traffic and the green environment hosts the new version. After validating the new version, traffic is switched from blue to green, enabling a seamless update.&lt;/p&gt;&lt;h2 id=&quot;heading-key-concepts&quot;&gt;🔑 Key Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-blue-green-deployment&quot;&gt;Blue-Green Deployment&lt;/h3&gt;&lt;p&gt;A strategy that allows for zero-downtime deployments by using two identical environments.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-switching&quot;&gt;Traffic Switching&lt;/h3&gt;&lt;p&gt;Switching traffic between blue and green environments to promote the new version.&lt;/p&gt;&lt;h3 id=&quot;heading-rollback&quot;&gt;Rollback&lt;/h3&gt;&lt;p&gt;Reverting traffic back to the blue environment if issues are detected in the green environment.&lt;/p&gt;&lt;h2 id=&quot;heading-blue-green-deployment-setup&quot;&gt;📄 Blue-Green Deployment Setup&lt;/h2&gt;&lt;h3 id=&quot;heading-initial-setup-for-blue-environment&quot;&gt;Initial Setup for Blue Environment&lt;/h3&gt;&lt;p&gt;Deploy the initial version of your application in the blue environment.&lt;/p&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-blue-environment&quot;&gt;Deployment YAML for Blue Environment&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;hljs-meta&quot;&gt;---&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-deploy-new-version-in-green-environment&quot;&gt;Deploy New Version in Green Environment&lt;/h3&gt;&lt;p&gt;Deploy the new version of your application in the green environment.&lt;/p&gt;&lt;h4 id=&quot;heading-deployment-yaml-for-green-environment&quot;&gt;Deployment YAML for Green Environment&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-green&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-traffic-management-with-service-selector&quot;&gt;Traffic Management with Service Selector&lt;/h3&gt;&lt;p&gt;Use Kubernetes services to switch traffic between the blue and green environments.&lt;/p&gt;&lt;h4 id=&quot;heading-update-service-selector-to-switch-traffic&quot;&gt;Update Service Selector to Switch Traffic&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;green&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-implement-blue-green-deployments&quot;&gt;🛠 Steps to Implement Blue-Green Deployments&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up the Blue Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Apply the deployment YAML for the blue environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Ensure the service selector points to the blue environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Apply the deployment YAML for the green environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that the green environment is running correctly.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Switch Traffic to the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Update the service selector to point to the green environment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify that traffic is being served by the green environment.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Verify&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Monitor the green environment for any issues.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Roll back to the blue environment if necessary by updating the service selector.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-explanation&quot;&gt;🔍 Detailed Example Explanation&lt;/h2&gt;&lt;h3 id=&quot;heading-blue-green-deployment-1&quot;&gt;Blue-Green Deployment&lt;/h3&gt;&lt;p&gt;Running two identical environments ensures zero downtime during updates. Traffic is switched from blue to green after verifying the new version.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-switching-1&quot;&gt;Traffic Switching&lt;/h3&gt;&lt;p&gt;Updating the service selector enables seamless traffic switching between blue and green environments.&lt;/p&gt;&lt;h2 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zero Downtime&lt;/strong&gt;: Ensures updates are deployed with minimal or no downtime.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Risk Mitigation&lt;/strong&gt;: Allows thorough testing of the new version before traffic switch.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Easy Rollback&lt;/strong&gt;: Simplifies reverting to the previous version if issues are detected.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-additional-concepts&quot;&gt;📚 Additional Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-rollback-to-blue-environment&quot;&gt;Rollback to Blue Environment&lt;/h3&gt;&lt;p&gt;If issues are detected in the green environment, update the service selector to revert to the blue environment.&lt;/p&gt;&lt;h4 id=&quot;heading-example&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;blue&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-using-ingress-for-traffic-management&quot;&gt;Using Ingress for Traffic Management&lt;/h3&gt;&lt;p&gt;An ingress controller can manage traffic between the blue and green environments.&lt;/p&gt;&lt;h4 id=&quot;heading-example-1&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-ingress&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;rules:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp.example.com&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;paths:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;pathType:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Prefix&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;backend:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;service:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt;              &lt;span class=&quot;hljs-attr&quot;&gt;number:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-hands-on-activity&quot;&gt;🧪 Hands-on Activity&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up the Blue Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply the deployment YAML for the blue environment, ensuring the service selector points to it.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply the deployment YAML for the green environment and verify it is running correctly.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Switch Traffic to the Green Environment&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the service selector to point to the green environment and verify traffic is served by it.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor and Verify&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Monitor the green environment for any issues and roll back to the blue environment if necessary.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Ingress for Traffic Management&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply an ingress resource to manage traffic between the environments.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use the following commands to verify the setup:&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;    kubectl get services    kubectl describe services myapp    kubectl get ingress&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-pros-and-cons-of-blue-green-deployments&quot;&gt;👍 Pros and 👎 Cons of Blue-Green Deployments&lt;/h2&gt;&lt;h3 id=&quot;heading-pros&quot;&gt;Pros&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Zero Downtime&lt;/strong&gt;: Provides seamless transitions between application versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Simple Rollbacks&lt;/strong&gt;: Easy to revert to a stable version in case of issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-cons&quot;&gt;Cons&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resource Intensive&lt;/strong&gt;: Requires double the resources to run two environments simultaneously.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complexity&lt;/strong&gt;: The management of two environments can add complexity to the deployment process.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-engage-and-reflect&quot;&gt;🤝 Engage and Reflect&lt;/h2&gt;&lt;p&gt;Understanding and implementing blue-green deployments is crucial for ensuring zero-downtime updates and minimizing risk during application deployments.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;💬 Engage With Us&lt;/strong&gt;: How do you plan to implement blue-green deployments in your Kubernetes projects? What challenges did you face while setting them up? Share your experiences and thoughts!&lt;/p&gt;&lt;p&gt;👉 Stay tuned for more learning opportunities and keep refining your Kubernetes knowledge to stay ahead in the ever-evolving tech landscape. Lets continue to explore, innovate, and automate together!&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1721137913029/c48d2606-02dc-4401-9bff-89a5e95bac61.png</hashnode:coverImage></item><item><title><![CDATA[Implementing Canary Deployments in Kubernetes]]></title><description><![CDATA[Learning Goal
Learn how to execute canary deployments in Kubernetes to update your applications while reducing risks gradually.
Context
You need to update your application within a Kubernetes cluster, aiming to minimize potential issues by gradually ...]]></description><link>https://devopsvoyager.hashnode.dev/implementing-canary-deployments-in-kubernetes</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/implementing-canary-deployments-in-kubernetes</guid><category><![CDATA[Canary deployment]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[#istio]]></category><category><![CDATA[istio service mesh]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Tue, 15 Oct 2024 03:30:40 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-learning-goal&quot;&gt;Learning Goal&lt;/h1&gt;&lt;p&gt;Learn how to execute canary deployments in Kubernetes to update your applications while reducing risks gradually.&lt;/p&gt;&lt;h2 id=&quot;heading-context&quot;&gt;Context&lt;/h2&gt;&lt;p&gt;You need to update your application within a Kubernetes cluster, aiming to minimize potential issues by gradually introducing changes to a small group of users before a complete rollout.&lt;/p&gt;&lt;h2 id=&quot;heading-overview&quot;&gt;Overview&lt;/h2&gt;&lt;p&gt;Canary deployments enable you to release a new application version to a limited user base first, helping to identify potential issues early and ensuring minimal impact on users if problems arise.&lt;/p&gt;&lt;h2 id=&quot;heading-key-concepts&quot;&gt;Key Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-canary-deployment&quot;&gt;Canary Deployment&lt;/h3&gt;&lt;p&gt;A strategy that gradually rolls out changes to a small segment of users before full deployment.&lt;/p&gt;&lt;h3 id=&quot;heading-istio&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;An open-source service mesh that facilitates traffic management, security, and observability, making it ideal for canary deployments.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-management&quot;&gt;Traffic Management&lt;/h3&gt;&lt;p&gt;Directing network traffic to different application versions during a canary deployment.&lt;/p&gt;&lt;h2 id=&quot;heading-setting-up-a-canary-deployment-with-istio&quot;&gt;Setting Up a Canary Deployment with Istio&lt;/h2&gt;&lt;p&gt;Istio can effectively manage traffic between different application versions during a canary deployment.&lt;/p&gt;&lt;h3 id=&quot;heading-installing-istio&quot;&gt;Installing Istio&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download and Install Istio CLI&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -L https://istio.io/downloadIstio | sh - &lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.* &lt;span class=&quot;hljs-built_in&quot;&gt;export&lt;/span&gt; PATH=&lt;span class=&quot;hljs-variable&quot;&gt;$PWD&lt;/span&gt;/bin:&lt;span class=&quot;hljs-variable&quot;&gt;$PATH&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio in Your Cluster&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Label the Namespace for Istio Injection&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl label namespace default istio-injection=enabled&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-deploying-the-initial-version-of-the-application&quot;&gt;Deploying the Initial Version of the Application&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Deployment YAML for Version 1&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;hljs-meta&quot;&gt;---&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-deploying-the-canary-version-of-the-application&quot;&gt;Deploying the Canary Version of the Application&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Deployment YAML for Version 2&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-managing-traffic-with-istio&quot;&gt;Managing Traffic with Istio&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;VirtualService for Canary Deployment&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;90&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-destinationrule-for-canary-deployment&quot;&gt;DestinationRule for Canary Deployment&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DestinationRule&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;subsets:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-implement-canary-deployments&quot;&gt;Steps to Implement Canary Deployments&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install Istio CLI and set up Istio in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Label the namespace for Istio injection.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Initial Application Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 1.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Canary Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 2.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create and apply a VirtualService to route traffic between versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create and apply a DestinationRule to configure traffic policies.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gradually Increase Traffic to the Canary Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the VirtualService to increase traffic to version 2 while monitoring for issues.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-insights&quot;&gt;Detailed Example Insights&lt;/h2&gt;&lt;h3 id=&quot;heading-canary-deployment-1&quot;&gt;Canary Deployment&lt;/h3&gt;&lt;p&gt;Gradually introducing updates to a small user segment allows for early identification of issues, limiting user impact in case of problems.&lt;/p&gt;&lt;h3 id=&quot;heading-istio-1&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;Istio enables precise traffic management, allowing fine-grained control over traffic routing between application versions.&lt;/p&gt;&lt;h2 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;Benefits for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimized Risk&lt;/strong&gt;: Reduces the likelihood of introducing bugs by incrementally rolling out changes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Early Detection&lt;/strong&gt;: Identifies potential issues before full deployment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Controlled Rollback&lt;/strong&gt;: Facilitates easy rollback if issues arise during the canary phase.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-additional-concepts&quot;&gt;Additional Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-rollback-to-the-previous-version&quot;&gt;Rollback to the Previous Version&lt;/h3&gt;&lt;p&gt;If issues occur with version 2, update the VirtualService to revert all traffic back to version 1.&lt;/p&gt;&lt;h4 id=&quot;heading-example&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-monitoring-and-metrics-with-istio&quot;&gt;Monitoring and Metrics with Istio&lt;/h3&gt;&lt;p&gt;Utilize Istio&apos;s telemetry features to track performance and health during the canary deployment.&lt;/p&gt;&lt;h4 id=&quot;heading-example-1&quot;&gt;Example&lt;/h4&gt;&lt;p&gt;Set up Prometheus and Grafana to visualize Istio metrics for monitoring application performance.&lt;/p&gt;&lt;h2 id=&quot;heading-practical-activity-guide&quot;&gt;Practical Activity Guide&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Download and install the Istio CLI, set up Istio in the cluster, and label the namespace.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Initial Application Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 1.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Canary Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 2.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic Using Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create and apply the VirtualService and DestinationRule for traffic management.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gradually Increase Traffic&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the VirtualService to increase traffic to version 2 while monitoring for issues.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rollback if Necessary&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Modify the VirtualService to direct all traffic back to version 1 if issues arise.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Application Performance&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Istios telemetry features to assess the application&apos;s health and performance.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-engage-and-share-insights&quot;&gt;Engage and Share Insights&lt;/h2&gt;&lt;p&gt;Understanding and implementing canary deployments is crucial for safely updating applications and minimizing risks.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Wed love to hear from you!&lt;/strong&gt; How do you plan to adopt canary deployments in your Kubernetes projects? What challenges have you encountered? Share your experiences and insights!&lt;/p&gt;&lt;p&gt;Stay tuned for more educational content and continue advancing your Kubernetes knowledge to stay competitive in the fast-evolving tech landscape. Lets keep exploring, innovating, and automating together!&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-learning-goal&quot;&gt;Learning Goal&lt;/h1&gt;&lt;p&gt;Learn how to execute canary deployments in Kubernetes to update your applications while reducing risks gradually.&lt;/p&gt;&lt;h2 id=&quot;heading-context&quot;&gt;Context&lt;/h2&gt;&lt;p&gt;You need to update your application within a Kubernetes cluster, aiming to minimize potential issues by gradually introducing changes to a small group of users before a complete rollout.&lt;/p&gt;&lt;h2 id=&quot;heading-overview&quot;&gt;Overview&lt;/h2&gt;&lt;p&gt;Canary deployments enable you to release a new application version to a limited user base first, helping to identify potential issues early and ensuring minimal impact on users if problems arise.&lt;/p&gt;&lt;h2 id=&quot;heading-key-concepts&quot;&gt;Key Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-canary-deployment&quot;&gt;Canary Deployment&lt;/h3&gt;&lt;p&gt;A strategy that gradually rolls out changes to a small segment of users before full deployment.&lt;/p&gt;&lt;h3 id=&quot;heading-istio&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;An open-source service mesh that facilitates traffic management, security, and observability, making it ideal for canary deployments.&lt;/p&gt;&lt;h3 id=&quot;heading-traffic-management&quot;&gt;Traffic Management&lt;/h3&gt;&lt;p&gt;Directing network traffic to different application versions during a canary deployment.&lt;/p&gt;&lt;h2 id=&quot;heading-setting-up-a-canary-deployment-with-istio&quot;&gt;Setting Up a Canary Deployment with Istio&lt;/h2&gt;&lt;p&gt;Istio can effectively manage traffic between different application versions during a canary deployment.&lt;/p&gt;&lt;h3 id=&quot;heading-installing-istio&quot;&gt;Installing Istio&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download and Install Istio CLI&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -L https://istio.io/downloadIstio | sh - &lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.* &lt;span class=&quot;hljs-built_in&quot;&gt;export&lt;/span&gt; PATH=&lt;span class=&quot;hljs-variable&quot;&gt;$PWD&lt;/span&gt;/bin:&lt;span class=&quot;hljs-variable&quot;&gt;$PATH&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio in Your Cluster&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Label the Namespace for Istio Injection&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl label namespace default istio-injection=enabled&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-deploying-the-initial-version-of-the-application&quot;&gt;Deploying the Initial Version of the Application&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Deployment YAML for Version 1&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;span class=&quot;hljs-meta&quot;&gt;---&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-deploying-the-canary-version-of-the-application&quot;&gt;Deploying the Canary Version of the Application&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Deployment YAML for Version 2&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp-v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp:v2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-managing-traffic-with-istio&quot;&gt;Managing Traffic with Istio&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;VirtualService for Canary Deployment&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;90&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-destinationrule-for-canary-deployment&quot;&gt;DestinationRule for Canary Deployment&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DestinationRule&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;subsets:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-implement-canary-deployments&quot;&gt;Steps to Implement Canary Deployments&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install Istio CLI and set up Istio in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Label the namespace for Istio injection.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Initial Application Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 1.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Canary Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 2.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create and apply a VirtualService to route traffic between versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create and apply a DestinationRule to configure traffic policies.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gradually Increase Traffic to the Canary Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the VirtualService to increase traffic to version 2 while monitoring for issues.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-insights&quot;&gt;Detailed Example Insights&lt;/h2&gt;&lt;h3 id=&quot;heading-canary-deployment-1&quot;&gt;Canary Deployment&lt;/h3&gt;&lt;p&gt;Gradually introducing updates to a small user segment allows for early identification of issues, limiting user impact in case of problems.&lt;/p&gt;&lt;h3 id=&quot;heading-istio-1&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;Istio enables precise traffic management, allowing fine-grained control over traffic routing between application versions.&lt;/p&gt;&lt;h2 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;Benefits for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Minimized Risk&lt;/strong&gt;: Reduces the likelihood of introducing bugs by incrementally rolling out changes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Early Detection&lt;/strong&gt;: Identifies potential issues before full deployment.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Controlled Rollback&lt;/strong&gt;: Facilitates easy rollback if issues arise during the canary phase.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-additional-concepts&quot;&gt;Additional Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-rollback-to-the-previous-version&quot;&gt;Rollback to the Previous Version&lt;/h3&gt;&lt;p&gt;If issues occur with version 2, update the VirtualService to revert all traffic back to version 1.&lt;/p&gt;&lt;h4 id=&quot;heading-example&quot;&gt;Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-monitoring-and-metrics-with-istio&quot;&gt;Monitoring and Metrics with Istio&lt;/h3&gt;&lt;p&gt;Utilize Istio&apos;s telemetry features to track performance and health during the canary deployment.&lt;/p&gt;&lt;h4 id=&quot;heading-example-1&quot;&gt;Example&lt;/h4&gt;&lt;p&gt;Set up Prometheus and Grafana to visualize Istio metrics for monitoring application performance.&lt;/p&gt;&lt;h2 id=&quot;heading-practical-activity-guide&quot;&gt;Practical Activity Guide&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Download and install the Istio CLI, set up Istio in the cluster, and label the namespace.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Initial Application Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 1.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Canary Version&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Apply the deployment YAML for version 2.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic Using Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create and apply the VirtualService and DestinationRule for traffic management.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Gradually Increase Traffic&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Update the VirtualService to increase traffic to version 2 while monitoring for issues.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rollback if Necessary&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Modify the VirtualService to direct all traffic back to version 1 if issues arise.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Application Performance&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Istios telemetry features to assess the application&apos;s health and performance.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-engage-and-share-insights&quot;&gt;Engage and Share Insights&lt;/h2&gt;&lt;p&gt;Understanding and implementing canary deployments is crucial for safely updating applications and minimizing risks.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Wed love to hear from you!&lt;/strong&gt; How do you plan to adopt canary deployments in your Kubernetes projects? What challenges have you encountered? Share your experiences and insights!&lt;/p&gt;&lt;p&gt;Stay tuned for more educational content and continue advancing your Kubernetes knowledge to stay competitive in the fast-evolving tech landscape. Lets keep exploring, innovating, and automating together!&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1721137388284/29399b88-5f1c-40f5-bb6a-ec20c67e9f38.png</hashnode:coverImage></item><item><title><![CDATA[Networking in Kubernetes: Enhancing Microservices with a Service Mesh]]></title><description><![CDATA[Learning Goal
Gain insights into managing Kubernetes networking and improving microservices communication through Istio.
Context
You are tasked with overseeing networking within your Kubernetes cluster and optimizing microservices interactions by uti...]]></description><link>https://devopsvoyager.hashnode.dev/networking-in-kubernetes-enhancing-microservices-with-a-service-mesh</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/networking-in-kubernetes-enhancing-microservices-with-a-service-mesh</guid><category><![CDATA[service mesh]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Mon, 14 Oct 2024 03:30:20 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-goal&quot;&gt;Learning Goal&lt;/h2&gt;&lt;p&gt;Gain insights into managing Kubernetes networking and improving microservices communication through Istio.&lt;/p&gt;&lt;h2 id=&quot;heading-context&quot;&gt;Context&lt;/h2&gt;&lt;p&gt;You are tasked with overseeing networking within your Kubernetes cluster and optimizing microservices interactions by utilizing Istio for capabilities such as traffic control, security, and monitoring.&lt;/p&gt;&lt;h2 id=&quot;heading-overview&quot;&gt;Overview&lt;/h2&gt;&lt;p&gt;Kubernetes networking is essential for facilitating communication among Pods, services, and external endpoints. Implementing a Service Mesh like Istio adds advanced features for traffic management, security, and observability, significantly improving microservices interactions.&lt;/p&gt;&lt;h2 id=&quot;heading-core-concepts&quot;&gt;Core Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-kubernetes-networking&quot;&gt;Kubernetes Networking&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Facilitates communication&lt;/strong&gt; among Pods, services, and external systems.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-service-mesh&quot;&gt;Service Mesh&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Infrastructure layer&lt;/strong&gt; that oversees service-to-service communication, often incorporating traffic management, security, and observability.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-istio&quot;&gt;Istio&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Open-source service mesh&lt;/strong&gt; that simplifies microservices management with capabilities for traffic control, security, and monitoring.&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-understanding-kubernetes-networking&quot;&gt;Understanding Kubernetes Networking&lt;/h2&gt;&lt;p&gt;Kubernetes employs various networking models and components to manage communications within the cluster.&lt;/p&gt;&lt;h3 id=&quot;heading-types-of-services&quot;&gt;Types of Services&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;ClusterIP&lt;/strong&gt;: Internal IP exposure within the cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;NodePort&lt;/strong&gt;: Service exposure via static ports on each Node&apos;s IP.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;LoadBalancer&lt;/strong&gt;: External service exposure using a cloud provider&apos;s load balancer.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;ExternalName&lt;/strong&gt;: Maps the service to a DNS name.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-clusterip-service-example&quot;&gt;ClusterIP Service Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-clusterip-service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ClusterIP&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-network-policy-example&quot;&gt;Network Policy Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;allow-app&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-exploring-istio-service-mesh&quot;&gt;Exploring Istio Service Mesh&lt;/h2&gt;&lt;p&gt;Istio enhances microservices communication by offering sophisticated traffic management, security, and observability.&lt;/p&gt;&lt;h3 id=&quot;heading-installing-istio&quot;&gt;Installing Istio&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download and Install Istio CLI&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -L https://istio.io/downloadIstio | sh - &lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.* &lt;span class=&quot;hljs-built_in&quot;&gt;export&lt;/span&gt; PATH=&lt;span class=&quot;hljs-variable&quot;&gt;$PWD&lt;/span&gt;/bin:&lt;span class=&quot;hljs-variable&quot;&gt;$PATH&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio in your Cluster&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Label Namespace for Istio Injection&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl label namespace default istio-injection=enabled&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-deploying-a-sample-application&quot;&gt;Deploying a Sample Application&lt;/h3&gt;&lt;p&gt;Deploy the Bookinfo application using the following command:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Verify the deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl get pods&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-traffic-management-using-istio&quot;&gt;Traffic Management Using Istio&lt;/h2&gt;&lt;p&gt;Istio provides extensive traffic management features, including routing, retries, and circuit breaking.&lt;/p&gt;&lt;h3 id=&quot;heading-virtualservice-example&quot;&gt;VirtualService Example&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;75&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-destinationrule-example&quot;&gt;DestinationRule Example&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DestinationRule&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;subsets:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;trafficPolicy:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;connectionPool:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;tcp:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;maxConnections:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;http1MaxPendingRequests:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1000&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;maxRequestsPerConnection:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;outlierDetection:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;consecutiveErrors:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;interval:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;10s&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;baseEjectionTime:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;30s&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;maxEjectionPercent:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-for-implementing-kubernetes-networking-and-istio&quot;&gt;Steps for Implementing Kubernetes Networking and Istio&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Establish Kubernetes Networking&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create and apply a ClusterIP service using the provided YAML definition.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set up a Network Policy to manage traffic flow between Pods.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Configure Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Download and install the Istio CLI.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Install Istio in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Label the default namespace for Istio injection.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy a Sample Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Deploy the Bookinfo sample application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify the deployment status to ensure Pods are operational.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Define and apply a VirtualService to handle traffic routing across different service versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create and apply a DestinationRule to configure traffic policies and connection settings.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-in-depth-example-insights&quot;&gt;In-Depth Example Insights&lt;/h2&gt;&lt;h3 id=&quot;heading-kubernetes-networking-1&quot;&gt;Kubernetes Networking&lt;/h3&gt;&lt;p&gt;Kubernetes networking organizes communications between Pods and services using various service types and network policies to secure traffic flow.&lt;/p&gt;&lt;h3 id=&quot;heading-istio-1&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;Istio elevates microservices interactions by providing advanced traffic management, security, and observability features, creating a powerful service mesh solution.&lt;/p&gt;&lt;h2 id=&quot;heading-advantages-for-enterprise-applications&quot;&gt;Advantages for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sophisticated Traffic Management&lt;/strong&gt;: Enables granular control over traffic routing, retries, and circuit breaking.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Security&lt;/strong&gt;: Secures service-to-service communication through mutual TLS and access policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Observability&lt;/strong&gt;: Offers comprehensive telemetry, logging, and tracing for better insight into service performance.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts&quot;&gt;Additional Concepts&lt;/h3&gt;&lt;h4 id=&quot;heading-mutual-tls-with-istio&quot;&gt;Mutual TLS with Istio&lt;/h4&gt;&lt;p&gt;Enable mutual TLS for securing inter-service communications.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;security.istio.io/v1beta1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PeerAuthentication&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;mtls:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;mode:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;STRICT&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-istio-telemetry-and-monitoring&quot;&gt;Istio Telemetry and Monitoring&lt;/h4&gt;&lt;p&gt;Utilize Istios telemetry features to gather and visualize metrics.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ConfigMap&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;istio-system&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;data:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;prometheus.yml:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;|    global:      scrape_interval: 15s    scrape_configs:    - job_name: &apos;istio&apos;      static_configs:      - targets: [&apos;localhost:15090&apos;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-practical-activity-guide&quot;&gt;Practical Activity Guide&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Establish Kubernetes Networking&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply a ClusterIP service along with a Network Policy.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Configure Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Download and set up the Istio CLI, install Istio in the cluster, and label the default namespace for Istio injection.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Sample Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy the Bookinfo sample application and confirm the deployment.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic Using Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create and apply a VirtualService and DestinationRule for effective traffic management.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Mutual TLS&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and implement a PeerAuthentication policy to activate mutual TLS.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure Istio Telemetry and Monitoring&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Set up Prometheus to collect Istio metrics and visualize them.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verification and Inspection&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use &lt;code&gt;kubectl get services&lt;/code&gt;, &lt;code&gt;kubectl get networkpolicies&lt;/code&gt;, and &lt;code&gt;kubectl describe&lt;/code&gt; to confirm the networking setup.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate Istio setup and application deployment using &lt;code&gt;istioctl proxy-status&lt;/code&gt; and &lt;code&gt;kubectl get pods&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-engage-and-share-insights&quot;&gt;Engage and Share Insights&lt;/h2&gt;&lt;p&gt;Understanding Kubernetes networking and implementing a service mesh like Istio is vital for effectively managing microservices communication in complex environments.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Wed love to hear from you!&lt;/strong&gt; How do you plan to manage networking and service communication in your Kubernetes projects? What challenges did you encounter while setting up Istio? Share your thoughts and experiences!&lt;/p&gt;&lt;p&gt;Stay tuned for more learning resources and continue enhancing your Kubernetes expertise to thrive in the rapidly evolving tech landscape. Lets keep exploring, innovating, and automating together!&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-goal&quot;&gt;Learning Goal&lt;/h2&gt;&lt;p&gt;Gain insights into managing Kubernetes networking and improving microservices communication through Istio.&lt;/p&gt;&lt;h2 id=&quot;heading-context&quot;&gt;Context&lt;/h2&gt;&lt;p&gt;You are tasked with overseeing networking within your Kubernetes cluster and optimizing microservices interactions by utilizing Istio for capabilities such as traffic control, security, and monitoring.&lt;/p&gt;&lt;h2 id=&quot;heading-overview&quot;&gt;Overview&lt;/h2&gt;&lt;p&gt;Kubernetes networking is essential for facilitating communication among Pods, services, and external endpoints. Implementing a Service Mesh like Istio adds advanced features for traffic management, security, and observability, significantly improving microservices interactions.&lt;/p&gt;&lt;h2 id=&quot;heading-core-concepts&quot;&gt;Core Concepts&lt;/h2&gt;&lt;h3 id=&quot;heading-kubernetes-networking&quot;&gt;Kubernetes Networking&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Facilitates communication&lt;/strong&gt; among Pods, services, and external systems.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-service-mesh&quot;&gt;Service Mesh&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Infrastructure layer&lt;/strong&gt; that oversees service-to-service communication, often incorporating traffic management, security, and observability.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-istio&quot;&gt;Istio&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Open-source service mesh&lt;/strong&gt; that simplifies microservices management with capabilities for traffic control, security, and monitoring.&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-understanding-kubernetes-networking&quot;&gt;Understanding Kubernetes Networking&lt;/h2&gt;&lt;p&gt;Kubernetes employs various networking models and components to manage communications within the cluster.&lt;/p&gt;&lt;h3 id=&quot;heading-types-of-services&quot;&gt;Types of Services&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;ClusterIP&lt;/strong&gt;: Internal IP exposure within the cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;NodePort&lt;/strong&gt;: Service exposure via static ports on each Node&apos;s IP.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;LoadBalancer&lt;/strong&gt;: External service exposure using a cloud provider&apos;s load balancer.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;ExternalName&lt;/strong&gt;: Maps the service to a DNS name.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-clusterip-service-example&quot;&gt;ClusterIP Service Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-clusterip-service&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;targetPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;type:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ClusterIP&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-network-policy-example&quot;&gt;Network Policy Example&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;allow-app&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;myapp&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-exploring-istio-service-mesh&quot;&gt;Exploring Istio Service Mesh&lt;/h2&gt;&lt;p&gt;Istio enhances microservices communication by offering sophisticated traffic management, security, and observability.&lt;/p&gt;&lt;h3 id=&quot;heading-installing-istio&quot;&gt;Installing Istio&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download and Install Istio CLI&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -L https://istio.io/downloadIstio | sh - &lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.* &lt;span class=&quot;hljs-built_in&quot;&gt;export&lt;/span&gt; PATH=&lt;span class=&quot;hljs-variable&quot;&gt;$PWD&lt;/span&gt;/bin:&lt;span class=&quot;hljs-variable&quot;&gt;$PATH&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio in your Cluster&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Label Namespace for Istio Injection&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; kubectl label namespace default istio-injection=enabled&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-deploying-a-sample-application&quot;&gt;Deploying a Sample Application&lt;/h3&gt;&lt;p&gt;Deploy the Bookinfo application using the following command:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Verify the deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl get pods&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-traffic-management-using-istio&quot;&gt;Traffic Management Using Istio&lt;/h2&gt;&lt;p&gt;Istio provides extensive traffic management features, including routing, retries, and circuit breaking.&lt;/p&gt;&lt;h3 id=&quot;heading-virtualservice-example&quot;&gt;VirtualService Example&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;75&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-destinationrule-example&quot;&gt;DestinationRule Example&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DestinationRule&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;subsets:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;trafficPolicy:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;connectionPool:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;tcp:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;maxConnections:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;http1MaxPendingRequests:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1000&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;maxRequestsPerConnection:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;outlierDetection:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;consecutiveErrors:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;interval:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;10s&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;baseEjectionTime:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;30s&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;maxEjectionPercent:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;100&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-for-implementing-kubernetes-networking-and-istio&quot;&gt;Steps for Implementing Kubernetes Networking and Istio&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Establish Kubernetes Networking&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create and apply a ClusterIP service using the provided YAML definition.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set up a Network Policy to manage traffic flow between Pods.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Configure Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Download and install the Istio CLI.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Install Istio in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Label the default namespace for Istio injection.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy a Sample Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Deploy the Bookinfo sample application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Verify the deployment status to ensure Pods are operational.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic with Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Define and apply a VirtualService to handle traffic routing across different service versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Create and apply a DestinationRule to configure traffic policies and connection settings.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-in-depth-example-insights&quot;&gt;In-Depth Example Insights&lt;/h2&gt;&lt;h3 id=&quot;heading-kubernetes-networking-1&quot;&gt;Kubernetes Networking&lt;/h3&gt;&lt;p&gt;Kubernetes networking organizes communications between Pods and services using various service types and network policies to secure traffic flow.&lt;/p&gt;&lt;h3 id=&quot;heading-istio-1&quot;&gt;Istio&lt;/h3&gt;&lt;p&gt;Istio elevates microservices interactions by providing advanced traffic management, security, and observability features, creating a powerful service mesh solution.&lt;/p&gt;&lt;h2 id=&quot;heading-advantages-for-enterprise-applications&quot;&gt;Advantages for Enterprise Applications&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sophisticated Traffic Management&lt;/strong&gt;: Enables granular control over traffic routing, retries, and circuit breaking.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Security&lt;/strong&gt;: Secures service-to-service communication through mutual TLS and access policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Observability&lt;/strong&gt;: Offers comprehensive telemetry, logging, and tracing for better insight into service performance.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts&quot;&gt;Additional Concepts&lt;/h3&gt;&lt;h4 id=&quot;heading-mutual-tls-with-istio&quot;&gt;Mutual TLS with Istio&lt;/h4&gt;&lt;p&gt;Enable mutual TLS for securing inter-service communications.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;security.istio.io/v1beta1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PeerAuthentication&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;mtls:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;mode:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;STRICT&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-istio-telemetry-and-monitoring&quot;&gt;Istio Telemetry and Monitoring&lt;/h4&gt;&lt;p&gt;Utilize Istios telemetry features to gather and visualize metrics.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ConfigMap&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;istio-system&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;data:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;prometheus.yml:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;|    global:      scrape_interval: 15s    scrape_configs:    - job_name: &apos;istio&apos;      static_configs:      - targets: [&apos;localhost:15090&apos;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-practical-activity-guide&quot;&gt;Practical Activity Guide&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Establish Kubernetes Networking&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply a ClusterIP service along with a Network Policy.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Configure Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Download and set up the Istio CLI, install Istio in the cluster, and label the default namespace for Istio injection.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the Sample Application&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy the Bookinfo sample application and confirm the deployment.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Traffic Using Istio&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Create and apply a VirtualService and DestinationRule for effective traffic management.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Mutual TLS&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and implement a PeerAuthentication policy to activate mutual TLS.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configure Istio Telemetry and Monitoring&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Set up Prometheus to collect Istio metrics and visualize them.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verification and Inspection&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Use &lt;code&gt;kubectl get services&lt;/code&gt;, &lt;code&gt;kubectl get networkpolicies&lt;/code&gt;, and &lt;code&gt;kubectl describe&lt;/code&gt; to confirm the networking setup.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Validate Istio setup and application deployment using &lt;code&gt;istioctl proxy-status&lt;/code&gt; and &lt;code&gt;kubectl get pods&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-engage-and-share-insights&quot;&gt;Engage and Share Insights&lt;/h2&gt;&lt;p&gt;Understanding Kubernetes networking and implementing a service mesh like Istio is vital for effectively managing microservices communication in complex environments.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Wed love to hear from you!&lt;/strong&gt; How do you plan to manage networking and service communication in your Kubernetes projects? What challenges did you encounter while setting up Istio? Share your thoughts and experiences!&lt;/p&gt;&lt;p&gt;Stay tuned for more learning resources and continue enhancing your Kubernetes expertise to thrive in the rapidly evolving tech landscape. Lets keep exploring, innovating, and automating together!&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1721136873558/8a9e00ea-6899-4107-98f6-533f8bacdc96.png</hashnode:coverImage></item><item><title><![CDATA[K8s: Multi-Cluster Management]]></title><description><![CDATA[🎯 Learning Objective
Understand how to manage multiple Kubernetes clusters using tools and strategies that provide centralized control, monitoring, and deployment.
📖 Scenario
It would help if you managed multiple Kubernetes clusters across differen...]]></description><link>https://devopsvoyager.hashnode.dev/k8s-multi-cluster-management</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/k8s-multi-cluster-management</guid><category><![CDATA[multi cluster management]]></category><category><![CDATA[multi-cluster-setup]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Sun, 13 Oct 2024 03:30:34 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h2&gt;&lt;p&gt;Understand how to manage multiple Kubernetes clusters using tools and strategies that provide centralized control, monitoring, and deployment.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h2&gt;&lt;p&gt;It would help if you managed multiple Kubernetes clusters across different environments (e.g., development, staging, production) to ensure consistency, security, and ease of administration.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;Explanation&lt;/h2&gt;&lt;p&gt;Managing multiple Kubernetes clusters can be complex without proper tools and strategies. Centralized management tools like Rancher, Kubernetes Federation (KubeFed), and GitOps provide a unified way to control, monitor, and deploy across multiple clusters.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts&quot;&gt;🔑 Key Concepts:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Cluster Management&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Managing multiple Kubernetes clusters from a single control plane.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;An open-source multi-cluster Kubernetes management platform.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Kubernetes Federation (KubeFed)&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A tool for coordinating the configuration of multiple Kubernetes clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;GitOps&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A model where Git is the single source of truth for the system&apos;s desired state and changes are automatically applied to the clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-rancher-installation&quot;&gt;Rancher Installation&lt;/h2&gt;&lt;p&gt;Rancher is an open-source platform for managing multiple Kubernetes clusters.&lt;/p&gt;&lt;h4 id=&quot;heading-install-rancher&quot;&gt;📑 Install Rancher:&lt;/h4&gt;&lt;p&gt;Deploy Rancher using Docker:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;sudo docker run -d --restart=unless-stopped \-p 80:80 -p 443:443 \rancher/rancher:latest&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Access the Rancher UI:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Open a web browser and navigate to &lt;code&gt;https://&amp;lt;your-server-ip&amp;gt;&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-kubernetes-federation-kubefed-setup&quot;&gt;Kubernetes Federation (KubeFed) Setup&lt;/h2&gt;&lt;p&gt;KubeFed allows you to coordinate configuration across multiple Kubernetes clusters.&lt;/p&gt;&lt;h4 id=&quot;heading-install-kubefed&quot;&gt;📑 Install KubeFed:&lt;/h4&gt;&lt;p&gt;Install KubeFed CLI (kubefedctl):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;wget https://github.com/kubernetes-sigs/kubefed/releases/download/v0.7.0/kubefedctl-$(uname | tr &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:upper:]&apos;&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:lower:]&apos;&lt;/span&gt;)-amd64chmod +x kubefedctl-$(uname | tr &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:upper:]&apos;&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:lower:]&apos;&lt;/span&gt;)-amd64sudo mv kubefedctl-$(uname | tr &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:upper:]&apos;&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:lower:]&apos;&lt;/span&gt;)-amd64 /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin/kubefedctl&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deploy KubeFed to the Host Cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl create ns kube-federation-systemkubefedctl join &amp;lt;HOST_CLUSTER&amp;gt; --cluster-context &amp;lt;HOST_CONTEXT&amp;gt; --host-cluster-context &amp;lt;HOST_CONTEXT&amp;gt; --v=2&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Join Member Clusters:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubefedctl join &amp;lt;MEMBER_CLUSTER&amp;gt; --cluster-context &amp;lt;MEMBER_CONTEXT&amp;gt; --host-cluster-context &amp;lt;HOST_CONTEXT&amp;gt; --v=2&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-gitops-setup&quot;&gt;GitOps Setup&lt;/h2&gt;&lt;p&gt;GitOps uses Git as the single source of truth for your clusters desired state, with tools like Argo CD or Flux to apply changes.&lt;/p&gt;&lt;h4 id=&quot;heading-install-argo-cd&quot;&gt;📑 Install Argo CD:&lt;/h4&gt;&lt;p&gt;Install Argo CD in your Kubernetes cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl create namespace argocdkubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Access the Argo CD UI:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Forward the Argo CD server port to your local machine:&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl port-forward svc/argocd-server -n argocd 8080:443&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;Open a web browser and navigate to &lt;a target=&quot;_blank&quot; href=&quot;https://localhost:8080&quot;&gt;&lt;code&gt;https://localhost:8080&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-steps-to-implement-multi-cluster-management&quot;&gt;Steps to Implement Multi-Cluster Management&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Access Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Deploy Rancher using Docker.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access the Rancher UI via the web browser.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Kubernetes Federation (KubeFed)&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install the KubeFed CLI.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy KubeFed to the host cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Join member clusters to the federation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement GitOps with Argo CD&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install Argo CD in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access the Argo CD UI via port forwarding.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-detailed-example-explanation&quot;&gt;🔍 Detailed Example Explanation:&lt;/h3&gt;&lt;h4 id=&quot;heading-rancher&quot;&gt;Rancher:&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Provides a web-based UI for managing multiple Kubernetes clusters&lt;/strong&gt;, including provisioning, upgrades, monitoring, and security management.&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-kubefed&quot;&gt;KubeFed:&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Enables you to manage multiple clusters as a single entity&lt;/strong&gt;, allowing for consistent configuration and resource management across clusters.&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-gitops-with-argo-cd&quot;&gt;GitOps with Argo CD:&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Argo CD continuously monitors Git repositories and applies changes to Kubernetes clusters&lt;/strong&gt;, ensuring the desired state is always maintained.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Centralized Management&lt;/strong&gt;: Simplifies the management of multiple clusters from a single control plane.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Ensures consistent configuration and policies across clusters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Easily manage and scale applications across multiple clusters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Disaster Recovery&lt;/strong&gt;: Provides high availability and disaster recovery by distributing workloads across clusters.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-additional-concepts-and-examples&quot;&gt;Additional Concepts and Examples&lt;/h2&gt;&lt;h3 id=&quot;heading-rancher-cluster-management&quot;&gt;Rancher Cluster Management:&lt;/h3&gt;&lt;p&gt;Use Rancher to create, import, and manage Kubernetes clusters.&lt;/p&gt;&lt;h5 id=&quot;heading-example&quot;&gt;Example:&lt;/h5&gt;&lt;p&gt;Creating a new cluster in Rancher:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use the Rancher UI to create a new cluster&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-federated-resources-with-kubefed&quot;&gt;Federated Resources with KubeFed:&lt;/h3&gt;&lt;p&gt;Use KubeFed to manage federated resources across clusters.&lt;/p&gt;&lt;h5 id=&quot;heading-example-1&quot;&gt;Example:&lt;/h5&gt;&lt;p&gt;Creating a federated deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;types.kubefed.io/v1beta1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;FederatedDeployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx:1.14.2&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-gitops-workflow-with-argo-cd&quot;&gt;GitOps Workflow with Argo CD:&lt;/h3&gt;&lt;p&gt;Use Argo CD to deploy applications and manage configuration across clusters.&lt;/p&gt;&lt;h5 id=&quot;heading-example-2&quot;&gt;Example:&lt;/h5&gt;&lt;p&gt;Creating an Argo CD application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;argoproj.io/v1alpha1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;guestbook&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;argocd&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;project:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;source:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;repoURL:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;https://github.com/argoproj/argocd-example-apps.git&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetRevision:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;HEAD&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;guestbook&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;server:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;https://kubernetes.default.svc&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;syncPolicy:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;automated:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;prune:&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;selfHeal:&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Access Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy Rancher and access its UI via a web browser.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Kubernetes Federation (KubeFed)&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Install the KubeFed CLI, deploy KubeFed, and join member clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement GitOps with Argo CD&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Install Argo CD, access its UI, and create an application for deployment.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Clusters with Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Rancher to create, import, and manage clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create Federated Resources with KubeFed&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply federated resources across clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Applications with Argo CD&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Argo CD to deploy and manage applications across clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Rancher, KubeFed, and Argo CD UIs and commands to verify and inspect multi-cluster management.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Following these steps, you can effectively manage multiple Kubernetes clusters, ensuring consistency, security, and ease of administration across different environments.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h2 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h2&gt;&lt;p&gt;Understand how to manage multiple Kubernetes clusters using tools and strategies that provide centralized control, monitoring, and deployment.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h2&gt;&lt;p&gt;It would help if you managed multiple Kubernetes clusters across different environments (e.g., development, staging, production) to ensure consistency, security, and ease of administration.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;Explanation&lt;/h2&gt;&lt;p&gt;Managing multiple Kubernetes clusters can be complex without proper tools and strategies. Centralized management tools like Rancher, Kubernetes Federation (KubeFed), and GitOps provide a unified way to control, monitor, and deploy across multiple clusters.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts&quot;&gt;🔑 Key Concepts:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Multi-Cluster Management&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Managing multiple Kubernetes clusters from a single control plane.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;An open-source multi-cluster Kubernetes management platform.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Kubernetes Federation (KubeFed)&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A tool for coordinating the configuration of multiple Kubernetes clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;GitOps&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;A model where Git is the single source of truth for the system&apos;s desired state and changes are automatically applied to the clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-rancher-installation&quot;&gt;Rancher Installation&lt;/h2&gt;&lt;p&gt;Rancher is an open-source platform for managing multiple Kubernetes clusters.&lt;/p&gt;&lt;h4 id=&quot;heading-install-rancher&quot;&gt;📑 Install Rancher:&lt;/h4&gt;&lt;p&gt;Deploy Rancher using Docker:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;sudo docker run -d --restart=unless-stopped \-p 80:80 -p 443:443 \rancher/rancher:latest&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Access the Rancher UI:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Open a web browser and navigate to &lt;code&gt;https://&amp;lt;your-server-ip&amp;gt;&lt;/code&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-kubernetes-federation-kubefed-setup&quot;&gt;Kubernetes Federation (KubeFed) Setup&lt;/h2&gt;&lt;p&gt;KubeFed allows you to coordinate configuration across multiple Kubernetes clusters.&lt;/p&gt;&lt;h4 id=&quot;heading-install-kubefed&quot;&gt;📑 Install KubeFed:&lt;/h4&gt;&lt;p&gt;Install KubeFed CLI (kubefedctl):&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;wget https://github.com/kubernetes-sigs/kubefed/releases/download/v0.7.0/kubefedctl-$(uname | tr &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:upper:]&apos;&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:lower:]&apos;&lt;/span&gt;)-amd64chmod +x kubefedctl-$(uname | tr &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:upper:]&apos;&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:lower:]&apos;&lt;/span&gt;)-amd64sudo mv kubefedctl-$(uname | tr &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:upper:]&apos;&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;[:lower:]&apos;&lt;/span&gt;)-amd64 /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin/kubefedctl&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Deploy KubeFed to the Host Cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl create ns kube-federation-systemkubefedctl join &amp;lt;HOST_CLUSTER&amp;gt; --cluster-context &amp;lt;HOST_CONTEXT&amp;gt; --host-cluster-context &amp;lt;HOST_CONTEXT&amp;gt; --v=2&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Join Member Clusters:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubefedctl join &amp;lt;MEMBER_CLUSTER&amp;gt; --cluster-context &amp;lt;MEMBER_CONTEXT&amp;gt; --host-cluster-context &amp;lt;HOST_CONTEXT&amp;gt; --v=2&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-gitops-setup&quot;&gt;GitOps Setup&lt;/h2&gt;&lt;p&gt;GitOps uses Git as the single source of truth for your clusters desired state, with tools like Argo CD or Flux to apply changes.&lt;/p&gt;&lt;h4 id=&quot;heading-install-argo-cd&quot;&gt;📑 Install Argo CD:&lt;/h4&gt;&lt;p&gt;Install Argo CD in your Kubernetes cluster:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl create namespace argocdkubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Access the Argo CD UI:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Forward the Argo CD server port to your local machine:&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl port-forward svc/argocd-server -n argocd 8080:443&lt;/code&gt;&lt;/pre&gt;&lt;ul&gt;&lt;li&gt;Open a web browser and navigate to &lt;a target=&quot;_blank&quot; href=&quot;https://localhost:8080&quot;&gt;&lt;code&gt;https://localhost:8080&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-steps-to-implement-multi-cluster-management&quot;&gt;Steps to Implement Multi-Cluster Management&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Access Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Deploy Rancher using Docker.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access the Rancher UI via the web browser.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Kubernetes Federation (KubeFed)&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install the KubeFed CLI.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy KubeFed to the host cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Join member clusters to the federation.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement GitOps with Argo CD&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Install Argo CD in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Access the Argo CD UI via port forwarding.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-detailed-example-explanation&quot;&gt;🔍 Detailed Example Explanation:&lt;/h3&gt;&lt;h4 id=&quot;heading-rancher&quot;&gt;Rancher:&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Provides a web-based UI for managing multiple Kubernetes clusters&lt;/strong&gt;, including provisioning, upgrades, monitoring, and security management.&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-kubefed&quot;&gt;KubeFed:&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Enables you to manage multiple clusters as a single entity&lt;/strong&gt;, allowing for consistent configuration and resource management across clusters.&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-gitops-with-argo-cd&quot;&gt;GitOps with Argo CD:&lt;/h4&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Argo CD continuously monitors Git repositories and applies changes to Kubernetes clusters&lt;/strong&gt;, ensuring the desired state is always maintained.&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Centralized Management&lt;/strong&gt;: Simplifies the management of multiple clusters from a single control plane.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Ensures consistent configuration and policies across clusters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scalability&lt;/strong&gt;: Easily manage and scale applications across multiple clusters.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Disaster Recovery&lt;/strong&gt;: Provides high availability and disaster recovery by distributing workloads across clusters.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-additional-concepts-and-examples&quot;&gt;Additional Concepts and Examples&lt;/h2&gt;&lt;h3 id=&quot;heading-rancher-cluster-management&quot;&gt;Rancher Cluster Management:&lt;/h3&gt;&lt;p&gt;Use Rancher to create, import, and manage Kubernetes clusters.&lt;/p&gt;&lt;h5 id=&quot;heading-example&quot;&gt;Example:&lt;/h5&gt;&lt;p&gt;Creating a new cluster in Rancher:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use the Rancher UI to create a new cluster&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-federated-resources-with-kubefed&quot;&gt;Federated Resources with KubeFed:&lt;/h3&gt;&lt;p&gt;Use KubeFed to manage federated resources across clusters.&lt;/p&gt;&lt;h5 id=&quot;heading-example-1&quot;&gt;Example:&lt;/h5&gt;&lt;p&gt;Creating a federated deployment:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;types.kubefed.io/v1beta1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;FederatedDeployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;          &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;nginx:1.14.2&lt;/span&gt;            &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;            &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-gitops-workflow-with-argo-cd&quot;&gt;GitOps Workflow with Argo CD:&lt;/h3&gt;&lt;p&gt;Use Argo CD to deploy applications and manage configuration across clusters.&lt;/p&gt;&lt;h5 id=&quot;heading-example-2&quot;&gt;Example:&lt;/h5&gt;&lt;p&gt;Creating an Argo CD application:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;argoproj.io/v1alpha1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Application&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;guestbook&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;argocd&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;project:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;source:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;repoURL:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;https://github.com/argoproj/argocd-example-apps.git&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;targetRevision:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;HEAD&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;guestbook&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;server:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;https://kubernetes.default.svc&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;syncPolicy:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;automated:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;prune:&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;selfHeal:&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity:&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install and Access Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Deploy Rancher and access its UI via a web browser.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Set Up Kubernetes Federation (KubeFed)&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Install the KubeFed CLI, deploy KubeFed, and join member clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement GitOps with Argo CD&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Install Argo CD, access its UI, and create an application for deployment.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Manage Clusters with Rancher&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Rancher to create, import, and manage clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create Federated Resources with KubeFed&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Define and apply federated resources across clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Applications with Argo CD&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Argo CD to deploy and manage applications across clusters.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Use Rancher, KubeFed, and Argo CD UIs and commands to verify and inspect multi-cluster management.&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Following these steps, you can effectively manage multiple Kubernetes clusters, ensuring consistency, security, and ease of administration across different environments.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1720707710521/d0c7973a-ae48-4b24-b9bd-eb1760fb9ee9.png</hashnode:coverImage></item><item><title><![CDATA[Kubernetes: Backup and Disaster Recovery]]></title><description><![CDATA[Introduction
In the fast-paced world of Kubernetes deployments, ensuring data protection and application continuity is paramount. This article explores the essential concepts and practical steps for implementing robust backup and disaster recovery (D...]]></description><link>https://devopsvoyager.hashnode.dev/kubernetes-backup-and-disaster-recovery</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/kubernetes-backup-and-disaster-recovery</guid><category><![CDATA[backup and discovery recovery]]></category><category><![CDATA[Backup Strategy]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Sat, 12 Oct 2024 03:30:51 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;In the fast-paced world of Kubernetes deployments, ensuring data protection and application continuity is paramount. This article explores the essential concepts and practical steps for implementing robust backup and disaster recovery (DR) strategies using tools like Velero.&lt;/p&gt;&lt;h3 id=&quot;heading-learning-objective&quot;&gt;Learning Objective&lt;/h3&gt;&lt;p&gt;The primary goal is to understand how to safeguard Kubernetes clusters and applications against failures or disasters by employing reliable backup and disaster recovery mechanisms.&lt;/p&gt;&lt;h3 id=&quot;heading-scenario&quot;&gt;Scenario&lt;/h3&gt;&lt;p&gt;Imagine managing a Kubernetes environment where continuous uptime and data integrity are critical. To mitigate risks from hardware failures, human errors, or unforeseen disasters, implementing effective backup and disaster recovery strategies becomes imperative.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;Explanation&lt;/h2&gt;&lt;h3 id=&quot;heading-backup&quot;&gt;Backup&lt;/h3&gt;&lt;p&gt;Regularly saving copies of Kubernetes resources and persistent volumes is essential to prevent data loss. Backups serve as a safety net against accidental deletions, corruption, or system failures.&lt;/p&gt;&lt;h3 id=&quot;heading-disaster-recovery&quot;&gt;Disaster Recovery&lt;/h3&gt;&lt;p&gt;Disaster recovery involves strategies and tools to restore data and applications swiftly to a functional state after a disaster strikes. This ensures minimal downtime and uninterrupted service delivery.&lt;/p&gt;&lt;h2 id=&quot;heading-velero-installation&quot;&gt;Velero Installation&lt;/h2&gt;&lt;p&gt;Velero, an open-source tool, simplifies backup, recovery, and migration of Kubernetes cluster resources and persistent volumes. Let&apos;s walk through the installation process:&lt;/p&gt;&lt;h3 id=&quot;heading-install-velero-cli&quot;&gt;Install Velero CLI&lt;/h3&gt;&lt;p&gt;First, download and install the Velero CLI on your management machine or Kubernetes master node:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;wget https://github.com/vmware-tanzu/velero/releases/download/v1.6.3/velero-v1.6.3-linux-amd64.tar.gztar -xvf velero-v1.6.3-linux-amd64.tar.gzsudo mv velero-v1.6.3-linux-amd64/velero /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin/&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-deploy-velero&quot;&gt;Deploy Velero&lt;/h3&gt;&lt;p&gt;Deploy Velero into your Kubernetes cluster, configuring it to use an S3-compatible storage service for backups. Replace placeholders with your actual S3 bucket details:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero install \    --provider aws \    --plugins velero/velero-plugin-for-aws:v1.2.0 \    --bucket &amp;lt;YOUR_BUCKET_NAME&amp;gt; \    --secret-file ./credentials-velero \    --backup-location-config region=&amp;lt;YOUR_REGION&amp;gt;,s3ForcePathStyle=&lt;span class=&quot;hljs-string&quot;&gt;&quot;true&quot;&lt;/span&gt;,s3Url=&amp;lt;YOUR_S3_URL&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-backup-and-restore-operations&quot;&gt;Backup and Restore Operations&lt;/h2&gt;&lt;p&gt;Once Velero is set up, you can perform essential backup and restore operations using its CLI:&lt;/p&gt;&lt;h3 id=&quot;heading-create-a-backup&quot;&gt;Create a Backup&lt;/h3&gt;&lt;p&gt;Initiate a backup of Kubernetes resources, specifying the namespaces to include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero backup create my-backup --include-namespaces default&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-verify-backup&quot;&gt;Verify Backup&lt;/h3&gt;&lt;p&gt;Check the details of a specific backup to ensure it is completed successfully:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero backup describe my-backup --details&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-restore-from-backup&quot;&gt;Restore from Backup&lt;/h3&gt;&lt;p&gt;Deploy resources and persistent volumes from a backup to restore your cluster&apos;s state:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero restore create --from-backup my-backup&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-steps-to-implement-backup-and-disaster-recovery&quot;&gt;Steps to Implement Backup and Disaster Recovery&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Velero CLI:&lt;/strong&gt; Download and install the Velero CLI for managing backups and restores.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Velero:&lt;/strong&gt; Configure and deploy Velero into your Kubernetes cluster with appropriate storage configurations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Backup:&lt;/strong&gt; Initiate backups of Kubernetes resources and persistent volumes using Velero.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Backup:&lt;/strong&gt; Confirm the success and details of created backups to ensure data integrity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Restore from Backup:&lt;/strong&gt; Utilize Velero to restore applications and data swiftly in case of failures or disasters.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-detailed-example-explanation&quot;&gt;Detailed Example Explanation&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Velero:&lt;/strong&gt;&lt;br /&gt;Velero facilitates reliable backup and recovery of Kubernetes resources and persistent volumes across various cloud providers.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Backup:&lt;/strong&gt;&lt;br /&gt;Regular backups ensure data availability and protection against unexpected data loss scenarios.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Restore:&lt;/strong&gt;&lt;br /&gt;Quick restoration from backups minimizes downtime and ensures the continuity of critical services.&lt;/p&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;Benefits for Enterprise Applications&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Protection:&lt;/strong&gt; Ensures data integrity and availability through scheduled backups and efficient recovery mechanisms.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Application Continuity:&lt;/strong&gt; Maintains seamless operations by swiftly recovering from disruptions or failures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compliance:&lt;/strong&gt; Meets regulatory requirements for data retention and disaster recovery capabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts-and-examples&quot;&gt;Additional Concepts and Examples&lt;/h3&gt;&lt;h4 id=&quot;heading-scheduled-backups&quot;&gt;Scheduled Backups&lt;/h4&gt;&lt;p&gt;Automate backups at regular intervals to ensure continuous data protection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero create schedule my-daily-backup --schedule=&lt;span class=&quot;hljs-string&quot;&gt;&quot;0 2 * * *&quot;&lt;/span&gt; --include-namespaces default&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-backup-with-custom-labels&quot;&gt;Backup with Custom Labels&lt;/h4&gt;&lt;p&gt;Add custom labels to backups for better organization and management:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero backup create my-backup --include-namespaces default --labels purpose=testing,env=dev&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Velero CLI:&lt;/strong&gt; Download and set up the Velero CLI as per the provided instructions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Velero:&lt;/strong&gt; Configure and deploy Velero into your Kubernetes cluster using the deployment script.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Backup:&lt;/strong&gt; Initiate a backup to protect Kubernetes resources and persistent volumes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect:&lt;/strong&gt; Use Velero commands to verify backups and inspect restore operations for confidence in data recovery capabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Mastering backup and disaster recovery in Kubernetes with tools like Velero empowers organizations to safeguard critical data, uphold service availability, and adhere to stringent compliance requirements. By following best practices and leveraging automation, teams can effectively mitigate risks and ensure business continuity in dynamic cloud-native environments.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;In the fast-paced world of Kubernetes deployments, ensuring data protection and application continuity is paramount. This article explores the essential concepts and practical steps for implementing robust backup and disaster recovery (DR) strategies using tools like Velero.&lt;/p&gt;&lt;h3 id=&quot;heading-learning-objective&quot;&gt;Learning Objective&lt;/h3&gt;&lt;p&gt;The primary goal is to understand how to safeguard Kubernetes clusters and applications against failures or disasters by employing reliable backup and disaster recovery mechanisms.&lt;/p&gt;&lt;h3 id=&quot;heading-scenario&quot;&gt;Scenario&lt;/h3&gt;&lt;p&gt;Imagine managing a Kubernetes environment where continuous uptime and data integrity are critical. To mitigate risks from hardware failures, human errors, or unforeseen disasters, implementing effective backup and disaster recovery strategies becomes imperative.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;Explanation&lt;/h2&gt;&lt;h3 id=&quot;heading-backup&quot;&gt;Backup&lt;/h3&gt;&lt;p&gt;Regularly saving copies of Kubernetes resources and persistent volumes is essential to prevent data loss. Backups serve as a safety net against accidental deletions, corruption, or system failures.&lt;/p&gt;&lt;h3 id=&quot;heading-disaster-recovery&quot;&gt;Disaster Recovery&lt;/h3&gt;&lt;p&gt;Disaster recovery involves strategies and tools to restore data and applications swiftly to a functional state after a disaster strikes. This ensures minimal downtime and uninterrupted service delivery.&lt;/p&gt;&lt;h2 id=&quot;heading-velero-installation&quot;&gt;Velero Installation&lt;/h2&gt;&lt;p&gt;Velero, an open-source tool, simplifies backup, recovery, and migration of Kubernetes cluster resources and persistent volumes. Let&apos;s walk through the installation process:&lt;/p&gt;&lt;h3 id=&quot;heading-install-velero-cli&quot;&gt;Install Velero CLI&lt;/h3&gt;&lt;p&gt;First, download and install the Velero CLI on your management machine or Kubernetes master node:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;wget https://github.com/vmware-tanzu/velero/releases/download/v1.6.3/velero-v1.6.3-linux-amd64.tar.gztar -xvf velero-v1.6.3-linux-amd64.tar.gzsudo mv velero-v1.6.3-linux-amd64/velero /usr/&lt;span class=&quot;hljs-built_in&quot;&gt;local&lt;/span&gt;/bin/&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-deploy-velero&quot;&gt;Deploy Velero&lt;/h3&gt;&lt;p&gt;Deploy Velero into your Kubernetes cluster, configuring it to use an S3-compatible storage service for backups. Replace placeholders with your actual S3 bucket details:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero install \    --provider aws \    --plugins velero/velero-plugin-for-aws:v1.2.0 \    --bucket &amp;lt;YOUR_BUCKET_NAME&amp;gt; \    --secret-file ./credentials-velero \    --backup-location-config region=&amp;lt;YOUR_REGION&amp;gt;,s3ForcePathStyle=&lt;span class=&quot;hljs-string&quot;&gt;&quot;true&quot;&lt;/span&gt;,s3Url=&amp;lt;YOUR_S3_URL&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-backup-and-restore-operations&quot;&gt;Backup and Restore Operations&lt;/h2&gt;&lt;p&gt;Once Velero is set up, you can perform essential backup and restore operations using its CLI:&lt;/p&gt;&lt;h3 id=&quot;heading-create-a-backup&quot;&gt;Create a Backup&lt;/h3&gt;&lt;p&gt;Initiate a backup of Kubernetes resources, specifying the namespaces to include:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero backup create my-backup --include-namespaces default&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-verify-backup&quot;&gt;Verify Backup&lt;/h3&gt;&lt;p&gt;Check the details of a specific backup to ensure it is completed successfully:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero backup describe my-backup --details&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-restore-from-backup&quot;&gt;Restore from Backup&lt;/h3&gt;&lt;p&gt;Deploy resources and persistent volumes from a backup to restore your cluster&apos;s state:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero restore create --from-backup my-backup&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-steps-to-implement-backup-and-disaster-recovery&quot;&gt;Steps to Implement Backup and Disaster Recovery&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Velero CLI:&lt;/strong&gt; Download and install the Velero CLI for managing backups and restores.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Velero:&lt;/strong&gt; Configure and deploy Velero into your Kubernetes cluster with appropriate storage configurations.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Backup:&lt;/strong&gt; Initiate backups of Kubernetes resources and persistent volumes using Velero.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Backup:&lt;/strong&gt; Confirm the success and details of created backups to ensure data integrity.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Restore from Backup:&lt;/strong&gt; Utilize Velero to restore applications and data swiftly in case of failures or disasters.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-detailed-example-explanation&quot;&gt;Detailed Example Explanation&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Velero:&lt;/strong&gt;&lt;br /&gt;Velero facilitates reliable backup and recovery of Kubernetes resources and persistent volumes across various cloud providers.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Backup:&lt;/strong&gt;&lt;br /&gt;Regular backups ensure data availability and protection against unexpected data loss scenarios.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Restore:&lt;/strong&gt;&lt;br /&gt;Quick restoration from backups minimizes downtime and ensures the continuity of critical services.&lt;/p&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;Benefits for Enterprise Applications&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Data Protection:&lt;/strong&gt; Ensures data integrity and availability through scheduled backups and efficient recovery mechanisms.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Application Continuity:&lt;/strong&gt; Maintains seamless operations by swiftly recovering from disruptions or failures.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Compliance:&lt;/strong&gt; Meets regulatory requirements for data retention and disaster recovery capabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts-and-examples&quot;&gt;Additional Concepts and Examples&lt;/h3&gt;&lt;h4 id=&quot;heading-scheduled-backups&quot;&gt;Scheduled Backups&lt;/h4&gt;&lt;p&gt;Automate backups at regular intervals to ensure continuous data protection:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero create schedule my-daily-backup --schedule=&lt;span class=&quot;hljs-string&quot;&gt;&quot;0 2 * * *&quot;&lt;/span&gt; --include-namespaces default&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-backup-with-custom-labels&quot;&gt;Backup with Custom Labels&lt;/h4&gt;&lt;p&gt;Add custom labels to backups for better organization and management:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;velero backup create my-backup --include-namespaces default --labels purpose=testing,env=dev&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Velero CLI:&lt;/strong&gt; Download and set up the Velero CLI as per the provided instructions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Velero:&lt;/strong&gt; Configure and deploy Velero into your Kubernetes cluster using the deployment script.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a Backup:&lt;/strong&gt; Initiate a backup to protect Kubernetes resources and persistent volumes.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect:&lt;/strong&gt; Use Velero commands to verify backups and inspect restore operations for confidence in data recovery capabilities.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Mastering backup and disaster recovery in Kubernetes with tools like Velero empowers organizations to safeguard critical data, uphold service availability, and adhere to stringent compliance requirements. By following best practices and leveraging automation, teams can effectively mitigate risks and ensure business continuity in dynamic cloud-native environments.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1720704782910/0d6f7231-8683-4446-8844-643ba643ec2a.png</hashnode:coverImage></item><item><title><![CDATA[Logging and Monitoring in k8s]]></title><description><![CDATA[Introduction
In the dynamic landscape of Kubernetes, effective management of applications and infrastructure demands robust logging and monitoring solutions. These tools not only provide visibility into the performance and health of your cluster but ...]]></description><link>https://devopsvoyager.hashnode.dev/logging-and-monitoring-in-k8s</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/logging-and-monitoring-in-k8s</guid><category><![CDATA[logging]]></category><category><![CDATA[monitoring]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Fri, 11 Oct 2024 03:30:40 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;In the dynamic landscape of Kubernetes, effective management of applications and infrastructure demands robust logging and monitoring solutions. These tools not only provide visibility into the performance and health of your cluster but also enable rapid detection and resolution of issues. By leveraging technologies like the EFK stack (Fluentd, Elasticsearch, Kibana) for logging and Prometheus with Grafana for monitoring, teams can achieve comprehensive insights and proactive management capabilities.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;Scenario&lt;/h2&gt;&lt;p&gt;You&apos;re tasked with ensuring optimal performance and quick issue resolution for your Kubernetes applications and clusters. Implementing robust logging and monitoring solutions is essential to achieving this goal.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;Explanation&lt;/h2&gt;&lt;p&gt;Logging and monitoring play pivotal roles in maintaining the stability and efficiency of Kubernetes environments. Tools like the EFK stack (Fluentd, Elasticsearch, Kibana) for logging, and Prometheus with Grafana for monitoring, provide comprehensive capabilities to collect, store, visualize logs, and metrics.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts&quot;&gt;Key Concepts&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Logging:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Collects, stores, and analyzes logs generated by applications and Kubernetes components.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tools: Fluentd, Elasticsearch, Kibana (EFK stack).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Monitoring:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Collects, stores, and visualizes metrics to monitor the performance and health of the Kubernetes cluster and applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tools: Prometheus and Grafana.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-logging-setup-with-efk-stack&quot;&gt;Logging Setup with EFK Stack&lt;/h2&gt;&lt;p&gt;Implement the EFK stack to manage logs effectively:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Fluentd DaemonSet&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DaemonSet&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kube-system&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluent/fluentd-kubernetes-daemonset:v1.11.1-debian-elasticsearch7-1.0&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;env:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;FLUENT_ELASTICSEARCH_HOST&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;elasticsearch.logging.svc&quot;&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;FLUENT_ELASTICSEARCH_PORT&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;9200&quot;&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlog&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/log&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlibdockercontainers&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/lib/docker/containers&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;readOnly:&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlog&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;hostPath:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/log&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlibdockercontainers&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;hostPath:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/lib/docker/containers&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Elasticsearch Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;docker.elastic.co/elasticsearch/elasticsearch:7.9.2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;env:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;discovery.type&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;single-node&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;9200&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;http&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;9300&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Kibana Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;docker.elastic.co/kibana/kibana:7.9.2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5601&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-monitoring-setup-with-prometheus-and-grafana&quot;&gt;📄 Monitoring Setup with Prometheus and Grafana&lt;/h4&gt;&lt;p&gt;Deploy Prometheus and Grafana for comprehensive monitoring:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Prometheus Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;monitoring&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prom/prometheus:v2.20.1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;args:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--config.file=/etc/prometheus/prometheus.yml&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;9090&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config-volume&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/etc/prometheus&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;storage-volume&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/prometheus&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config-volume&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;configMap:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus-config&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;storage-volume&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;emptyDir:&lt;/span&gt; {}&lt;span class=&quot;hljs-comment&quot;&gt;# Grafana Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;monitoring&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana/grafana:7.1.5&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3000&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/etc/grafana&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;configMap:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana-config&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-set-up-logging-and-monitoring&quot;&gt;Steps to Set Up Logging and Monitoring&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the EFK Stack:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create the logging namespace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy Elasticsearch, Fluentd DaemonSet, and Kibana.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Prometheus and Grafana:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create the monitoring namespace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy Prometheus and Grafana to collect, store, and visualize metrics.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-explanation&quot;&gt;Detailed Example Explanation&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;EFK Stack:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fluentd:&lt;/strong&gt; Collects and forwards logs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Elasticsearch:&lt;/strong&gt; Stores and indexes logs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Kibana:&lt;/strong&gt; Provides a web UI for log visualization.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Prometheus and Grafana:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prometheus:&lt;/strong&gt; Gathers and stores metrics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Grafana:&lt;/strong&gt; Offers a visual interface for monitoring and creating dashboards.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Visibility:&lt;/strong&gt; Gain clear insights into cluster and application performance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Troubleshooting:&lt;/strong&gt; Quickly diagnose issues by analyzing logs and metrics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Proactive Management:&lt;/strong&gt; Use alerts and dashboards to stay ahead of potential problems.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts-and-examples&quot;&gt;Additional Concepts and Examples&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Prometheus Configuration:&lt;/strong&gt; Define scraping jobs to collect metrics from Kubernetes nodes, pods, and services.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Grafana Configuration:&lt;/strong&gt; Configure Grafana to connect to Prometheus and create custom dashboards.&lt;/p&gt;&lt;h3 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the EFK Stack:&lt;/strong&gt; Set up logging with Elasticsearch, Fluentd, and Kibana.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Prometheus and Grafana:&lt;/strong&gt; Implement monitoring with Prometheus and Grafana.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Tasks:&lt;/strong&gt; Define scraping jobs and configure Grafana dashboards.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt; Ensure deployments are successful using &lt;code&gt;kubectl get pods&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Implementing logging and monitoring in Kubernetes is pivotal for ensuring the reliability and efficiency of your applications. The EFK stack facilitates centralized log management, while Prometheus and Grafana offer powerful metrics collection and visualization. By setting up these tools, organizations can monitor key metrics, troubleshoot efficiently, and maintain optimal performance across their Kubernetes deployments. Embrace these solutions to elevate your operational capabilities and drive continuous improvement in your infrastructure management practices.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;In the dynamic landscape of Kubernetes, effective management of applications and infrastructure demands robust logging and monitoring solutions. These tools not only provide visibility into the performance and health of your cluster but also enable rapid detection and resolution of issues. By leveraging technologies like the EFK stack (Fluentd, Elasticsearch, Kibana) for logging and Prometheus with Grafana for monitoring, teams can achieve comprehensive insights and proactive management capabilities.&lt;/p&gt;&lt;h2 id=&quot;heading-scenario&quot;&gt;Scenario&lt;/h2&gt;&lt;p&gt;You&apos;re tasked with ensuring optimal performance and quick issue resolution for your Kubernetes applications and clusters. Implementing robust logging and monitoring solutions is essential to achieving this goal.&lt;/p&gt;&lt;h2 id=&quot;heading-explanation&quot;&gt;Explanation&lt;/h2&gt;&lt;p&gt;Logging and monitoring play pivotal roles in maintaining the stability and efficiency of Kubernetes environments. Tools like the EFK stack (Fluentd, Elasticsearch, Kibana) for logging, and Prometheus with Grafana for monitoring, provide comprehensive capabilities to collect, store, visualize logs, and metrics.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts&quot;&gt;Key Concepts&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Logging:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Collects, stores, and analyzes logs generated by applications and Kubernetes components.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tools: Fluentd, Elasticsearch, Kibana (EFK stack).&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Monitoring:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Collects, stores, and visualizes metrics to monitor the performance and health of the Kubernetes cluster and applications.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Tools: Prometheus and Grafana.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-logging-setup-with-efk-stack&quot;&gt;Logging Setup with EFK Stack&lt;/h2&gt;&lt;p&gt;Implement the EFK stack to manage logs effectively:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Fluentd DaemonSet&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;DaemonSet&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kube-system&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluentd&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;fluent/fluentd-kubernetes-daemonset:v1.11.1-debian-elasticsearch7-1.0&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;env:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;FLUENT_ELASTICSEARCH_HOST&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;elasticsearch.logging.svc&quot;&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;FLUENT_ELASTICSEARCH_PORT&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;9200&quot;&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlog&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/log&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlibdockercontainers&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/lib/docker/containers&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;readOnly:&lt;/span&gt; &lt;span class=&quot;hljs-literal&quot;&gt;true&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlog&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;hostPath:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/log&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;varlibdockercontainers&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;hostPath:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;path:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/var/lib/docker/containers&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Elasticsearch Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;elasticsearch&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;docker.elastic.co/elasticsearch/elasticsearch:7.9.2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;env:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;discovery.type&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;value:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;single-node&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;9200&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;http&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;9300&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Kibana Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;logging&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;kibana&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;docker.elastic.co/kibana/kibana:7.9.2&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5601&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-monitoring-setup-with-prometheus-and-grafana&quot;&gt;📄 Monitoring Setup with Prometheus and Grafana&lt;/h4&gt;&lt;p&gt;Deploy Prometheus and Grafana for comprehensive monitoring:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;# Prometheus Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;monitoring&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prom/prometheus:v2.20.1&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;args:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;--config.file=/etc/prometheus/prometheus.yml&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;9090&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config-volume&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/etc/prometheus&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;storage-volume&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/prometheus&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config-volume&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;configMap:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;prometheus-config&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;storage-volume&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;emptyDir:&lt;/span&gt; {}&lt;span class=&quot;hljs-comment&quot;&gt;# Grafana Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;apps/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deployment&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;monitoring&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;replicas:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;selector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;template:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;labels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;containers:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;image:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana/grafana:7.1.5&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;containerPort:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;3000&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;volumeMounts:&lt;/span&gt;        &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;mountPath:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;/etc/grafana&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;volumes:&lt;/span&gt;      &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;config&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;configMap:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;grafana-config&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-set-up-logging-and-monitoring&quot;&gt;Steps to Set Up Logging and Monitoring&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the EFK Stack:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create the logging namespace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy Elasticsearch, Fluentd DaemonSet, and Kibana.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Prometheus and Grafana:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Create the monitoring namespace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Deploy Prometheus and Grafana to collect, store, and visualize metrics.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-detailed-example-explanation&quot;&gt;Detailed Example Explanation&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;EFK Stack:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fluentd:&lt;/strong&gt; Collects and forwards logs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Elasticsearch:&lt;/strong&gt; Stores and indexes logs.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Kibana:&lt;/strong&gt; Provides a web UI for log visualization.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Prometheus and Grafana:&lt;/strong&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prometheus:&lt;/strong&gt; Gathers and stores metrics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Grafana:&lt;/strong&gt; Offers a visual interface for monitoring and creating dashboards.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;💡 Benefits for Enterprise Applications&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Visibility:&lt;/strong&gt; Gain clear insights into cluster and application performance.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Troubleshooting:&lt;/strong&gt; Quickly diagnose issues by analyzing logs and metrics.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Proactive Management:&lt;/strong&gt; Use alerts and dashboards to stay ahead of potential problems.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts-and-examples&quot;&gt;Additional Concepts and Examples&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Prometheus Configuration:&lt;/strong&gt; Define scraping jobs to collect metrics from Kubernetes nodes, pods, and services.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Grafana Configuration:&lt;/strong&gt; Configure Grafana to connect to Prometheus and create custom dashboards.&lt;/p&gt;&lt;h3 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy the EFK Stack:&lt;/strong&gt; Set up logging with Elasticsearch, Fluentd, and Kibana.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Prometheus and Grafana:&lt;/strong&gt; Implement monitoring with Prometheus and Grafana.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Configuration Tasks:&lt;/strong&gt; Define scraping jobs and configure Grafana dashboards.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verification:&lt;/strong&gt; Ensure deployments are successful using &lt;code&gt;kubectl get pods&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Implementing logging and monitoring in Kubernetes is pivotal for ensuring the reliability and efficiency of your applications. The EFK stack facilitates centralized log management, while Prometheus and Grafana offer powerful metrics collection and visualization. By setting up these tools, organizations can monitor key metrics, troubleshoot efficiently, and maintain optimal performance across their Kubernetes deployments. Embrace these solutions to elevate your operational capabilities and drive continuous improvement in your infrastructure management practices.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1720613424554/05ff7695-c2d6-44d8-a3b9-d04e9fe26e90.png</hashnode:coverImage></item><item><title><![CDATA[Kubernetes Service Mesh with Istio]]></title><description><![CDATA[🎯 Learning Objective
Learn how to implement Istio, a Service Mesh, within Kubernetes to manage and secure microservices communication effectively.
📖 Scenario
You want to improve the observability, security, and resilience of your microservices arch...]]></description><link>https://devopsvoyager.hashnode.dev/kubernetes-service-mesh-with-istio</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/kubernetes-service-mesh-with-istio</guid><category><![CDATA[service mesh]]></category><category><![CDATA[#istio]]></category><category><![CDATA[istio service mesh]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Thu, 10 Oct 2024 03:30:14 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h3 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h3&gt;&lt;p&gt;Learn how to implement Istio, a Service Mesh, within Kubernetes to manage and secure microservices communication effectively.&lt;/p&gt;&lt;h3 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h3&gt;&lt;p&gt;You want to improve the observability, security, and resilience of your microservices architecture running in Kubernetes. Istio offers a solution to manage traffic, enforce policies, and gather telemetry data without requiring changes to your application code.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Service Mesh:&lt;/strong&gt;&lt;br /&gt;A dedicated infrastructure layer handling communication between services within Kubernetes.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Istio:&lt;/strong&gt;&lt;br /&gt;An open-source Service Mesh that simplifies service-to-service communications by managing traffic, enforcing security policies, and providing observability through metrics, logs, and traces.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Envoy Proxy:&lt;/strong&gt;&lt;br /&gt;A high-performance proxy deployed alongside each service to manage inbound and outbound traffic, enforcing policies and collecting telemetry data.&lt;/p&gt;&lt;h3 id=&quot;heading-istio-installation&quot;&gt;Istio Installation&lt;/h3&gt;&lt;p&gt;To begin using Istio in your Kubernetes cluster, follow these steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download Istio Installation Script:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -L https://istio.io/downloadIstio | sh - &lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.*&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-deploy-a-sample-application-with-istio&quot;&gt;Deploy a Sample Application with Istio&lt;/h3&gt;&lt;p&gt;Deploy the Bookinfo sample application, consisting of multiple microservices:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-enable-istio-injection&quot;&gt;Enable Istio Injection&lt;/h3&gt;&lt;p&gt;Automatically inject Istio sidecars into pods in the default namespace:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl label namespace default istio-injection=enabledkubectl delete -f samples/bookinfo/platform/kube/bookinfo.yamlkubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-set-up-and-use-istio&quot;&gt;Steps to Set Up and Use Istio&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio:&lt;/strong&gt;&lt;br /&gt; Download and install Istio using the provided script.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Installation:&lt;/strong&gt;&lt;br /&gt; Check Istio and Kubernetes pods to ensure everything is running correctly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy a Sample Application:&lt;/strong&gt;&lt;br /&gt; Deploy the Bookinfo application to test Istio&apos;s capabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Istio Injection:&lt;/strong&gt;&lt;br /&gt; Label the default namespace to enable Istio sidecar injection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Redeploy the Application:&lt;/strong&gt;&lt;br /&gt; Update your application deployment to include Istio sidecars.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-istio-components&quot;&gt;&lt;strong&gt;Istio Components&lt;/strong&gt;&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pilot:&lt;/strong&gt; Manages traffic and service discovery.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixer:&lt;/strong&gt; Enforces access control and usage policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Citadel:&lt;/strong&gt; Manages certificates and identities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Galley:&lt;/strong&gt; Validates configurations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Envoy Proxy:&lt;/strong&gt; Each service includes an Envoy proxy sidecar for handling traffic, enforcing policies, and collecting telemetry data.&lt;/p&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;Benefits for Enterprise Applications&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traffic Management:&lt;/strong&gt; Control traffic flow and API calls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security:&lt;/strong&gt; Implement mutual TLS for secure communication.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observability:&lt;/strong&gt; Collect metrics, logs, and traces.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resilience:&lt;/strong&gt; Enhance fault tolerance with retries and circuit breakers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts-amp-examples&quot;&gt;Additional Concepts &amp;amp; Examples&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Traffic Shifting:&lt;/strong&gt; Gradually shift traffic between service versions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;75&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Mutual TLS:&lt;/strong&gt; Enable mutual TLS for secure service-to-service communication.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;security.istio.io/v1beta1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PeerAuthentication&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;mtls:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;mode:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;STRICT&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio:&lt;/strong&gt;&lt;br /&gt; Use the provided commands to install Istio in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Bookinfo Application:&lt;/strong&gt;&lt;br /&gt; Deploy and verify the Bookinfo sample application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Istio Injection:&lt;/strong&gt;&lt;br /&gt; Label your namespace and redeploy to include Istio sidecars.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Traffic Shifting:&lt;/strong&gt;&lt;br /&gt; Define a VirtualService to shift traffic between service versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Mutual TLS:&lt;/strong&gt;&lt;br /&gt; Apply a PeerAuthentication policy for secure communication.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect:&lt;/strong&gt;&lt;br /&gt; Use commands like &lt;code&gt;kubectl get pods&lt;/code&gt;, &lt;code&gt;istioctl proxy-status&lt;/code&gt;, and &lt;code&gt;kubectl describe &amp;lt;resource&amp;gt;&lt;/code&gt; to validate Istio configurations and inspect deployments.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Implementing Istio in Kubernetes enhances your microservices architecture by providing robust traffic management, security features, and detailed observability, ensuring your applications run efficiently and securely in a distributed environment.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h3 id=&quot;heading-learning-objective&quot;&gt;🎯 Learning Objective&lt;/h3&gt;&lt;p&gt;Learn how to implement Istio, a Service Mesh, within Kubernetes to manage and secure microservices communication effectively.&lt;/p&gt;&lt;h3 id=&quot;heading-scenario&quot;&gt;📖 Scenario&lt;/h3&gt;&lt;p&gt;You want to improve the observability, security, and resilience of your microservices architecture running in Kubernetes. Istio offers a solution to manage traffic, enforce policies, and gather telemetry data without requiring changes to your application code.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Service Mesh:&lt;/strong&gt;&lt;br /&gt;A dedicated infrastructure layer handling communication between services within Kubernetes.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Istio:&lt;/strong&gt;&lt;br /&gt;An open-source Service Mesh that simplifies service-to-service communications by managing traffic, enforcing security policies, and providing observability through metrics, logs, and traces.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Envoy Proxy:&lt;/strong&gt;&lt;br /&gt;A high-performance proxy deployed alongside each service to manage inbound and outbound traffic, enforcing policies and collecting telemetry data.&lt;/p&gt;&lt;h3 id=&quot;heading-istio-installation&quot;&gt;Istio Installation&lt;/h3&gt;&lt;p&gt;To begin using Istio in your Kubernetes cluster, follow these steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Download Istio Installation Script:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; curl -L https://istio.io/downloadIstio | sh - &lt;span class=&quot;hljs-built_in&quot;&gt;cd&lt;/span&gt; istio-1.*&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio:&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; istioctl install --&lt;span class=&quot;hljs-built_in&quot;&gt;set&lt;/span&gt; profile=demo -y&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-deploy-a-sample-application-with-istio&quot;&gt;Deploy a Sample Application with Istio&lt;/h3&gt;&lt;p&gt;Deploy the Bookinfo sample application, consisting of multiple microservices:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-enable-istio-injection&quot;&gt;Enable Istio Injection&lt;/h3&gt;&lt;p&gt;Automatically inject Istio sidecars into pods in the default namespace:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt;kubectl label namespace default istio-injection=enabledkubectl delete -f samples/bookinfo/platform/kube/bookinfo.yamlkubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-steps-to-set-up-and-use-istio&quot;&gt;Steps to Set Up and Use Istio&lt;/h2&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio:&lt;/strong&gt;&lt;br /&gt; Download and install Istio using the provided script.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify the Installation:&lt;/strong&gt;&lt;br /&gt; Check Istio and Kubernetes pods to ensure everything is running correctly.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy a Sample Application:&lt;/strong&gt;&lt;br /&gt; Deploy the Bookinfo application to test Istio&apos;s capabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Istio Injection:&lt;/strong&gt;&lt;br /&gt; Label the default namespace to enable Istio sidecar injection.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Redeploy the Application:&lt;/strong&gt;&lt;br /&gt; Update your application deployment to include Istio sidecars.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-istio-components&quot;&gt;&lt;strong&gt;Istio Components&lt;/strong&gt;&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pilot:&lt;/strong&gt; Manages traffic and service discovery.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Mixer:&lt;/strong&gt; Enforces access control and usage policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Citadel:&lt;/strong&gt; Manages certificates and identities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Galley:&lt;/strong&gt; Validates configurations.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Envoy Proxy:&lt;/strong&gt; Each service includes an Envoy proxy sidecar for handling traffic, enforcing policies, and collecting telemetry data.&lt;/p&gt;&lt;h3 id=&quot;heading-benefits-for-enterprise-applications&quot;&gt;Benefits for Enterprise Applications&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Traffic Management:&lt;/strong&gt; Control traffic flow and API calls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security:&lt;/strong&gt; Implement mutual TLS for secure communication.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Observability:&lt;/strong&gt; Collect metrics, logs, and traces.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Resilience:&lt;/strong&gt; Enhance fault tolerance with retries and circuit breakers.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;heading-additional-concepts-amp-examples&quot;&gt;Additional Concepts &amp;amp; Examples&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Traffic Shifting:&lt;/strong&gt; Gradually shift traffic between service versions.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.istio.io/v1alpha3&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;VirtualService&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;hosts:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;http:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;route:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v1&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;75&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;destination:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;host:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;reviews&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;subset:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;v2&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;weight:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;25&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Mutual TLS:&lt;/strong&gt; Enable mutual TLS for secure service-to-service communication.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;security.istio.io/v1beta1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;PeerAuthentication&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;mtls:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;mode:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;STRICT&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-hands-on-activity&quot;&gt;Hands-on Activity&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Install Istio:&lt;/strong&gt;&lt;br /&gt; Use the provided commands to install Istio in your Kubernetes cluster.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Deploy Bookinfo Application:&lt;/strong&gt;&lt;br /&gt; Deploy and verify the Bookinfo sample application.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Istio Injection:&lt;/strong&gt;&lt;br /&gt; Label your namespace and redeploy to include Istio sidecars.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Implement Traffic Shifting:&lt;/strong&gt;&lt;br /&gt; Define a VirtualService to shift traffic between service versions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enable Mutual TLS:&lt;/strong&gt;&lt;br /&gt; Apply a PeerAuthentication policy for secure communication.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Verify and Inspect:&lt;/strong&gt;&lt;br /&gt; Use commands like &lt;code&gt;kubectl get pods&lt;/code&gt;, &lt;code&gt;istioctl proxy-status&lt;/code&gt;, and &lt;code&gt;kubectl describe &amp;lt;resource&amp;gt;&lt;/code&gt; to validate Istio configurations and inspect deployments.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;Implementing Istio in Kubernetes enhances your microservices architecture by providing robust traffic management, security features, and detailed observability, ensuring your applications run efficiently and securely in a distributed environment.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1720612372012/b45e03fa-cd4c-4842-a536-51d0493e2975.png</hashnode:coverImage></item><item><title><![CDATA[Network Policies in k8s]]></title><description><![CDATA[Introduction
Network Policies in Kubernetes are crucial for securing and managing network traffic within a cluster. They allow administrators to define rules that control traffic flow to and from pods, providing a way to enforce network segmentation ...]]></description><link>https://devopsvoyager.hashnode.dev/network-policies-in-k8s</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/network-policies-in-k8s</guid><category><![CDATA[kubernetes network policies]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Wed, 09 Oct 2024 03:30:30 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;Network Policies in Kubernetes are crucial for securing and managing network traffic within a cluster. They allow administrators to define rules that control traffic flow to and from pods, providing a way to enforce network segmentation and isolation.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts-of-network-policies&quot;&gt;Key Concepts of Network Policies&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network Policy Resource&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selectors&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ingress and Egress Rules&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network Plugins&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-network-policy-resource&quot;&gt;Network Policy Resource&lt;/h2&gt;&lt;p&gt;A Network Policy is a Kubernetes resource that defines how groups of pods are allowed to communicate with each other and other network endpoints. Network Policies use selectors to specify the target pods and rules to control traffic.&lt;/p&gt;&lt;h4 id=&quot;heading-example-of-a-simple-network-policy&quot;&gt;Example of a Simple Network Policy&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;allow-frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this example:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The policy applies to pods with the label &lt;code&gt;role: frontend&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It allows inbound traffic from pods with the label &lt;code&gt;role: backend&lt;/code&gt; on port 80/TCP.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-selectors&quot;&gt;Selectors&lt;/h2&gt;&lt;p&gt;Selectors define which pods the Network Policy applies to. There are two main types of selectors:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Selectors&lt;/strong&gt;: Used to target specific pods within the same namespace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Namespace Selectors&lt;/strong&gt;: Used to target pods in other namespaces.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-example-of-a-pod-selector&quot;&gt;Example of a Pod Selector&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-example-of-a-namespace-selector&quot;&gt;Example of a Namespace Selector&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;namespaceSelector:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;environment:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;production&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-ingress-and-egress-rules&quot;&gt;Ingress and Egress Rules&lt;/h2&gt;&lt;p&gt;Network Policies can define ingress (incoming) and egress (outgoing) traffic rules.&lt;/p&gt;&lt;h3 id=&quot;heading-ingress-rules&quot;&gt;Ingress Rules&lt;/h3&gt;&lt;p&gt;Ingress rules control incoming traffic to the selected pods. They can specify the sources of traffic and the allowed ports and protocols.&lt;/p&gt;&lt;p&gt;Example of an Ingress Rule:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-egress-rules&quot;&gt;Egress Rules&lt;/h3&gt;&lt;p&gt;Egress rules control outgoing traffic from the selected pods. They can specify the destinations of traffic and the allowed ports and protocols.&lt;/p&gt;&lt;p&gt;Example of an Egress Rule:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;egress:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;to:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;ipBlock:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;cidr:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.0&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.0&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;/24&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;53&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-network-plugins&quot;&gt;Network Plugins&lt;/h2&gt;&lt;p&gt;Network Policies are implemented by network plugins, such as Calico, Cilium, and Weave. Ensure that the chosen network plugin supports Network Policies and is correctly configured in your cluster.&lt;/p&gt;&lt;h3 id=&quot;heading-use-case-1-isolating-sensitive-applications&quot;&gt;Use Case 1: Isolating Sensitive Applications&lt;/h3&gt;&lt;p&gt;Consider a scenario where you have a database pod that should only be accessible by the backend application pods. You can create a Network Policy to enforce this isolation.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;db-isolation&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;database&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5432&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-use-case-2-restricting-traffic-to-external-services&quot;&gt;Use Case 2: Restricting Traffic to External Services&lt;/h3&gt;&lt;p&gt;You may want to restrict pods in your development environment from accessing external services except for necessary updates. This can be achieved with egress rules.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;restrict-external&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;environment:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;dev&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Egress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;egress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;to:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;ipBlock:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;cidr:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;192.168&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.0&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;/24&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;443&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-use-case-3-enforcing-zero-trust-networking&quot;&gt;Use Case 3: Enforcing Zero Trust Networking&lt;/h3&gt;&lt;p&gt;Implementing zero trust networking involves ensuring that only explicitly allowed communications are permitted. Heres an example of enforcing such a policy for frontend and backend services.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;zero-trust&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Egress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;egress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;to:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-benefits-of-network-policies&quot;&gt;Benefits of Network Policies&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Security&lt;/strong&gt;: By defining strict rules for traffic flow, you reduce the attack surface and protect sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Compliance&lt;/strong&gt;: Network policies help in meeting regulatory requirements by enforcing network segmentation and access controls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Microservices Management&lt;/strong&gt;: Simplifies the management of microservices by defining clear communication rules between services.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Network Policies in Kubernetes are a powerful tool for managing and securing network traffic within a cluster. By leveraging selectors, ingress, and egress rules, administrators can enforce fine-grained access controls, ensuring that only authorized traffic flows between pods. This not only enhances the security posture of the cluster but also aids in compliance and effective management of microservices. Whether isolating sensitive applications, restricting access to external services, or implementing zero trust networking, Network Policies provide the necessary framework to achieve these goals.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;Network Policies in Kubernetes are crucial for securing and managing network traffic within a cluster. They allow administrators to define rules that control traffic flow to and from pods, providing a way to enforce network segmentation and isolation.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts-of-network-policies&quot;&gt;Key Concepts of Network Policies&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network Policy Resource&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Selectors&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Ingress and Egress Rules&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network Plugins&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-network-policy-resource&quot;&gt;Network Policy Resource&lt;/h2&gt;&lt;p&gt;A Network Policy is a Kubernetes resource that defines how groups of pods are allowed to communicate with each other and other network endpoints. Network Policies use selectors to specify the target pods and rules to control traffic.&lt;/p&gt;&lt;h4 id=&quot;heading-example-of-a-simple-network-policy&quot;&gt;Example of a Simple Network Policy&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;allow-frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this example:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;The policy applies to pods with the label &lt;code&gt;role: frontend&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;It allows inbound traffic from pods with the label &lt;code&gt;role: backend&lt;/code&gt; on port 80/TCP.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;heading-selectors&quot;&gt;Selectors&lt;/h2&gt;&lt;p&gt;Selectors define which pods the Network Policy applies to. There are two main types of selectors:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Pod Selectors&lt;/strong&gt;: Used to target specific pods within the same namespace.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Namespace Selectors&lt;/strong&gt;: Used to target pods in other namespaces.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h4 id=&quot;heading-example-of-a-pod-selector&quot;&gt;Example of a Pod Selector&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;app:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-app&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h4 id=&quot;heading-example-of-a-namespace-selector&quot;&gt;Example of a Namespace Selector&lt;/h4&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;namespaceSelector:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;environment:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;production&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-ingress-and-egress-rules&quot;&gt;Ingress and Egress Rules&lt;/h2&gt;&lt;p&gt;Network Policies can define ingress (incoming) and egress (outgoing) traffic rules.&lt;/p&gt;&lt;h3 id=&quot;heading-ingress-rules&quot;&gt;Ingress Rules&lt;/h3&gt;&lt;p&gt;Ingress rules control incoming traffic to the selected pods. They can specify the sources of traffic and the allowed ports and protocols.&lt;/p&gt;&lt;p&gt;Example of an Ingress Rule:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-egress-rules&quot;&gt;Egress Rules&lt;/h3&gt;&lt;p&gt;Egress rules control outgoing traffic from the selected pods. They can specify the destinations of traffic and the allowed ports and protocols.&lt;/p&gt;&lt;p&gt;Example of an Egress Rule:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;egress:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;to:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;ipBlock:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;cidr:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;10.0&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.0&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.0&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;/24&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;53&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-network-plugins&quot;&gt;Network Plugins&lt;/h2&gt;&lt;p&gt;Network Policies are implemented by network plugins, such as Calico, Cilium, and Weave. Ensure that the chosen network plugin supports Network Policies and is correctly configured in your cluster.&lt;/p&gt;&lt;h3 id=&quot;heading-use-case-1-isolating-sensitive-applications&quot;&gt;Use Case 1: Isolating Sensitive Applications&lt;/h3&gt;&lt;p&gt;Consider a scenario where you have a database pod that should only be accessible by the backend application pods. You can create a Network Policy to enforce this isolation.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;db-isolation&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;database&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;5432&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-use-case-2-restricting-traffic-to-external-services&quot;&gt;Use Case 2: Restricting Traffic to External Services&lt;/h3&gt;&lt;p&gt;You may want to restrict pods in your development environment from accessing external services except for necessary updates. This can be achieved with egress rules.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;restrict-external&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;dev&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;environment:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;dev&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Egress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;egress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;to:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;ipBlock:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;cidr:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;192.168&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.1&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;.0&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;/24&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;443&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;heading-use-case-3-enforcing-zero-trust-networking&quot;&gt;Use Case 3: Enforcing Zero Trust Networking&lt;/h3&gt;&lt;p&gt;Implementing zero trust networking involves ensuring that only explicitly allowed communications are permitted. Heres an example of enforcing such a policy for frontend and backend services.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;networking.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;NetworkPolicy&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;zero-trust&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;spec:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;frontend&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;policyTypes:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Ingress&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Egress&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;ingress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;from:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;egress:&lt;/span&gt;  &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;to:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;podSelector:&lt;/span&gt;        &lt;span class=&quot;hljs-attr&quot;&gt;matchLabels:&lt;/span&gt;          &lt;span class=&quot;hljs-attr&quot;&gt;role:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;backend&lt;/span&gt;    &lt;span class=&quot;hljs-attr&quot;&gt;ports:&lt;/span&gt;    &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;protocol:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;TCP&lt;/span&gt;      &lt;span class=&quot;hljs-attr&quot;&gt;port:&lt;/span&gt; &lt;span class=&quot;hljs-number&quot;&gt;80&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-benefits-of-network-policies&quot;&gt;Benefits of Network Policies&lt;/h2&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Enhanced Security&lt;/strong&gt;: By defining strict rules for traffic flow, you reduce the attack surface and protect sensitive data.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Improved Compliance&lt;/strong&gt;: Network policies help in meeting regulatory requirements by enforcing network segmentation and access controls.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Microservices Management&lt;/strong&gt;: Simplifies the management of microservices by defining clear communication rules between services.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Network Policies in Kubernetes are a powerful tool for managing and securing network traffic within a cluster. By leveraging selectors, ingress, and egress rules, administrators can enforce fine-grained access controls, ensuring that only authorized traffic flows between pods. This not only enhances the security posture of the cluster but also aids in compliance and effective management of microservices. Whether isolating sensitive applications, restricting access to external services, or implementing zero trust networking, Network Policies provide the necessary framework to achieve these goals.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1720610861704/d49e216c-0cdf-4968-ab81-5efe4914177a.png</hashnode:coverImage></item><item><title><![CDATA[RBAC Policy as Code in K8s]]></title><description><![CDATA[Introduction
Policy as Code is a practice that involves defining and managing policies through code. In the context of Role-Based Access Control (RBAC) in Kubernetes, Policy as Code means specifying access control policies (who can do what within the...]]></description><link>https://devopsvoyager.hashnode.dev/rbac-policy-as-code-in-k8s</link><guid isPermaLink="true">https://devopsvoyager.hashnode.dev/rbac-policy-as-code-in-k8s</guid><category><![CDATA[policy as code]]></category><category><![CDATA[rbac]]></category><category><![CDATA[Kubernetes]]></category><category><![CDATA[k8s]]></category><category><![CDATA[Devops]]></category><category><![CDATA[Devops articles]]></category><category><![CDATA[DevOps Journey]]></category><category><![CDATA[#Devopscommunity]]></category><category><![CDATA[DevOps trends]]></category><category><![CDATA[DevOps tools]]></category><dc:creator><![CDATA[Saurabh Adhau]]></dc:creator><pubDate>Tue, 08 Oct 2024 03:30:57 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;Policy as Code&lt;/strong&gt; is a practice that involves defining and managing policies through code. In the context of Role-Based Access Control (RBAC) in Kubernetes, Policy as Code means specifying access control policies (who can do what within the cluster) using code, usually in the form of configuration files. This approach enables version control, automated testing, and easier management of policies.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts&quot;&gt;Key Concepts&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Declarative Configuration&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version Control&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automated Validation&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Continuous Integration/Continuous Deployment (CI/CD)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-declarative-configuration&quot;&gt;Declarative Configuration&lt;/h2&gt;&lt;p&gt;In Kubernetes, RBAC policies are defined declaratively using YAML or JSON configuration files. These files specify Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings.&lt;/p&gt;&lt;p&gt;Example of a Role:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Role&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-namespace&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;pod-reader&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;rules:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;apiGroups:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-attr&quot;&gt;resources:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;pods&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-attr&quot;&gt;verbs:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;get&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;list&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;watch&quot;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example of a RoleBinding:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RoleBinding&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;read-pods-binding&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-namespace&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;subjects:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;User&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;jane&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiGroup:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;roleRef:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Role&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;pod-reader&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiGroup:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-version-control&quot;&gt;Version Control&lt;/h2&gt;&lt;p&gt;By defining RBAC policies as code, you can manage them using version control systems like Git. This approach provides several benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;History and Auditing&lt;/strong&gt;: Track changes to policies over time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaboration&lt;/strong&gt;: Enable multiple team members to collaborate on policy definitions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rollback&lt;/strong&gt;: Easily revert to previous versions of policies if needed.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-example-in-version-control&quot;&gt;Example in Version Control&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initialize a Git Repository&lt;/strong&gt;: Initialize a Git repository in your local directory.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git init&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Add RBAC Policy Files&lt;/strong&gt;: Create and add your RBAC policy files (e.g., &lt;code&gt;role.yaml&lt;/code&gt;, &lt;code&gt;rolebinding.yaml&lt;/code&gt;) to the repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git add role.yaml rolebinding.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit Changes&lt;/strong&gt;: Commit the changes with a descriptive message.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git commit -m &lt;span class=&quot;hljs-string&quot;&gt;&quot;Add initial RBAC policies for pod-reader role&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Push to Remote Repository&lt;/strong&gt;: Push the changes to a remote repository, such as GitHub or GitLab.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git remote add origin &amp;lt;remote-repo-url&amp;gt; git push -u origin master&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-automated-validation&quot;&gt;Automated Validation&lt;/h2&gt;&lt;p&gt;Automated validation tools can be used to ensure that RBAC policies are correctly defined and adhere to best practices. These tools can check for common issues such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Overly Broad Permissions&lt;/strong&gt;: Identifying roles that grant excessive access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Ensuring that policies are consistent across different environments.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples of tools for policy validation:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;OPA (Open Policy Agent)&lt;/strong&gt;: A powerful policy engine that can enforce custom policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;kube-linter&lt;/strong&gt;: A static analysis tool that checks Kubernetes YAML files for potential issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example of an OPA policy to check for overly broad permissions:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-rego&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;kubernetes&lt;/span&gt;.rbacdeny&lt;span class=&quot;hljs-punctuation&quot;&gt;[msg]&lt;/span&gt; &lt;span class=&quot;hljs-punctuation&quot;&gt;{&lt;/span&gt;  &lt;span class=&quot;hljs-variable&quot;&gt;input&lt;/span&gt;.kind == &lt;span class=&quot;hljs-string&quot;&gt;&quot;Role&quot;&lt;/span&gt;  &lt;span class=&quot;hljs-variable&quot;&gt;input&lt;/span&gt;.rules&lt;span class=&quot;hljs-punctuation&quot;&gt;[_]&lt;/span&gt;&lt;span class=&quot;hljs-punctuation&quot;&gt;.verbs[&lt;/span&gt;_&lt;span class=&quot;hljs-punctuation&quot;&gt;] &lt;/span&gt;== &lt;span class=&quot;hljs-string&quot;&gt;&quot;*&quot;&lt;/span&gt;  msg = sprintf&lt;span class=&quot;hljs-punctuation&quot;&gt;(&quot;&lt;/span&gt;Role &apos;%s&apos; grants wildcard &lt;span class=&quot;hljs-variable&quot;&gt;permissions&lt;/span&gt;.&lt;span class=&quot;hljs-string&quot;&gt;&quot;, [input.metadata.name])}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-continuous-integrationcontinuous-deployment-cicd&quot;&gt;Continuous Integration/Continuous Deployment (CI/CD)&lt;/h2&gt;&lt;p&gt;By integrating RBAC policies into your CI/CD pipeline, you can automate the deployment and testing of policies. This ensures that changes to policies are applied consistently across environments and reduces the risk of manual errors.&lt;/p&gt;&lt;h4 id=&quot;heading-example-cicd-pipeline-with-github-actions&quot;&gt;Example CI/CD Pipeline with GitHub Actions&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a GitHub Actions Workflow&lt;/strong&gt;: Create a &lt;code&gt;.github/workflows/deploy-rbac.yaml&lt;/code&gt; file in your repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deploy&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RBAC&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Policies&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;on:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;push:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;branches:&lt;/span&gt;       &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;jobs:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;validate-and-deploy:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;runs-on:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ubuntu-latest&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;steps:&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Checkout&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;repository&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;uses:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;actions/checkout@v2&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Set&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;up&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Kubernetes&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;CLI&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;uses:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;azure/setup-kubectl@v1&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;with:&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;v1.20.0&apos;&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Validate&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RBAC&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Policies&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;run:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;|         # Run OPA validation or other validation tools         # opa eval --data rbac.rego --input role.yaml --format pretty&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Apply&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RBAC&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Policies&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;run:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;|         kubectl apply -f role.yaml         kubectl apply -f rolebinding.yaml&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit and Push Workflow&lt;/strong&gt;: Commit and push the GitHub Actions workflow file to your repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git add .github/workflows/deploy-rbac.yaml git commit -m &lt;span class=&quot;hljs-string&quot;&gt;&quot;Add GitHub Actions workflow for RBAC policy deployment&quot;&lt;/span&gt; git push origin main&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor the Workflow&lt;/strong&gt;: Navigate to the &quot;Actions&quot; tab in your GitHub repository to monitor the CI/CD pipeline execution. The workflow will validate and deploy the RBAC policies whenever changes are pushed to the &lt;code&gt;main&lt;/code&gt; branch.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-benefits-of-policy-as-code-in-rbac&quot;&gt;Benefits of Policy as Code in RBAC&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Ensures that RBAC policies are applied consistently across different environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Audibility&lt;/strong&gt;: Provides a clear audit trail of changes to policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: Reduces the risk of misconfigurations that could lead to security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automation&lt;/strong&gt;: Enables automated validation and deployment of policies, reducing manual effort and errors.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaboration&lt;/strong&gt;: Facilitates collaboration among team members by using version control systems.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Policy as Code is a powerful approach to managing RBAC in Kubernetes. By defining policies declaratively, using version control, automating validation, and integrating with CI/CD pipelines, organizations can achieve greater consistency, security, and efficiency in managing access controls. This practice not only enhances the security posture of the cluster but also simplifies the process of managing and auditing access policies.&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;h1 id=&quot;heading-introduction&quot;&gt;Introduction&lt;/h1&gt;&lt;p&gt;&lt;strong&gt;Policy as Code&lt;/strong&gt; is a practice that involves defining and managing policies through code. In the context of Role-Based Access Control (RBAC) in Kubernetes, Policy as Code means specifying access control policies (who can do what within the cluster) using code, usually in the form of configuration files. This approach enables version control, automated testing, and easier management of policies.&lt;/p&gt;&lt;h3 id=&quot;heading-key-concepts&quot;&gt;Key Concepts&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Declarative Configuration&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Version Control&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automated Validation&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Continuous Integration/Continuous Deployment (CI/CD)&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-declarative-configuration&quot;&gt;Declarative Configuration&lt;/h2&gt;&lt;p&gt;In Kubernetes, RBAC policies are defined declaratively using YAML or JSON configuration files. These files specify Roles, ClusterRoles, RoleBindings, and ClusterRoleBindings.&lt;/p&gt;&lt;p&gt;Example of a Role:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Role&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-namespace&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;pod-reader&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;rules:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;apiGroups:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-attr&quot;&gt;resources:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;pods&quot;&lt;/span&gt;]  &lt;span class=&quot;hljs-attr&quot;&gt;verbs:&lt;/span&gt; [&lt;span class=&quot;hljs-string&quot;&gt;&quot;get&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;list&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;watch&quot;&lt;/span&gt;]&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Example of a RoleBinding:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;apiVersion:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io/v1&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RoleBinding&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;metadata:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;read-pods-binding&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;namespace:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;my-namespace&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;subjects:&lt;/span&gt;&lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;User&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;jane&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiGroup:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io&lt;/span&gt;&lt;span class=&quot;hljs-attr&quot;&gt;roleRef:&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;kind:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Role&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;pod-reader&lt;/span&gt;  &lt;span class=&quot;hljs-attr&quot;&gt;apiGroup:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;rbac.authorization.k8s.io&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-version-control&quot;&gt;Version Control&lt;/h2&gt;&lt;p&gt;By defining RBAC policies as code, you can manage them using version control systems like Git. This approach provides several benefits:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;History and Auditing&lt;/strong&gt;: Track changes to policies over time.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaboration&lt;/strong&gt;: Enable multiple team members to collaborate on policy definitions.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rollback&lt;/strong&gt;: Easily revert to previous versions of policies if needed.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h4 id=&quot;heading-example-in-version-control&quot;&gt;Example in Version Control&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Initialize a Git Repository&lt;/strong&gt;: Initialize a Git repository in your local directory.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git init&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Add RBAC Policy Files&lt;/strong&gt;: Create and add your RBAC policy files (e.g., &lt;code&gt;role.yaml&lt;/code&gt;, &lt;code&gt;rolebinding.yaml&lt;/code&gt;) to the repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git add role.yaml rolebinding.yaml&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit Changes&lt;/strong&gt;: Commit the changes with a descriptive message.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git commit -m &lt;span class=&quot;hljs-string&quot;&gt;&quot;Add initial RBAC policies for pod-reader role&quot;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Push to Remote Repository&lt;/strong&gt;: Push the changes to a remote repository, such as GitHub or GitLab.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git remote add origin &amp;lt;remote-repo-url&amp;gt; git push -u origin master&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 id=&quot;heading-automated-validation&quot;&gt;Automated Validation&lt;/h2&gt;&lt;p&gt;Automated validation tools can be used to ensure that RBAC policies are correctly defined and adhere to best practices. These tools can check for common issues such as:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Overly Broad Permissions&lt;/strong&gt;: Identifying roles that grant excessive access.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Ensuring that policies are consistent across different environments.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Examples of tools for policy validation:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;OPA (Open Policy Agent)&lt;/strong&gt;: A powerful policy engine that can enforce custom policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;kube-linter&lt;/strong&gt;: A static analysis tool that checks Kubernetes YAML files for potential issues.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Example of an OPA policy to check for overly broad permissions:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-rego&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;hljs-variable&quot;&gt;kubernetes&lt;/span&gt;.rbacdeny&lt;span class=&quot;hljs-punctuation&quot;&gt;[msg]&lt;/span&gt; &lt;span class=&quot;hljs-punctuation&quot;&gt;{&lt;/span&gt;  &lt;span class=&quot;hljs-variable&quot;&gt;input&lt;/span&gt;.kind == &lt;span class=&quot;hljs-string&quot;&gt;&quot;Role&quot;&lt;/span&gt;  &lt;span class=&quot;hljs-variable&quot;&gt;input&lt;/span&gt;.rules&lt;span class=&quot;hljs-punctuation&quot;&gt;[_]&lt;/span&gt;&lt;span class=&quot;hljs-punctuation&quot;&gt;.verbs[&lt;/span&gt;_&lt;span class=&quot;hljs-punctuation&quot;&gt;] &lt;/span&gt;== &lt;span class=&quot;hljs-string&quot;&gt;&quot;*&quot;&lt;/span&gt;  msg = sprintf&lt;span class=&quot;hljs-punctuation&quot;&gt;(&quot;&lt;/span&gt;Role &apos;%s&apos; grants wildcard &lt;span class=&quot;hljs-variable&quot;&gt;permissions&lt;/span&gt;.&lt;span class=&quot;hljs-string&quot;&gt;&quot;, [input.metadata.name])}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;heading-continuous-integrationcontinuous-deployment-cicd&quot;&gt;Continuous Integration/Continuous Deployment (CI/CD)&lt;/h2&gt;&lt;p&gt;By integrating RBAC policies into your CI/CD pipeline, you can automate the deployment and testing of policies. This ensures that changes to policies are applied consistently across environments and reduces the risk of manual errors.&lt;/p&gt;&lt;h4 id=&quot;heading-example-cicd-pipeline-with-github-actions&quot;&gt;Example CI/CD Pipeline with GitHub Actions&lt;/h4&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Create a GitHub Actions Workflow&lt;/strong&gt;: Create a &lt;code&gt;.github/workflows/deploy-rbac.yaml&lt;/code&gt; file in your repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-yaml&quot;&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Deploy&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RBAC&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Policies&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;on:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;push:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;branches:&lt;/span&gt;       &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;jobs:&lt;/span&gt;   &lt;span class=&quot;hljs-attr&quot;&gt;validate-and-deploy:&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;runs-on:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;ubuntu-latest&lt;/span&gt;     &lt;span class=&quot;hljs-attr&quot;&gt;steps:&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Checkout&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;repository&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;uses:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;actions/checkout@v2&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Set&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;up&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Kubernetes&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;CLI&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;uses:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;azure/setup-kubectl@v1&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;with:&lt;/span&gt;         &lt;span class=&quot;hljs-attr&quot;&gt;version:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;&apos;v1.20.0&apos;&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Validate&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RBAC&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Policies&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;run:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;|         # Run OPA validation or other validation tools         # opa eval --data rbac.rego --input role.yaml --format pretty&lt;/span&gt;     &lt;span class=&quot;hljs-bullet&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;hljs-attr&quot;&gt;name:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Apply&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;RBAC&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;Policies&lt;/span&gt;       &lt;span class=&quot;hljs-attr&quot;&gt;run:&lt;/span&gt; &lt;span class=&quot;hljs-string&quot;&gt;|         kubectl apply -f role.yaml         kubectl apply -f rolebinding.yaml&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Commit and Push Workflow&lt;/strong&gt;: Commit and push the GitHub Actions workflow file to your repository.&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;lang-bash&quot;&gt; git add .github/workflows/deploy-rbac.yaml git commit -m &lt;span class=&quot;hljs-string&quot;&gt;&quot;Add GitHub Actions workflow for RBAC policy deployment&quot;&lt;/span&gt; git push origin main&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor the Workflow&lt;/strong&gt;: Navigate to the &quot;Actions&quot; tab in your GitHub repository to monitor the CI/CD pipeline execution. The workflow will validate and deploy the RBAC policies whenever changes are pushed to the &lt;code&gt;main&lt;/code&gt; branch.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;heading-benefits-of-policy-as-code-in-rbac&quot;&gt;Benefits of Policy as Code in RBAC&lt;/h3&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt;: Ensures that RBAC policies are applied consistently across different environments.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Audibility&lt;/strong&gt;: Provides a clear audit trail of changes to policies.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Security&lt;/strong&gt;: Reduces the risk of misconfigurations that could lead to security vulnerabilities.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automation&lt;/strong&gt;: Enables automated validation and deployment of policies, reducing manual effort and errors.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Collaboration&lt;/strong&gt;: Facilitates collaboration among team members by using version control systems.&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;h1 id=&quot;heading-conclusion&quot;&gt;Conclusion&lt;/h1&gt;&lt;p&gt;Policy as Code is a powerful approach to managing RBAC in Kubernetes. By defining policies declaratively, using version control, automating validation, and integrating with CI/CD pipelines, organizations can achieve greater consistency, security, and efficiency in managing access controls. This practice not only enhances the security posture of the cluster but also simplifies the process of managing and auditing access policies.&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1720594447722/dd621b3a-33eb-41aa-8c99-0573b75aa999.png</hashnode:coverImage></item></channel></rss>