Followers

Kubernetes Replication Controller Assignment

  1. Create a Replication controller with nginx image with 3 Replicas on Prod env ( means those nodes which have node label env=prod).The Re...

 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

2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.

3. Delete a Pod and check a new Pod should be created by the Replication Controller  (To verify check the Events of rc).

4. Create a new Pod pod1 with a label server=web with tomcat image.

5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.

6. Delete the Replication controller and all the pods.

7. Again create Pod as mentioned in step 4.

8. Create Replication Controller as mentioned in Step 1

9. Check how many pods were created by RC if it is not 3 then find out the reason.

10. Delete RC and verify that pod1 is also deleted.



COMMENTS

BLOGGER: 11
  1. 1. vi assign-rc.yaml
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: assign-rc
    spec:
    replicas: 3
    template:
    metadata:
    name: nginx-pod
    labels:
    server: web
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    nodeSelector:
    env: "prod"
    selector:
    server: web

    2. kubectl create -f assign-rc.yaml
    kubectl get po
    (3 pods are running on kworker2 (which has label env=prod))

    3. kubectl delete pod assign-rc-ftmh4
    kubectl get po -o wide

    4. kubectl run pod1 --image=tomcat
    kubectl label pods pod1 server=web

    5. kubectl get po
    (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.)

    6. kubectl delete -f assign-rc.yaml

    7. kubectl run pod1 --image=tomcat
    kubectl label pods pod1 server=web

    8. kubectl create -f assign-rc.yaml

    9. kubectl get po
    (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)

    10. kubectl delete -f assign-rc.yaml
    (yes pod1 is also terminated. Reason is because it has the same label so it follows the manifest)


    ReplyDelete
  2.  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
    -> vi rc-assignment.yml
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: rc-aasignment
    labels:
    server: web
    spec:
    replicas: 3
    template:
    metadata:
    name: nginx-pod
    labels:
    env: prod
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    selector:
    env: prod

    -> kubectl create -f rc-assignment.yml

    2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.
    -> kubectl get pods -o wide (all running)
    -> kubectl get pods -l env=prod (all running)

    3. Delete a Pod and check a new Pod should be created by the Replication Controller  (To verify check the Events of rc).
    -> kubectl delete pod rc-aasignment-rjtjc
    -> kubectl get pods -o wide (new pod created)
    -> kubectl describe rc
    << Events:
    Type Reason Age From Message
    ---- ------ ---- ---- -------
    Normal SuccessfulCreate 6m17s replication-controller Created pod: rc-aasignment-tt5gq
    Normal SuccessfulCreate 6m17s replication-controller Created pod: rc-aasignment-z7kvj
    Normal SuccessfulCreate 6m17s replication-controller Created pod: rc-aasignment-rjtjc
    Normal SuccessfulCreate 94s replication-controller Created pod: rc-aasignment-bj97v >>


    4. Create a new Pod pod1 with a label server=web with tomcat image.
    -> kubectl run pod1 --image=tomcat
    -> kubectl label pods pod1 server=web

    5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.
    -> kubectl get pods --show-labels (YES)
    << pod1 1/1 Running 0 45s run=pod1,server=web
    rc-aasignment-bj97v 1/1 Running 0 9m34s env=prod
    rc-aasignment-tt5gq 1/1 Running 0 14m env=prod
    rc-aasignment-z7kvj 1/1 Running 0 14m env=prod >>

    6. Delete the Replication controller and all the pods.
    -> kubectl delete -f rc-assignment.yml
    -> kubectl delete pods pod1

    7. Again create Pod as mentioned in step 4.
    -> kubectl run pod1 --image=tomcat
    -> kubectl label pods pod1 server=web

    8. Create Replication Controller as mentioned in Step 1
    -> kubectl create -f rc-assignment.yml

    9. Check how many pods were created by RC if it is not 3 then find out the reason.
    -> kubectl get rc (3 pods created)

    10. Delete RC and verify that pod1 is also deleted.
    -> kubectl delete -f rc-assignment.yml
    -> kubectl get pods -o wide (pod1 not deleted)

    ReplyDelete
    Replies
    1.  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
      -> get nodes --show-labels
      -> kubectl label nodes kworker1 env=prod
      -> vi rc-assignment.yml
      apiVersion: v1
      kind: ReplicationController
      metadata:
      name: nginx-rc
      spec:
      replicas: 3
      template:
      metadata:
      name: nginx-pod
      labels:
      server: web
      spec:
      containers:
      - name: nginx-container
      image: nginx
      ports:
      - containerPort: 80
      nodeSelector:
      env: prod
      selector:
      server: web

      -> kubectl create -f rc-assignment.yml

      2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.
      -> kubectl get pods -o wide (all running)
      -> kubectl describe pods (Node-Selectors: env=prod)

      3. Delete a Pod and check a new Pod should be created by the Replication Controller  (To verify check the Events of rc).
      -> kubectl delete pod nginx-rc-45m6s
      -> kubectl get pods -o wide (new pod created)
      -> kubectl describe rc
      << Events:
      Type Reason Age From Message
      ---- ------ ---- ---- -------
      Normal SuccessfulCreate 8m36s replication-controller Created pod: nginx-rc-45m6s
      Normal SuccessfulCreate 8m36s replication-controller Created pod: nginx-rc-fnlkm
      Normal SuccessfulCreate 8m36s replication-controller Created pod: nginx-rc-6tgfv
      Normal SuccessfulCreate 52s replication-controller Created pod: nginx-rc-86zj9 >>


      4. Create a new Pod pod1 with a label server=web with tomcat image.
      -> kubectl run pod1 --image=tomcat
      -> kubectl label pods pod1 server=web

      5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.
      -> kubectl get pods -o wide (NO, pod1 was terminated when labeled with server=web)

      6. Delete the Replication controller and all the pods.
      -> kubectl delete -f rc-assignment.yml

      7. Again create Pod as mentioned in step 4.
      -> kubectl run pod1 --image=tomcat
      -> kubectl label pods pod1 server=web

      8. Create Replication Controller as mentioned in Step 1
      -> kubectl create -f rc-assignment.yml

      9. Check how many pods were created by RC if it is not 3 then find out the reason.
      -> kubectl describe rc (2 pods created)

      10. Delete RC and verify that pod1 is also deleted.
      -> kubectl delete -f rc-assignment.yml
      -> kubectl get pods -o wide (pod1 also deleted)

      Delete
  3. 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

    vi rc-nginx.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: nginx-rc
    spec:
    replicas: 3
    template:
    metadata:
    name: nginx-pod
    labels:
    server: web
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80

    affinity:

    nodeAffinity:

    requiredDuringSchedulingIgnoredDuringExecution:

    nodeSelectorTerms:

    - matchExpressions:

    - key: env

    operator: In

    values:

    - prod

    selector:
    server: web

    kubectl label nodes kworker2 env=prod --overwrite
    kubectl create -f rc-nginx.yaml

    2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.

    kubectl get pods -o wide

    3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).

    kubectl delete pod nginx-rc-9fds8
    kubectl describe rc

    4. Create a new Pod pod1 with a label server=web with tomcat image.

    kubectl run pod1 --image tomcat
    kubectl label pod pod1 server=web

    5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.

    kubectl get pods -o wide

    6. Delete the Replication controller and all the pods.

    kubectl delete -f rc-nginx.yaml
    kubectl delete pods pod1

    7. Again create Pod as mentioned in step 4.

    kubectl run pod1 --image tomcat
    kubectl label pod pod1 server=web

    8. Create Replication Controller as mentioned in Step 1

    vi rc2-nginx.yaml
    kubectl create -f rc2-nginx.yaml

    9. Check how many pods were created by RC if it is not 3 then find out the reason.

    kubectl get pods -o wide
    2 pods were create because pod1 has the same label

    10. Delete RC and verify that pod1 is also deleted.
    kubectl delete -f rc2-nginx.yaml
    all pods got deleted

    ReplyDelete
  4. 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
    kubectl label nodes kworker2 env=prod --overwrite
    vi nginx-rc.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: nginx-rc
    spec:
    replicas: 3
    template:
    metadata:
    name: nginx-pod
    labels:
    app: nginx-app
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    nodeSelector:
    env: prod
    selector:
    app: nginx-app

    kubectl create -f nginx-rc.yaml

    2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.
    kubectl get pod -o wide
    Verified that all running under Node: kworker2

    3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).
    kubectl delete pod nginx-rc-d9rn2
    kubectl get pod -o wide
    Verified that deleted pod is back and running within seconds

    4. Create a new Pod pod1 with a label server=web with tomcat image.
    vi pod1.yaml

    apiVersion: v1
    kind: Pod
    metadata:
    name: pod1
    labels:
    server: web
    spec:
    containers:
    - name: pod1
    image: tomcat
    ports:
    - containerPort: 8080

    kubectl create -f pod1.yaml

    5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.
    kubectl get pod -o wide
    pod1 created in kworker1

    6. Delete the Replication controller and all the pods.
    kubectl delete -f nginx-rc.yaml
    kubectl get rc → no resources
    kubectl get pod -l app=nginx-app → no resources

    7. Again create Pod as mentioned in step 4.
    kubectl create -f pod1.yaml
    Error from server (AlreadyExists): error when creating "pod1.yaml": pods "pod1" already exists

    8. Create Replication Controller as mentioned in Step 1
    kubectl create -f nginx-rc.yaml

    9. Check how many pods were created by RC if it is not 3 then find out the reason.
    kubectl get pod -o wide

    10. Delete RC and verify that pod1 is also deleted.
    kubectl delete -f nginx-rc.yaml
    kubectl get pod -o wide → pod1 not deleted

    ReplyDelete
    Replies
    1. 1.
      apiVersion: v1
      kind: ReplicationController
      metadata:
      name: nginx-rc
      spec:
      replicas: 3
      template:
      metadata:
      name: nginx-pod
      labels:
      server: web
      spec:
      containers:
      - name: nginx-container
      image: nginx
      ports:
      - containerPort: 80
      nodeSelector:
      env: prod
      selector:
      server: web

      9.
      kubectl get pod -o wide >> only 2 RC is created due to pod1 label is server = web

      10.
      kubectl delete -f nginx-rc.yaml
      Both RCs and pod1 is deleted

      Delete
  5. 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
    kubectl label nodes kworker2 env=prod --overwrite
    node/kworker2 labeled

    vi rc.yml
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: nginx-rc1
    spec:
    replicas: 3 #create 3 pods
    template: #pods’ specification template
    metadata:
    name: nginx-pod
    labels:
    app: nginx-app
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    nodeSelector:
    env: prod

    2. Verify Replication Controller created successfully and make sure all 3 pods are in running state and also running in Prod env.

    kubectl create -f rc.yml
    replicationcontroller/nginx-rc1 created

    kubectl get pods -o wide
    all 3 pods are running

    3. Delete a Pod and check a new Pod should be created by the Replication Controller (To verify check the Events of rc).
    kubectl delete pod nginx-rc1-8kbfr
    pod "nginx-rc1-8kbfr" deleted
    kubectl describe pod nginx-rc1
    under most recent 'Events'

    4. Create a new Pod pod1 with a label server=web with tomcat image.
    vi pod.yml
    apiVersion: v1
    kind: Pod
    metadata:
    name: pod1
    labels:
    server: web

    spec:
    containers:
    - name: tcimg
    image: tomcat
    nodeName: kworker1

    kubectl create -f pod.yml
    pod/pod1 created

    5. Verify that Pod pod1 is created successfully if it is not shown in the pod list then find out the reason.
    the label does not match with any of the worker nodes
    kubectl get pods -o wide
    pod1 running

    6. Delete the Replication controller and all the pods.
    kubectl delete -f rc.yml
    replicationcontroller "nginx-rc1" deleted
    kubectl delete -f pod.yml
    pod "pod1" deleted


    7. Again create Pod as mentioned in step 4.
    vi pod.yml
    apiVersion: v1
    kind: Pod
    metadata:
    name: pod1
    labels:
    app: nginx-app

    spec:
    containers:
    - name: tcimg
    image: tomcat
    nodeName: kworker1

    kubectl create -f pod.yml
    pod/pod1 created

    8. Create Replication Controller as mentioned in Step 1
    repeated vi rc.yml
    kubectl create -f rc.yml
    replicationcontroller/nginx-rc1 created

    9. Check how many pods were created by RC if it is not 3 then find out the reason.
    kubectl get pods -o wide
    3 nginx pods are running but no record of pod1 at all

    10. Delete RC and verify that pod1 is also deleted.
    kubectl delete -f rc.yml
    replicationcontroller "nginx-rc1" deleted
    root@kmaster:/home/vagrant# kubectl get pods -o wide
    No resources found in default namespace.

    ReplyDelete
  6. 1. kubectl label nodes kworker1 env=prod
    vi nginx-rc.yaml
    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: nginx-rc
    spec:
    replicas: 3
    template:
    metadata:
    name: nginx-pod
    labels:
    server: web
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    nodeSelector:
    env: prod
    selector:
    server: web
    2. kubectl get pods -o wide
    all pods deployed on kworker1 ok
    3. kubectl delete pod nginx-rc-vtz2l
    kubectl get pods -o wide
    3 pods are deployed, new pod was created to replace.
    kubectl describe rc nginx-rc
    Normal SuccessfulCreate 4m51s replication-controller Created pod: nginx-rc-clj2m
    Normal SuccessfulCreate 4m51s replication-controller Created pod: nginx-rc-vtz2l
    Normal SuccessfulCreate 4m51s replication-controller Created pod: nginx-rc-gnzgb
    Normal SuccessfulCreate 68s replication-controller Created pod: nginx-rc-ftfhg

    4. vi pod1.yaml
    apiVersion: v1
    kind: Pod
    metadata:
    name: pod1
    labels:
    server: "web"
    spec:
    containers:
    - name: c1
    image: tomcat
    kubectl create -f pod1.yaml
    5. pod1 terminated immediately.
    Due to having same label as replication controller.
    6. kubectl delete -f nginx-rc.yaml
    7. kubectl create -f pod1.yaml
    kubectl get pods -o wide
    pod1 is running.
    8. kubectl create -f nginx-rc.yaml
    kubectl get pods -o wide
    9. 2 pods were created by RC
    that is because it is maintaing a total of 3 pods
    pod1 also exists with the same label as rc.
    10. kubectl delete -f nginx-rc.yaml
    kubectl get pods -o wide
    all pods were deleted including pod1

    ReplyDelete
  7. ##find the logs of the replication controller events
    kubectl describe rc nginx-rc

    kubectl run pod1 --image=tomcat --labels server=web
    pod1 is not running, because of the label
    kubectl get pods -o wide

    delete RC and pods
    kubectl delete -f nginx-rc.yaml

    check
    kubectl get pods -o wide

    after RC created
    only 2 replicas created in addition to pod 1
    after repcon2.yaml deleted
    all pods deleted

    ReplyDelete
  8. Pong:

    1. vi nginx-rc.yaml

    apiVersion: v1
    kind: ReplicationController
    metadata:
    name: nginx-rc
    spec:
    replicas: 3
    template:
    metadata:
    name: nginx-pod
    labels:
    server: web
    spec:
    containers:
    - name: nginx-container
    image: nginx
    ports:
    - containerPort: 80
    nodeSelector:
    env: prod

    kubectl create -f nginx-rc.yaml

    2. kubectl describe nginx-rc

    3. kubectl delete pods --all

    4. kubectl run pod1 --image=tomcat -label
    kubectl label pods pod1 server=web

    5. kubectl describe pod pod1

    6. kubectl delete -f nginx-rc.yaml
    kubectl delete pods --all
    7. kubectl run pod1 --image=tomcat

    8. kubectl create -f nginx-rc.yaml

    9. kubectl get pods

    10. kubectl delete -f nginx-rc.yaml

    ReplyDelete

Name

Ansible,6,AWS,1,Azure DevOps,1,Containerization with docker,2,DevOps,2,Docker Quiz,1,Docker Swarm,1,DockerCompose,1,ELK,2,git,2,Jira,1,Kubernetes,1,Kubernetes Quiz,5,SAST DAST Security Testing,1,SonarQube,3,Splunk,2,vagrant kubernetes,1,YAML Basics,1,
ltr
item
DevOpsWorld: Kubernetes Replication Controller Assignment
Kubernetes Replication Controller Assignment
DevOpsWorld
https://www.devopsworld.co.in/2022/03/kubernetes-replication-controller.html
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/
https://www.devopsworld.co.in/2022/03/kubernetes-replication-controller.html
true
5997357714110665304
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content