<?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[Learning...]]></title><description><![CDATA[Learning...]]></description><link>https://saahitya.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 03 Dec 2024 08:52:15 GMT</lastBuildDate><atom:link href="https://saahitya.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><atom:link rel="next" href="https://saahitya.hashnode.dev/rss.xml?page=2"/><atom:link rel="previous" href="https://saahitya.hashnode.dev/rss.xml"/><item><title><![CDATA[Pod Disruption Budget(Pdb)]]></title><description><![CDATA[Before diving into what is pod disruption budget we need to understand two types of disruptions i.e., Voluntary Disruptions & Involuntary Disruptions.
What are disruptions in kubernetes? A disruption is an interrupt or event that has occured and whic...]]></description><link>https://saahitya.hashnode.dev/pod-disruption-budgetpdb</link><guid isPermaLink="true">https://saahitya.hashnode.dev/pod-disruption-budgetpdb</guid><category><![CDATA[Kubernetes]]></category><category><![CDATA[pod-disruptions]]></category><category><![CDATA[PodDisruptionBudget]]></category><dc:creator><![CDATA[Sahitya Inkulu]]></dc:creator><pubDate>Fri, 26 Aug 2022 12:18:33 GMT</pubDate><content:encoded>&lt;![CDATA[&lt;p&gt;Before diving into what is pod disruption budget we need to understand two types of disruptions i.e., Voluntary Disruptions &amp;amp; Involuntary Disruptions.&lt;/p&gt;&lt;p&gt;What are disruptions in kubernetes? A disruption is an interrupt or event that has occured and which may lead to destroying of a running pod.&lt;/p&gt;&lt;p&gt;There are two types of disruption in kubernetes which cause pod disruptions:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Involuntary Disruptions:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Cases where unavoidable hardware or system software errors occur, it cause involuntary disruption of a pod. They may be:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;a hardware failure of the physical machine backing the node&lt;/li&gt;&lt;li&gt;cluster administrator deletes VM (instance) by mistake&lt;/li&gt;&lt;li&gt;cloud provider or hypervisor failure makes VM disappear&lt;/li&gt;&lt;li&gt;a kernel panic&lt;/li&gt;&lt;li&gt;the node disappears from the cluster due to cluster network partition&lt;/li&gt;&lt;li&gt;eviction of a pod due to the node being out-of-resources.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These disruptions can&apos;t be avoided at any cause even by the cluster administrator.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Voluntary Disruptions:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Voluntary Disruptions occur when the Cluster administrator or Application owner perform any of these actions:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;deleting the deployment or other controller that manages the pod&lt;/li&gt;&lt;li&gt;updating a deployment&apos;s pod template causing a restart&lt;/li&gt;&lt;li&gt;directly deleting a pod&lt;/li&gt;&lt;li&gt;Draining a node for repair or upgrade.&lt;/li&gt;&lt;li&gt;Draining a node from a cluster to scale the cluster down.&lt;/li&gt;&lt;li&gt;Removing a pod from a node to permit something else to fit on that node.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So kubernetes introduced a feature to make our applications highly available even when voluntary disruptions occur which is known as pod disruption budget.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;NOTE: &lt;/strong&gt; Deleting pods or deployments can&apos;t be constrained by PodDisruptionBudget.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;PodDisruptionBudget (PDB):&lt;/strong&gt;  A PDB limits the number of Pods of a replicated application that are down simultaneously from voluntary disruptions.&lt;/p&gt;&lt;p&gt;For example, a quorum-based application would like to ensure that the number of replicas running is never brought below the number needed for a quorum. A web front end might want to ensure that the number of replicas serving load never falls below a certain percentage of the total.&lt;/p&gt;&lt;p&gt;So now let us get through a demo of how pod disruption budget can be configured for our applications in-order to make our applications highly available in-case of voluntary disruptions.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Configuring PodDisruptionBudget for an application&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Currently there are no pods in the cluster&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661503433799/5XChikaNC.PNG&quot; alt=&quot;pdb-1.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;So, let&apos;s create an Nginx deployment.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Creating an Nginx Deployment&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661503563374/YFeZg0Pid.PNG&quot; alt=&quot;pdb-2.PNG&quot; /&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661503570486/9QV9SkHcX.PNG&quot; alt=&quot;pdb-3.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;Now we have the 4 Nginx pods up and running in the node.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661504176736/P6XO53Vom.PNG&quot; alt=&quot;pdb-5.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Creating a PodDisruptionBudget&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A pdb is created by specifying the kind as &quot;PodDisruptionBudget&quot;.A pdb template can be written as simple as other templates.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661504191998/tMjB4B9qG.PNG&quot; alt=&quot;pdb-6.PNG&quot; /&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661504199439/ZOlwvBEYB.PNG&quot; alt=&quot;pdb-7.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;The 2 important fields that need to be looked into are &lt;strong&gt;kind&lt;/strong&gt;  which should be &quot;PodDisruptionBudget&quot; and &lt;strong&gt;minAvailable&lt;/strong&gt; which is number of pods you need in running state even after a voluntary disruption occurs.And another field that we need is &lt;strong&gt;matchLabels&lt;/strong&gt; which indicates that for what pod the pdb need to be created. So make sure you use the same labels in your application&apos;s deployment file.&lt;/p&gt;&lt;p&gt;Now let&apos;s apply the pod disruption budget.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661508058552/uKQZ6yB2-.PNG&quot; alt=&quot;pdb-8.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661508071134/GIhUYq5GT.PNG&quot; alt=&quot;pdb-10.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;Let&apos;s test it by creating a voluntary disruption. By draining a node which is one of the voluntary disruption, the pods present in that node gets evicted. But as we created PodDisruptionBudget with minimum availability of 2 pods we should see 2 pods running always even in the case of voluntary disruptions.&lt;/p&gt;&lt;p&gt;Command to drain a node&lt;/p&gt;&lt;p&gt;&lt;em&gt;kubectl drain node-name --ignore-daemonsets --force&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661512724815/mabEVK3vK.PNG&quot; alt=&quot;pdb-11.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;We created the Nginx deployment with 4 replicas and the PodDisruptionBudget with a minimum availability of 2 pods. That is the reason we see 2 pods are evicted successfully and 2 pods have an error when evicting,  while draining the node.&lt;/p&gt;&lt;p&gt;So if we look into our pods status we can see 2 pods are ready and in running state even if the node is drained and scheduling is disabled on that node.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661513260394/bI6uzqzSX.PNG&quot; alt=&quot;pdb-12.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661513316403/5E0Riw76D.PNG&quot; alt=&quot;pdb-13.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;Now you can uncordon your node by using the command &lt;em&gt;kubectl uncordon node-name&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661514774451/5iNd0j99p.PNG&quot; alt=&quot;pdb-14.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;In this way you can configure PodDisruptionBudget for your pods and make them available when there are voluntary disruptions.&lt;/p&gt;&lt;p&gt;Instead of the field &lt;strong&gt;minAvailable&lt;/strong&gt; we can also use &lt;strong&gt;maxUnavailable&lt;/strong&gt; which specifies the number of pods that can be evicted in-case of disruption. We can also specify the &lt;strong&gt;%&lt;/strong&gt; value(what percentage of pods need to be available or evicted) instead of an &lt;strong&gt;integer&lt;/strong&gt; value for  &lt;strong&gt;minAvailable&lt;/strong&gt; or &lt;strong&gt;maxUnavailable&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Hope this article helps you in basic understanding of PodDisruptionBudget. Thanks for reading :)&lt;/p&gt;&lt;p&gt;References: &lt;a target=&quot;_blank&quot; href=&quot;Link&quot;&gt;https://kubernetes.io/docs/concepts/workloads/pods/disruptions/&lt;/a&gt;&lt;/p&gt;]]&gt;</content:encoded><hashnode:content>&lt;![CDATA[&lt;p&gt;Before diving into what is pod disruption budget we need to understand two types of disruptions i.e., Voluntary Disruptions &amp;amp; Involuntary Disruptions.&lt;/p&gt;&lt;p&gt;What are disruptions in kubernetes? A disruption is an interrupt or event that has occured and which may lead to destroying of a running pod.&lt;/p&gt;&lt;p&gt;There are two types of disruption in kubernetes which cause pod disruptions:&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Involuntary Disruptions:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Cases where unavoidable hardware or system software errors occur, it cause involuntary disruption of a pod. They may be:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;a hardware failure of the physical machine backing the node&lt;/li&gt;&lt;li&gt;cluster administrator deletes VM (instance) by mistake&lt;/li&gt;&lt;li&gt;cloud provider or hypervisor failure makes VM disappear&lt;/li&gt;&lt;li&gt;a kernel panic&lt;/li&gt;&lt;li&gt;the node disappears from the cluster due to cluster network partition&lt;/li&gt;&lt;li&gt;eviction of a pod due to the node being out-of-resources.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;These disruptions can&apos;t be avoided at any cause even by the cluster administrator.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Voluntary Disruptions:&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Voluntary Disruptions occur when the Cluster administrator or Application owner perform any of these actions:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;deleting the deployment or other controller that manages the pod&lt;/li&gt;&lt;li&gt;updating a deployment&apos;s pod template causing a restart&lt;/li&gt;&lt;li&gt;directly deleting a pod&lt;/li&gt;&lt;li&gt;Draining a node for repair or upgrade.&lt;/li&gt;&lt;li&gt;Draining a node from a cluster to scale the cluster down.&lt;/li&gt;&lt;li&gt;Removing a pod from a node to permit something else to fit on that node.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So kubernetes introduced a feature to make our applications highly available even when voluntary disruptions occur which is known as pod disruption budget.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;NOTE: &lt;/strong&gt; Deleting pods or deployments can&apos;t be constrained by PodDisruptionBudget.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;PodDisruptionBudget (PDB):&lt;/strong&gt;  A PDB limits the number of Pods of a replicated application that are down simultaneously from voluntary disruptions.&lt;/p&gt;&lt;p&gt;For example, a quorum-based application would like to ensure that the number of replicas running is never brought below the number needed for a quorum. A web front end might want to ensure that the number of replicas serving load never falls below a certain percentage of the total.&lt;/p&gt;&lt;p&gt;So now let us get through a demo of how pod disruption budget can be configured for our applications in-order to make our applications highly available in-case of voluntary disruptions.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Configuring PodDisruptionBudget for an application&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;Currently there are no pods in the cluster&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661503433799/5XChikaNC.PNG&quot; alt=&quot;pdb-1.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;So, let&apos;s create an Nginx deployment.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Creating an Nginx Deployment&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661503563374/YFeZg0Pid.PNG&quot; alt=&quot;pdb-2.PNG&quot; /&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661503570486/9QV9SkHcX.PNG&quot; alt=&quot;pdb-3.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;Now we have the 4 Nginx pods up and running in the node.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661504176736/P6XO53Vom.PNG&quot; alt=&quot;pdb-5.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Creating a PodDisruptionBudget&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;A pdb is created by specifying the kind as &quot;PodDisruptionBudget&quot;.A pdb template can be written as simple as other templates.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661504191998/tMjB4B9qG.PNG&quot; alt=&quot;pdb-6.PNG&quot; /&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661504199439/ZOlwvBEYB.PNG&quot; alt=&quot;pdb-7.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;The 2 important fields that need to be looked into are &lt;strong&gt;kind&lt;/strong&gt;  which should be &quot;PodDisruptionBudget&quot; and &lt;strong&gt;minAvailable&lt;/strong&gt; which is number of pods you need in running state even after a voluntary disruption occurs.And another field that we need is &lt;strong&gt;matchLabels&lt;/strong&gt; which indicates that for what pod the pdb need to be created. So make sure you use the same labels in your application&apos;s deployment file.&lt;/p&gt;&lt;p&gt;Now let&apos;s apply the pod disruption budget.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661508058552/uKQZ6yB2-.PNG&quot; alt=&quot;pdb-8.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661508071134/GIhUYq5GT.PNG&quot; alt=&quot;pdb-10.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;Let&apos;s test it by creating a voluntary disruption. By draining a node which is one of the voluntary disruption, the pods present in that node gets evicted. But as we created PodDisruptionBudget with minimum availability of 2 pods we should see 2 pods running always even in the case of voluntary disruptions.&lt;/p&gt;&lt;p&gt;Command to drain a node&lt;/p&gt;&lt;p&gt;&lt;em&gt;kubectl drain node-name --ignore-daemonsets --force&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661512724815/mabEVK3vK.PNG&quot; alt=&quot;pdb-11.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;We created the Nginx deployment with 4 replicas and the PodDisruptionBudget with a minimum availability of 2 pods. That is the reason we see 2 pods are evicted successfully and 2 pods have an error when evicting,  while draining the node.&lt;/p&gt;&lt;p&gt;So if we look into our pods status we can see 2 pods are ready and in running state even if the node is drained and scheduling is disabled on that node.&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661513260394/bI6uzqzSX.PNG&quot; alt=&quot;pdb-12.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661513316403/5E0Riw76D.PNG&quot; alt=&quot;pdb-13.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;Now you can uncordon your node by using the command &lt;em&gt;kubectl uncordon node-name&lt;/em&gt;&lt;/p&gt;&lt;p&gt;&lt;img src=&quot;https://cdn.hashnode.com/res/hashnode/image/upload/v1661514774451/5iNd0j99p.PNG&quot; alt=&quot;pdb-14.PNG&quot; /&gt;&lt;/p&gt;&lt;p&gt;In this way you can configure PodDisruptionBudget for your pods and make them available when there are voluntary disruptions.&lt;/p&gt;&lt;p&gt;Instead of the field &lt;strong&gt;minAvailable&lt;/strong&gt; we can also use &lt;strong&gt;maxUnavailable&lt;/strong&gt; which specifies the number of pods that can be evicted in-case of disruption. We can also specify the &lt;strong&gt;%&lt;/strong&gt; value(what percentage of pods need to be available or evicted) instead of an &lt;strong&gt;integer&lt;/strong&gt; value for  &lt;strong&gt;minAvailable&lt;/strong&gt; or &lt;strong&gt;maxUnavailable&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;Hope this article helps you in basic understanding of PodDisruptionBudget. Thanks for reading :)&lt;/p&gt;&lt;p&gt;References: &lt;a target=&quot;_blank&quot; href=&quot;Link&quot;&gt;https://kubernetes.io/docs/concepts/workloads/pods/disruptions/&lt;/a&gt;&lt;/p&gt;]]&gt;</hashnode:content><hashnode:coverImage>https://cdn.hashnode.com/res/hashnode/image/upload/v1661517908913/Pw_Tr7S--.png</hashnode:coverImage></item></channel></rss>