{"id":887,"date":"2023-08-17T23:06:48","date_gmt":"2023-08-17T17:36:48","guid":{"rendered":"https:\/\/www.openwriteup.com\/?page_id=887"},"modified":"2024-03-19T14:30:22","modified_gmt":"2024-03-19T09:00:22","slug":"lab-taint-namespace-and-resourcequota","status":"publish","type":"page","link":"https:\/\/www.openwriteup.com\/?page_id=887","title":{"rendered":"Lab: Taint, Namespace,ResourceQuota &#038; LimitRange"},"content":{"rendered":"<p>In this lab:<\/p>\n<p>What is taint in kubernetes and why master is tainted?<\/p>\n<p>Taints are used to influence where workloads are placed (scheduled) within the cluster. A taint on a node tells the Kubernetes scheduler that only pods with matching &#8220;tolerations&#8221; (an attribute in pod specifications) are allowed to be scheduled on that node.\u00a0&#8220;master&#8221; nodes (also known as control plane nodes) are responsible for managing and coordinating the entire cluster.<\/p>\n<p>Lab: Check the master node Taint and un-taint it to schedule the workoad<\/p>\n<p><strong>Note: This is not recommended in production, only for training or testing purpose<\/strong><\/p>\n<pre>kubectl get nodes\r\nkubectl describe nodes &lt;provide the master node name from get nodes command&gt;|grep Taint<\/pre>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/Taint.jpg\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-888\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/Taint-300x46.jpg\" alt=\"\" width=\"300\" height=\"46\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/Taint-300x46.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/Taint-700x107.jpg 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/Taint.jpg 765w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Un-taint the master node<\/p>\n<pre>kubectl taint node &lt;node name&gt; &lt;Taintvalue&gt;-\r\n\r\nexample: kubectl taint node k8s node-role.kubernetes.io\/master:NoSchedule-\r\n\r\nkubectl describe node &lt;node name&gt; |grep Taint<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/untaint.jpg\"><img decoding=\"async\" class=\"alignnone wp-image-889\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/untaint-300x44.jpg\" alt=\"\" width=\"470\" height=\"69\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/untaint-300x44.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/untaint-700x102.jpg 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/untaint-768x112.jpg 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/untaint.jpg 929w\" sizes=\"(max-width: 470px) 100vw, 470px\" \/><\/a><\/p>\n<p>Lab2: Namespace<\/p>\n<p>Create namespace from command line<\/p>\n<pre>kubectl create ns labs\r\n\r\nkubectl describe ns labs\r\n\r\nkubectl get ns labs -o yaml\r\n\r\nkubectl delete ns labs\r\n\r\n\/\/delete command will delete all the resources of namespace<\/pre>\n<p>If you want to create namespace from yaml file<\/p>\n<p>use vi editor and open ns.yaml, copy\/paste the below code and save it<\/p>\n<pre>apiVersion: v1\r\nkind: Namespace\r\nmetadata:\r\n\u00a0 name: labs<\/pre>\n<ul>\n<li><code>apiVersion<\/code>: Specifies the API version being used, which is <code>v1<\/code> in this case.<\/li>\n<li><code>kind<\/code>: Specifies the kind of resource, which is a Namespace.<\/li>\n<li><code>metadata<\/code>: Contains metadata about the Namespace.\n<ul>\n<li><code>name<\/code>: Specifies the name of the Namespace, which is &#8220;labs&#8221; in this\u00a0 example<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Run command<\/p>\n<pre>kubectl create -f ns.yaml\r\n\r\nkubectl get ns\r\n\r\nkubectl describe ns labs<\/pre>\n<p>Lab3: Assign ResourceQuota namespace<\/p>\n<pre>git clone https:\/\/github.com\/amitopenwriteup\/k8s.git\r\ncd k8s\r\ncheck the rquota.yaml file<\/pre>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rquota.jpg\"><img decoding=\"async\" class=\"alignnone size-medium wp-image-897\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rquota-300x164.jpg\" alt=\"\" width=\"300\" height=\"164\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rquota-300x164.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rquota.jpg 541w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<pre>kubectl create ns labs\r\nkubectl apply -f rquota.yaml\r\nkubectl describe ns labs\r\nkubectl delete ns labs<\/pre>\n<p>Lab 4: assign LimitRange to namespace<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/lrange.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-896\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/lrange-277x300.jpg\" alt=\"\" width=\"277\" height=\"300\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/lrange-277x300.jpg 277w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/lrange.jpg 518w\" sizes=\"(max-width: 277px) 100vw, 277px\" \/><\/a><\/p>\n<pre>kubectl create ns labs\r\nkubectl apply -f lrange.yaml\r\nkubectl describe ns labs\r\nkubectl api-resources\r\nkubectl delete ns labs<\/pre>\n<ul>\n<li><code>ResourceQuota<\/code> limits the total resources that can be used within the &#8220;labs&#8221; namespace. It specifies maximum numbers of pods and limits on CPU and memory usage for requests and limits.<\/li>\n<li><code>LimitRange<\/code> defines constraints on resources for containers within pods. It specifies limits on CPU and memory for containers, as well as default and minimum values for requests.<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In this lab: What is taint in kubernetes and why master is tainted? Taints are used to influence where workloads are placed (scheduled) within the cluster. A taint on a node tells the Kubernetes scheduler that only pods with matching &#8220;tolerations&#8221; (an attribute in pod specifications) are allowed to be scheduled on that node.\u00a0&#8220;master&#8221; nodes (also known as control plane nodes) are responsible for managing and coordinating the entire cluster. Lab: Check the master node Taint and un-taint it to schedule the workoad Note: This is not recommended in production, only for training or testing purpose kubectl get nodes kubectl describe nodes &lt;provide the master node name from get nodes command&gt;|grep Taint Un-taint the master node kubectl taint node &lt;node name&gt; &lt;Taintvalue&gt;- example: kubectl taint node k8s node-role.kubernetes.io\/master:NoSchedule- kubectl describe node &lt;node name&gt; |grep Taint &nbsp; Lab2: Namespace Create namespace from command line kubectl create ns labs kubectl describe ns labs kubectl get ns labs -o yaml kubectl delete ns labs \/\/delete command will delete all the resources of namespace If you want to create namespace from yaml file use vi editor and open ns.yaml, copy\/paste the below code and save it apiVersion: v1 kind: Namespace metadata: \u00a0 name: labs apiVersion: Specifies the API version being used, which is v1 in this case. kind: Specifies the kind of resource, which is a Namespace. metadata: Contains metadata about the Namespace. name: Specifies the name of the Namespace, which is &#8220;labs&#8221; in this\u00a0 example Run command kubectl create -f ns.yaml kubectl get ns kubectl describe ns labs Lab3: Assign ResourceQuota namespace git clone https:\/\/github.com\/amitopenwriteup\/k8s.git cd k8s check the rquota.yaml file kubectl create ns labs kubectl apply -f rquota.yaml kubectl describe ns labs kubectl delete ns labs Lab 4: assign LimitRange to namespace kubectl create ns labs kubectl apply -f lrange.yaml kubectl describe ns labs kubectl api-resources kubectl delete ns labs ResourceQuota limits the total resources that can be used within the &#8220;labs&#8221; namespace. It specifies maximum numbers of pods and limits on CPU and memory usage for requests and limits. LimitRange defines constraints on resources for containers within pods. It specifies limits on CPU and memory for containers, as well as default and minimum values for requests.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-887","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/887","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=887"}],"version-history":[{"count":11,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/887\/revisions"}],"predecessor-version":[{"id":1393,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/887\/revisions\/1393"}],"wp:attachment":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=887"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}