Kubernetes CKA sample exam question 29 with answer

Question
Create a ReplicaSet (name: web-pod, image: nginx:1.16, replica: 3).
There already a pod running in cluster.
Please make sure that total count of pods running on a cluster is not more than 3.

Answer
Get some details:

kubectl get po
kubectl get po --show-labels
We can see a pod running with labels app=web. We should use this label when creating ReplicaSet.
Create manifest file - as imperative creation of ReplicaSet is not available, we will do for Deployment:
kubectl create deploy web-pod --image=nginx --replicas 3 --dry-run=client -o yaml
Adjust the manifest to look like this - pay attention on labels:
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  labels:
    app: web
  name: web-pod
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web
    spec:
      containers:
      - image: nginx
        name: nginx
Apply:
kubectl apply -f rs.yaml
Check:
kubectl get rs
kubectl get po --show-labels
You should have additional 2 pods running with same label