{"id":957,"date":"2023-08-21T13:07:31","date_gmt":"2023-08-21T07:37:31","guid":{"rendered":"https:\/\/www.openwriteup.com\/?page_id=957"},"modified":"2025-04-03T17:22:47","modified_gmt":"2025-04-03T11:52:47","slug":"lab-rc-deployment-statefulset","status":"publish","type":"page","link":"https:\/\/www.openwriteup.com\/?page_id=957","title":{"rendered":"Lab: RC, Deployment, StatefulSet"},"content":{"rendered":"<p>In this part we will cover below labs<\/p>\n<ul>\n<li>Replication Controller<\/li>\n<li>Deployments (Rolling Update and Recreate)<\/li>\n<li>StatefulSets<\/li>\n<\/ul>\n<p>Lab 1:\u00a0 Replication Controller<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-940\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc-278x300.jpg\" alt=\"\" width=\"278\" height=\"300\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc-278x300.jpg 278w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc.jpg 481w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><\/a><\/p>\n<p><code>kind<\/code>: The type of Kubernetes resource being defined. Here, it&#8217;s a <code>ReplicationController<\/code>.<\/p>\n<p><code>spec<\/code>: The specification for the ReplicationController, which includes:<\/p>\n<ul>\n<li><code>replicas<\/code>: The desired number of replicas (pods) that the ReplicationController should maintain. In this case, it&#8217;s set to <code>3<\/code>.<\/li>\n<li><code>selector<\/code>: A set of labels that the ReplicationController uses to identify the pods it should manage. In this case, it&#8217;s selecting pods with the label <code>app: nginx<\/code>.<\/li>\n<\/ul>\n<pre> kubectl create -f repc.yaml\r\nkubectl get rc\r\nkubectl describe replicationcontroller hello-dep \r\n# for deleting rc\r\nkubectl delete -f repc.yaml<\/pre>\n<p>Lab2: Replicaset<\/p>\n<p>MatchLabel<\/p>\n<pre>kubectl create -f replicasetmatchlabel.yaml\r\nkubectl describe replicaset.apps\/my-replicaset\r\nkubectl delete replicaset.apps\/my-replicaset<\/pre>\n<p>matchexpression<\/p>\n<pre>kubectl create -f matchexpressionset.yaml\r\nkubectl describe replicaset.apps\/my-replicaiset1<\/pre>\n<p>Try to create one pod with same label<\/p>\n<pre>kubectl create -f replicasetpod.yaml<\/pre>\n<p>Delete the pod<\/p>\n<pre>kubectl delete replicaset.apps\/my-replicaiset1<\/pre>\n<p>Again Create the pod and create rs , and check how many replicas<\/p>\n<pre>kubectl create -f replicasetpod.yaml\r\nkubectl create -f matchexpressionset.yaml\r\nkubectl describe replicaset.apps\/my-replicaiset1<\/pre>\n<p>&nbsp;<\/p>\n<p>Lab3 : Deployment<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/dep.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-941\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/dep-262x300.jpg\" alt=\"\" width=\"262\" height=\"300\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/dep-262x300.jpg 262w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/dep.jpg 495w\" sizes=\"auto, (max-width: 262px) 100vw, 262px\" \/><\/a><\/p>\n<p>This Deployment definition ensures that there will always be three replicas (pods) of the Nginx image (version 1.14.2) running, exposing port 80.<\/p>\n<p>Deployments offer features like rolling updates, scaling, and automated rollout and rollback strategies, making them a more robust way to manage your application&#8217;s replicas in Kubernetes.<\/p>\n<pre>kubectl create -f dep.yaml\r\nkubectl get deployment\r\nkubectl get pods\r\nkubectl describe deployment nginx-deployment\r\n#For deleting the deployment\r\nkubectl delete -f dep.yaml<\/pre>\n<p>Lab 4: Rolling update Deployment<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-942\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc-1-278x300.jpg\" alt=\"\" width=\"278\" height=\"300\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc-1-278x300.jpg 278w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/rc-1.jpg 481w\" sizes=\"auto, (max-width: 278px) 100vw, 278px\" \/><\/a><\/p>\n<p><code>strategy<\/code>: The update strategy for the Deployment. Here, it&#8217;s set to <code>RollingUpdate<\/code>, which ensures a gradual and controlled update of pods.<\/p>\n<ul>\n<li><code>rollingUpdate<\/code>: Configuration parameters for the rolling update strategy.\n<ul>\n<li><code>maxSurge<\/code>: The maximum number of pods that can be created above the desired replicas during an update. Here, it&#8217;s set to <code>1<\/code>, meaning one additional pod can be created.<\/li>\n<li><code>maxUnavailable<\/code>: The maximum number (or percentage) of pods that can be unavailable during an update. Here, it&#8217;s set to <code>25%<\/code>, which allows up to 25% of pods to be unavailable at a time during the updat<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre>kubectl create -f ru.yaml\r\nkubectl get deployment\r\nkubectl get pods\r\nkubectl get rs\r\nkubectl describe deployment hello-rcp\r\n# update the image\r\n kubectl set image deployment\/hello-rcp hello-dep=nginx:1.16.1\r\n# Check rollout status\r\nkubectl rollout status deployment\/hello-rcp\r\n#Rollout history\r\nkubectl rollout history deployment\/hello-rcp\r\n#roll back\r\n kubectl rollout undo deployment\/hello-rcp --to-revision=1\r\n#scaleup\r\n kubectl scale deployment\/hello-rcp --replicas=10\r\n\r\nkubectl rollout history deployment hello-dep --revision=0\r\nkubectl rollout history deployment hello-dep --revision=1\r\n#delete\r\n kubectl delete deployment.apps\/hello-rcp<\/pre>\n<p>Lab 5: Recreate<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/recreate.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-943\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/recreate-210x300.jpg\" alt=\"\" width=\"210\" height=\"300\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/recreate-210x300.jpg 210w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/recreate.jpg 441w\" sizes=\"auto, (max-width: 210px) 100vw, 210px\" \/><\/a><\/p>\n<p><code>strategy<\/code>: The update strategy for the Deployment. Here, it&#8217;s set to <code>Recreate<\/code>, which means that during an update, the existing pods are scaled down to zero replicas before scaling up the new ones. This is a less sophisticated strategy compared to <code>RollingUpdate<\/code>, and it can result in temporary downtime during updates.<\/p>\n<pre>kubectl create -f rc.yaml\r\nkubectl get deployment\r\nkubectl get pods\r\nkubectl get rs\r\nkubectl describe deployment hello-dep\r\n# update the image\r\nkubectl set image deployment\/hello-dep hello-dep=nginx:1.16.1\r\n# Check rollout status\r\nkubectl rollout status deployment\/hello-dep\r\n#Rollout history\r\nkubectl rollout history deployment\/hello-dep\r\n#roll back\r\nkubectl rollout undo deployment\/hello-dep --to-revision=1\r\n#scaleup\r\nkubectl scale deployment\/hello-dep --replicas=10\r\n#delete\r\nkubectl delete deployment.apps\/hello-dep<\/pre>\n<p>Lab 6: Statefulsets<\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hl.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-945\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hl-300x294.jpg\" alt=\"\" width=\"300\" height=\"294\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hl-300x294.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/hl.jpg 374w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/sf.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-946\" src=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/sf-300x187.jpg\" alt=\"\" width=\"359\" height=\"224\" srcset=\"https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/sf-300x187.jpg 300w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/sf-700x435.jpg 700w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/sf-768x478.jpg 768w, https:\/\/www.openwriteup.com\/wp-content\/uploads\/2023\/08\/sf.jpg 910w\" sizes=\"auto, (max-width: 359px) 100vw, 359px\" \/><\/a><\/p>\n<p><code>clusterIP<\/code>: The IP address to assign to the Service. Here, it&#8217;s set to <code>None<\/code>, making it a headless Service.<\/p>\n<p><code>serviceName<\/code>: The name of the headless Service associated with the StatefulSet.<\/p>\n<p>This configuration sets up a headless Service named <code>nginx<\/code> and a StatefulSet named <code>web<\/code> with Nginx pods. The headless Service is used as the <code>serviceName<\/code> for the StatefulSet, providing DNS-based discovery for the pods<\/p>\n<pre>kubectl create -f sf.yaml\r\nkubectl describe statefulset web\r\nkubectl get pods\r\n# check dns\r\nkubectl run -it --rm --restart=Never dnsutils2 --image=tutum\/dnsutils --command -- bash\r\n#perform nslookup to ip of the pod\r\nnslookup 10.244.0.5\r\nexit\r\n#delete one of the pod \r\nkubectl delete pod web-0\r\n#then again check\r\nkubectl get pods -o wide<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this part we will cover below labs Replication Controller Deployments (Rolling Update and Recreate) StatefulSets Lab 1:\u00a0 Replication Controller kind: The type of Kubernetes resource being defined. Here, it&#8217;s a ReplicationController. spec: The specification for the ReplicationController, which includes: replicas: The desired number of replicas (pods) that the ReplicationController should maintain. In this case, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_oct_exclude_from_cache":false,"footnotes":""},"class_list":["post-957","page","type-page","status-publish","hentry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/957","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=957"}],"version-history":[{"count":8,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/957\/revisions"}],"predecessor-version":[{"id":1541,"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=\/wp\/v2\/pages\/957\/revisions\/1541"}],"wp:attachment":[{"href":"https:\/\/www.openwriteup.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}