tag:blogger.com,1999:blog-5997357714110665304.post4865949679812518761..comments2024-03-03T00:53:01.698-08:00Comments on DevOpsWorld: Kubernetes Replication Controller AssignmentRamanhttp://www.blogger.com/profile/06942152063269905258noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-5997357714110665304.post-35486336111558482292022-03-07T21:59:26.424-08:002022-03-07T21:59:26.424-08:00Pong:
1. vi nginx-rc.yaml
apiVersion: v1
kind: R...Pong:<br /><br />1. vi nginx-rc.yaml<br /><br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: nginx-rc<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> server: web<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> nodeSelector:<br /> env: prod<br /><br />kubectl create -f nginx-rc.yaml<br /><br />2. kubectl describe nginx-rc<br /><br />3. kubectl delete pods --all<br /><br />4. kubectl run pod1 --image=tomcat -label<br /> kubectl label pods pod1 server=web<br /><br />5. kubectl describe pod pod1<br /><br />6. kubectl delete -f nginx-rc.yaml<br /> kubectl delete pods --all<br />7. kubectl run pod1 --image=tomcat<br /> <br />8. kubectl create -f nginx-rc.yaml<br /><br />9. kubectl get pods<br /><br />10. kubectl delete -f nginx-rc.yamlPonghttps://www.blogger.com/profile/06088485780955228433noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-67466432060175521372022-03-07T21:35:03.133-08:002022-03-07T21:35:03.133-08:00 1. Create a Replication controller with nginx ima... 1. Create a Replication controller with nginx image with 3 Replicas on Prod env ( means those nodes which have node label env=prod).The Replication Controller should have label server=web<br />-> get nodes --show-labels<br />-> kubectl label nodes kworker1 env=prod<br />-> vi rc-assignment.yml<br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: nginx-rc<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> server: web<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> nodeSelector:<br /> env: prod<br /> selector:<br /> server: web<br /><br />-> kubectl create -f rc-assignment.yml<br /><br />2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.<br />-> kubectl get pods -o wide (all running)<br />-> kubectl describe pods (Node-Selectors: env=prod)<br /><br />3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).<br />-> kubectl delete pod nginx-rc-45m6s<br />-> kubectl get pods -o wide (new pod created)<br />-> kubectl describe rc <br /><< Events:<br /> Type Reason Age From Message<br /> ---- ------ ---- ---- -------<br /> Normal SuccessfulCreate 8m36s replication-controller Created pod: nginx-rc-45m6s<br /> Normal SuccessfulCreate 8m36s replication-controller Created pod: nginx-rc-fnlkm<br /> Normal SuccessfulCreate 8m36s replication-controller Created pod: nginx-rc-6tgfv<br /> Normal SuccessfulCreate 52s replication-controller Created pod: nginx-rc-86zj9 >><br /><br /><br />4. Create a new Pod pod1 with a label server=web with tomcat image.<br />-> kubectl run pod1 --image=tomcat<br />-> kubectl label pods pod1 server=web<br /><br />5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.<br />-> kubectl get pods -o wide (NO, pod1 was terminated when labeled with server=web)<br /><br />6. Delete the Replication controller and all the pods.<br />-> kubectl delete -f rc-assignment.yml<br /><br />7. Again create Pod as mentioned in step 4.<br />-> kubectl run pod1 --image=tomcat<br />-> kubectl label pods pod1 server=web<br /><br />8. Create Replication Controller as mentioned in Step 1<br />-> kubectl create -f rc-assignment.yml<br /><br />9. Check how many pods were created by RC if it is not 3 then find out the reason.<br />-> kubectl describe rc (2 pods created)<br /><br />10. Delete RC and verify that pod1 is also deleted.<br />-> kubectl delete -f rc-assignment.yml<br />-> kubectl get pods -o wide (pod1 also deleted)<br />Jeromehttps://www.blogger.com/profile/08086559536548594938noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-84430480099064182922022-03-07T21:28:51.389-08:002022-03-07T21:28:51.389-08:00##find the logs of the replication controller even...##find the logs of the replication controller events<br />kubectl describe rc nginx-rc<br /><br />kubectl run pod1 --image=tomcat --labels server=web<br />pod1 is not running, because of the label<br />kubectl get pods -o wide<br /><br />delete RC and pods<br />kubectl delete -f nginx-rc.yaml<br /><br />check<br />kubectl get pods -o wide<br /><br />after RC created<br />only 2 replicas created in addition to pod 1<br />after repcon2.yaml deleted<br />all pods deleted<br />learnerhttps://www.blogger.com/profile/15125202012612049684noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-91441958542248753852022-03-07T21:26:08.061-08:002022-03-07T21:26:08.061-08:001.
apiVersion: v1
kind: ReplicationController
meta...1.<br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br />name: nginx-rc<br />spec:<br />replicas: 3<br />template:<br />metadata:<br />name: nginx-pod<br />labels:<br /> server: web<br />spec:<br />containers:<br />- name: nginx-container<br />image: nginx<br />ports:<br />- containerPort: 80<br />nodeSelector:<br />env: prod<br />selector:<br /> server: web<br /><br />9.<br />kubectl get pod -o wide >> only 2 RC is created due to pod1 label is server = web<br /><br />10.<br />kubectl delete -f nginx-rc.yaml<br />Both RCs and pod1 is deletedChin YZhttps://www.blogger.com/profile/09154930103136164435noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-12184592468939732252022-03-07T21:24:07.675-08:002022-03-07T21:24:07.675-08:001. kubectl label nodes kworker1 env=prod
vi ngi...1. kubectl label nodes kworker1 env=prod<br /> vi nginx-rc.yaml<br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: nginx-rc<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> server: web<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> nodeSelector:<br /> env: prod<br /> selector:<br /> server: web<br />2. kubectl get pods -o wide<br /> all pods deployed on kworker1 ok<br />3. kubectl delete pod nginx-rc-vtz2l<br /> kubectl get pods -o wide<br /> 3 pods are deployed, new pod was created to replace.<br /> kubectl describe rc nginx-rc<br /> Normal SuccessfulCreate 4m51s replication-controller Created pod: nginx-rc-clj2m<br /> Normal SuccessfulCreate 4m51s replication-controller Created pod: nginx-rc-vtz2l<br /> Normal SuccessfulCreate 4m51s replication-controller Created pod: nginx-rc-gnzgb<br /> Normal SuccessfulCreate 68s replication-controller Created pod: nginx-rc-ftfhg<br /><br />4. vi pod1.yaml<br /> apiVersion: v1<br /> kind: Pod<br /> metadata:<br /> name: pod1<br /> labels:<br /> server: "web"<br /> spec:<br /> containers:<br /> - name: c1<br /> image: tomcat<br /> kubectl create -f pod1.yaml<br />5. pod1 terminated immediately.<br /> Due to having same label as replication controller.<br />6. kubectl delete -f nginx-rc.yaml<br />7. kubectl create -f pod1.yaml<br /> kubectl get pods -o wide<br /> pod1 is running.<br />8. kubectl create -f nginx-rc.yaml<br /> kubectl get pods -o wide<br />9. 2 pods were created by RC<br /> that is because it is maintaing a total of 3 pods<br /> pod1 also exists with the same label as rc.<br />10. kubectl delete -f nginx-rc.yaml<br /> kubectl get pods -o wide<br /> all pods were deleted including pod1Naveenhttps://www.blogger.com/profile/17031252849183889559noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-31094907417618437002022-03-07T21:23:58.634-08:002022-03-07T21:23:58.634-08:00MikrajMikrajAnonymoushttps://www.blogger.com/profile/09239152818279499340noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-11581092400077450712022-03-07T21:23:44.615-08:002022-03-07T21:23:44.615-08:001. Create a Replication controller with nginx imag...1. Create a Replication controller with nginx image with 3 Replicas on Prod env ( means those nodes which have node label env=prod).The Replication Controller should have label server=web<br />kubectl label nodes kworker2 env=prod --overwrite<br />node/kworker2 labeled<br /><br />vi rc.yml<br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: nginx-rc1 <br />spec:<br /> replicas: 3 #create 3 pods<br /> template: #pods’ specification template<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> app: nginx-app <br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> nodeSelector:<br /> env: prod<br /><br />2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.<br /><br />kubectl create -f rc.yml<br />replicationcontroller/nginx-rc1 created<br /><br />kubectl get pods -o wide<br />all 3 pods are running<br /><br />3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).<br />kubectl delete pod nginx-rc1-8kbfr<br />pod "nginx-rc1-8kbfr" deleted<br />kubectl describe pod nginx-rc1<br />under most recent 'Events'<br /><br />4. Create a new Pod pod1 with a label server=web with tomcat image.<br />vi pod.yml<br />apiVersion: v1<br />kind: Pod<br />metadata:<br /> name: pod1<br /> labels:<br /> server: web<br /><br />spec:<br /> containers:<br /> - name: tcimg<br /> image: tomcat<br /> nodeName: kworker1<br /><br />kubectl create -f pod.yml<br />pod/pod1 created<br /><br />5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason. <br />the label does not match with any of the worker nodes<br />kubectl get pods -o wide<br />pod1 running<br /><br />6. Delete the Replication controller and all the pods.<br />kubectl delete -f rc.yml<br />replicationcontroller "nginx-rc1" deleted<br />kubectl delete -f pod.yml<br />pod "pod1" deleted<br /><br /><br />7. Again create Pod as mentioned in step 4.<br />vi pod.yml<br />apiVersion: v1<br />kind: Pod<br />metadata:<br /> name: pod1<br /> labels:<br /> app: nginx-app<br /><br />spec:<br /> containers:<br /> - name: tcimg<br /> image: tomcat<br /> nodeName: kworker1<br /><br />kubectl create -f pod.yml<br />pod/pod1 created<br /><br />8. Create Replication Controller as mentioned in Step 1<br />repeated vi rc.yml<br />kubectl create -f rc.yml<br />replicationcontroller/nginx-rc1 created<br /><br />9. Check how many pods were created by RC if it is not 3 then find out the reason.<br />kubectl get pods -o wide<br />3 nginx pods are running but no record of pod1 at all<br /><br />10. Delete RC and verify that pod1 is also deleted.<br />kubectl delete -f rc.yml<br />replicationcontroller "nginx-rc1" deleted<br />root@kmaster:/home/vagrant# kubectl get pods -o wide<br />No resources found in default namespace.Anonymoushttps://www.blogger.com/profile/09239152818279499340noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-42792688713829338972022-03-07T21:14:57.307-08:002022-03-07T21:14:57.307-08:001. Create a Replication controller with nginx imag...1. Create a Replication controller with nginx image with 3 Replicas on Prod env ( means those nodes which have node label env=prod).The Replication Controller should have label server=web<br />kubectl label nodes kworker2 env=prod --overwrite<br />vi nginx-rc.yaml<br /><br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: nginx-rc<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> app: nginx-app<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> nodeSelector:<br /> env: prod<br /> selector:<br /> app: nginx-app<br /><br />kubectl create -f nginx-rc.yaml<br /><br />2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.<br />kubectl get pod -o wide<br />Verified that all running under Node: kworker2<br /><br />3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).<br />kubectl delete pod nginx-rc-d9rn2<br />kubectl get pod -o wide<br />Verified that deleted pod is back and running within seconds<br /><br />4. Create a new Pod pod1 with a label server=web with tomcat image.<br />vi pod1.yaml<br /><br />apiVersion: v1<br />kind: Pod<br />metadata:<br /> name: pod1<br /> labels:<br /> server: web<br />spec:<br /> containers:<br /> - name: pod1<br /> image: tomcat<br /> ports:<br /> - containerPort: 8080<br /><br />kubectl create -f pod1.yaml <br /><br />5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.<br />kubectl get pod -o wide<br />pod1 created in kworker1<br /><br />6. Delete the Replication controller and all the pods.<br />kubectl delete -f nginx-rc.yaml<br />kubectl get rc → no resources<br />kubectl get pod -l app=nginx-app → no resources<br /><br />7. Again create Pod as mentioned in step 4.<br />kubectl create -f pod1.yaml <br />Error from server (AlreadyExists): error when creating "pod1.yaml": pods "pod1" already exists<br /><br />8. Create Replication Controller as mentioned in Step 1<br />kubectl create -f nginx-rc.yaml<br /><br />9. Check how many pods were created by RC if it is not 3 then find out the reason.<br />kubectl get pod -o wide<br /><br />10. Delete RC and verify that pod1 is also deleted.<br />kubectl delete -f nginx-rc.yaml<br />kubectl get pod -o wide → pod1 not deleted<br />Chin YZhttps://www.blogger.com/profile/09154930103136164435noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-62906905866700391932022-03-07T21:10:06.733-08:002022-03-07T21:10:06.733-08:00 1. Create a Replication controller with nginx ima... 1. Create a Replication controller with nginx image with 3 Replicas on Prod env ( means those nodes which have node label env=prod).The Replication Controller should have label server=web<br /><br />vi rc-nginx.yaml<br /><br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: nginx-rc<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> server: web<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /><br /> affinity:<br /><br /> nodeAffinity:<br /><br /> requiredDuringSchedulingIgnoredDuringExecution:<br /><br /> nodeSelectorTerms:<br /><br /> - matchExpressions:<br /><br /> - key: env<br /><br /> operator: In<br /><br /> values:<br /><br /> - prod<br /><br /> selector:<br /> server: web<br /><br />kubectl label nodes kworker2 env=prod --overwrite<br />kubectl create -f rc-nginx.yaml<br /><br />2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.<br /><br />kubectl get pods -o wide<br /><br />3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).<br /><br />kubectl delete pod nginx-rc-9fds8 <br />kubectl describe rc<br /><br />4. Create a new Pod pod1 with a label server=web with tomcat image.<br /><br />kubectl run pod1 --image tomcat<br />kubectl label pod pod1 server=web<br /><br />5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.<br /><br />kubectl get pods -o wide<br /><br />6. Delete the Replication controller and all the pods.<br /><br />kubectl delete -f rc-nginx.yaml<br />kubectl delete pods pod1<br /><br />7. Again create Pod as mentioned in step 4.<br /><br />kubectl run pod1 --image tomcat<br />kubectl label pod pod1 server=web<br /><br />8. Create Replication Controller as mentioned in Step 1<br /><br />vi rc2-nginx.yaml<br />kubectl create -f rc2-nginx.yaml<br /><br />9. Check how many pods were created by RC if it is not 3 then find out the reason.<br /><br />kubectl get pods -o wide<br />2 pods were create because pod1 has the same label<br /><br />10. Delete RC and verify that pod1 is also deleted.<br />kubectl delete -f rc2-nginx.yaml<br />all pods got deletedAsyrafhttps://www.blogger.com/profile/01977461381198652478noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-78130844430528423552022-03-07T21:04:05.120-08:002022-03-07T21:04:05.120-08:00 1. Create a Replication controller with nginx ima... 1. Create a Replication controller with nginx image with 3 Replicas on Prod env ( means those nodes which have node label env=prod).The Replication Controller should have label server=web<br />-> vi rc-assignment.yml<br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: rc-aasignment<br /> labels:<br /> server: web<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> env: prod<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> selector:<br /> env: prod<br /><br />-> kubectl create -f rc-assignment.yml<br /><br />2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.<br />-> kubectl get pods -o wide (all running)<br />-> kubectl get pods -l env=prod (all running)<br /><br />3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).<br />-> kubectl delete pod rc-aasignment-rjtjc<br />-> kubectl get pods -o wide (new pod created)<br />-> kubectl describe rc <br /><< Events:<br /> Type Reason Age From Message<br /> ---- ------ ---- ---- -------<br /> Normal SuccessfulCreate 6m17s replication-controller Created pod: rc-aasignment-tt5gq<br /> Normal SuccessfulCreate 6m17s replication-controller Created pod: rc-aasignment-z7kvj<br /> Normal SuccessfulCreate 6m17s replication-controller Created pod: rc-aasignment-rjtjc<br /> Normal SuccessfulCreate 94s replication-controller Created pod: rc-aasignment-bj97v >><br /><br /><br />4. Create a new Pod pod1 with a label server=web with tomcat image.<br />-> kubectl run pod1 --image=tomcat<br />-> kubectl label pods pod1 server=web<br /><br />5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.<br />-> kubectl get pods --show-labels (YES)<br /><< pod1 1/1 Running 0 45s run=pod1,server=web<br />rc-aasignment-bj97v 1/1 Running 0 9m34s env=prod<br />rc-aasignment-tt5gq 1/1 Running 0 14m env=prod<br />rc-aasignment-z7kvj 1/1 Running 0 14m env=prod >><br /><br />6. Delete the Replication controller and all the pods.<br />-> kubectl delete -f rc-assignment.yml<br />-> kubectl delete pods pod1<br /><br />7. Again create Pod as mentioned in step 4.<br />-> kubectl run pod1 --image=tomcat<br />-> kubectl label pods pod1 server=web<br /><br />8. Create Replication Controller as mentioned in Step 1<br />-> kubectl create -f rc-assignment.yml<br /><br />9. Check how many pods were created by RC if it is not 3 then find out the reason.<br />-> kubectl get rc (3 pods created)<br /><br />10. Delete RC and verify that pod1 is also deleted.<br />-> kubectl delete -f rc-assignment.yml<br />-> kubectl get pods -o wide (pod1 not deleted)Jeromehttps://www.blogger.com/profile/08086559536548594938noreply@blogger.comtag:blogger.com,1999:blog-5997357714110665304.post-88735245563265788932022-03-07T21:01:44.513-08:002022-03-07T21:01:44.513-08:001. vi assign-rc.yaml
apiVersion: v1
kind: Replicat...1. vi assign-rc.yaml<br />apiVersion: v1<br />kind: ReplicationController<br />metadata:<br /> name: assign-rc<br />spec:<br /> replicas: 3<br /> template:<br /> metadata:<br /> name: nginx-pod<br /> labels:<br /> server: web<br /> spec:<br /> containers:<br /> - name: nginx-container<br /> image: nginx<br /> ports:<br /> - containerPort: 80<br /> nodeSelector:<br /> env: "prod"<br /> selector:<br /> server: web<br /><br />2. kubectl create -f assign-rc.yaml<br />kubectl get po<br />(3 pods are running on kworker2 (which has label env=prod))<br /><br />3. kubectl delete pod assign-rc-ftmh4<br />kubectl get po -o wide<br /><br />4. kubectl run pod1 --image=tomcat<br />kubectl label pods pod1 server=web<br /><br />5. kubectl get po<br />(Pod1 is terminating as soon as the command on step 4 is executed. Reason is because the desired state of the ReplicationController manifest file is satisfied.)<br /><br />6. kubectl delete -f assign-rc.yaml<br /><br />7. kubectl run pod1 --image=tomcat<br />kubectl label pods pod1 server=web<br /><br />8. kubectl create -f assign-rc.yaml<br /><br />9. kubectl get po<br />(only 2 pods created via the ReplicationController manifest. Reason is because pod1 also has the label server=web, which satisfies the desired state of the ReplicationController)<br /><br />10. kubectl delete -f assign-rc.yaml<br />(yes pod1 is also terminated. Reason is because it has the same label so it follows the manifest)<br /><br /><br />Muhd Irfan Abdul Rahmanhttps://www.blogger.com/profile/05917293972906626351noreply@blogger.com