Skip to content

Latest commit

 

History

History
219 lines (146 loc) · 4.5 KB

15-Practice-Tests-ReplicaSet.md

File metadata and controls

219 lines (146 loc) · 4.5 KB

Practice Test - ReplicaSets

Solutions for the replicaset practice tests

  1. How many pods exist on the system?
    kubectl get pods

    Count the number of pods (if any)

  2. How many ReplicaSets exist on the system?
    kubectl get replicasets

    Count the number of ReplicaSets (if any)

  3. How about now? How many ReplicaSets do you see?
    kubectl get replicasets

    Count the number of ReplicaSets (if any)

  4. How many PODs are DESIRED in the new-replica-set?

    From the output of Q3, look in DESIRED column

  5. What is the image used to create the pods in the new-replica-set?
    kubectl describe replicaset
    

    ...and look under the containers section --- or --

    kubectl get rs -o wide
    

    ...and look in the IMAGES column. Kubernetes accepts rs as shorthand for replicaset.

  6. How many PODs are READY in the new-replica-set?
    kubectl get rs
    

    Look in the READY column.

  7. Why do you think the PODs are not ready?
    kubectl describe pods
    

    Look in the Events section at the end.

  8. Delete any one of the 4 PODs.
    kubectl get pods
    

    Choose any of the four.

    kubectl delete pod new-replica-set-XXXX
    
  9. How many PODs exist now?
    kubectl get pods
    
  10. Why are there still 4 PODs, even after you deleted one? > ReplicaSets ensures that desired number of PODs always run
  11. Create a ReplicaSet using the replicaset-definition-1.yaml file located at /root/.
    There is an issue with the file, so try to fix it.
    kubectl create -f replicaset-definition-1.yaml
    

    Note the error message.

    Get the apiVersion for replicaset

    $ kubectl explain replicaset | grep VERSION
    

    Update the replicaset definition file in vi with correct version and then retry creation.

    $ kubectl create -f replicaset-definition-1.yaml
    
  12. Fix the issue in the replicaset-definition-2.yaml file and create a ReplicaSet using it.
    kubectl create -f replicaset-definition-1.yaml
    

    Note the error message.

    Selector matchLabels should match with POD labels - Update replicaset-definition-2.yaml

    The values for labels on lines 9 and 13 should match.

    $ kubectl create -f replicaset-definition-2.yaml
    
  13. Delete the two newly created ReplicaSets - replicaset-1 and replicaset-2
    kubectl delete replicaset replicaset-1
    kubectl delete rs replicaset-2
    

    --- OR ---

    kubectl delete replicaset replicaset-1 replicaset-2
    
  14. Fix the original replica set new-replica-set to use the correct busybox image.
    kubectl edit replicaset new-replica-set
    

    Edit the image to be busybox, save and exit.

  15. Fix the original replica set new-replica-set to use the correct busybox image.
    kubectl edit replicaset new-replica-set
    

    Fix the image, save and exit.

    You will note if you do kubectl get pods, that they are still broken. ReplicaSets are not very smart and do not redeploy pods when the container specification has been edited.

    We must either delete and recreate the replicaset by exporting its YAML...

    kubectl get rs new-replica-set -o yaml > rs.yaml
    kubectl delete rs new-replica-set
    kunectl create -f rs.yaml
    

    -- OR --

    Delete each broken pod. The ReplicaSet will deploy a new one in its place which should be working.

    -- OR --

    Scale it to zero, then back to 4

    kubectl scale rs new-replica-set --replicas 0
    kubectl scale rs new-replica-set --replicas 4
    
  16. Scale the ReplicaSet to 5 PODs.
    kubectl scale rs new-replica-set --replicas 5