(K8s) Kubernetes lab 105 Deployment 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 deployment.yaml

apiVersion: apps/v1

kind: Deployment

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

  • create a new file deployment.yaml

  • the one marked in bold are required field

  • you can use any key: value pairs for labels

  • labels in match label and template.metadata should match

  • labels are used to select pods

  • provide name for container

  • provide image for container

Step 6 : kubectl apply -f deployment.yaml

  • this command will list all the pods in cluster

Step 7 : kubectl get deployment

  • this command will list all the Deployment in cluster

Step 8 : kubectl get rs

  • this command will list all the pods in cluster

  • you will observe ReplicaSet with demo-XXXX

Step 9 : kubectl get pods

  • this command will list all the pods in cluster

  • you will observe pods with demo-XXXX-YYYY

Step 10: kubectl get pods -o wide

  • this command will list all pods with node pods are running

Step 11 : kubectl describe deployment demo

  • this command will provide details of deployment

Step 12 : kubectl get deployment demo -o yaml

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

Step 13 : kubectl get deployment demo -o json

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

Step 14 : kubectl scale deployment demo --replicas=5

  • this command will increase replica count for ReplicaSet

Step 15 : kubectl get pods

  • you will observe 5 pods with demo-XXXX-YYY

Step 16 : kubectl describe pods demo-XXXX-YYY

  • pick a pod from step 14

  • you will see Controlled By: ReplicaSet/demo-XXXX

Step 17 : kubectl describe rs <name of Replicaset from step16>

  • you will observe that Controlled By: Deployment/demo

Step18 : kubectl delete deployment demo

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