(K8s) Kubernetes lab 104 ReplicaSet with Yaml

Step 0 : Create docker hub account. https://hub.docker.com

Step 1 : Open Play with Kubernetes login with your docker hub account.

Step 2 : Click on start

Step 3 : It will start a 4 hr session, click on + ADD NEW INSTANCE

Step 4 : Click in terminal and run steps from lab 101 to build cluster

Step 5 : Enter terminal of master node and create a new file with

vi rs.yaml

apiVersion: apps/v1

kind: ReplicaSet

metadata:

name: demo

labels:

app: demo

type: web

spec:

replicas: 3

selector:

matchLabels:

type: web

template:

metadata:

labels:

type: web

spec:

containers:

- name: demo-nginx

image: nginx

ports:

- containerPort: 80

  • the one marked in bold are required field

  • you can use any key: value pairs for labels

  • labels in matchlabels and template.metadata should match

  • labels are used to select pods

  • provide name for container

  • provide image for container

Step 6 : kubectl apply -f rs.yaml

  • this command will create replicaset

Step 7 : kubectl get pods

  • this command will list all the pods in default namespace

  • you will observe 3 pods with demo-XXXX

Step 8 : kubectl get rs

  • this command will list all the ReplicaSet in cluster

Step 9: kubectl get pods -o wide

  • this command will list all pods, with information of node where pods are running

Step 10 : kubectl describe rs demo

  • this command will provide details of ReplicaSet

Step 11 : kubectl get rs demo -o yaml

  • this command will provide details similar to describe but in yaml format

Step 12 : kubectl get rs demo -o json

  • this command will provide details similar to above commands in json format

Step 13 : kubectl scale rs demo --replicas=5

  • this command will increase replica count for ReplicaSet

Step 14 : kubectl get pods

  • you will observe 5 pods with demo-XXXX

Step 15 : kubectl describe pods demo-XXXX

  • pick a pod from step 14

  • you will see Controlled By: ReplicaSet/demo

Step 15 : kubectl delete rs demo

  • this command will delete ReplicaSet and pods related to ReplicaSet demo