Practice Test - ReplicaSets
Solutions for the replicaset practice tests
-
How many pods exist on the system?
```bash
kubectl get pods
```
Count the number of pods (if any)
-
How many ReplicaSets exist on the system?
```bash
kubectl get replicasets
```
Count the number of ReplicaSets (if any)
-
How about now? How many ReplicaSets do you see?
```bash
kubectl get replicasets
```
Count the number of ReplicaSets (if any)
-
How many PODs are DESIRED in the new-replica-set?
From the output of Q3, look in `DESIRED` column
-
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`.
-
How many PODs are READY in the new-replica-set?
```
kubectl get rs
```
Look in the `READY` column.
-
Why do you think the PODs are not ready?
```
kubectl describe pods
```
Look in the `Events` section at the end.
-
Delete any one of the 4 PODs.
```
kubectl get pods
```
Choose any of the four.
```
kubectl delete pod new-replica-set-XXXX
```
-
How many PODs exist now?
```
kubectl get pods
```
-
Why are there still 4 PODs, even after you deleted one?
> ReplicaSets ensures that desired number of PODs always run
-
Create a ReplicaSet using the replicaset-definition-1.yaml file located at /root/.</br>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
```
-
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
```
-
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
```
-
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.
-
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
```
-
Scale the ReplicaSet to 5 PODs.
```
kubectl scale rs new-replica-set --replicas 5
```