image

In this lab we will practice creating deployment with yaml file

In case you prefer a video, check below our YouTube video for this lab

Task: Create Kubernetes cluster with 3 worker nodes.

Master: 1 node

Worker: 2 node

Hint

Solution

Create docker hub account. Docker Hub if you already have one skip this step

Open Play with Kubernetes login with your docker hub account.

Click on start

It will start a 4 hr session

create three instance

click on + ADD NEW INSTANCE three time to add three instances

imageon first instance enter below command, this node will be master node
kubeadm init --apiserver-advertise-address $(hostname -i) --pod-network-cidr 10.5.0.0/16

enter below command on first node

kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml

capture output of kubeadm join XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

image

enter captured command in second and third node

kubeadm join  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
imageimageCheck node status, all 3 nodes should be in ready state image

Task: Create a Deployment with below settings

name: demo
image: nginx
replca: 3
labels:
  app: demo
  type: web

verify with below command

kubectl get deployment
Solution 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
kubectl apply -f deployment.yaml

this command will create deployment using seeting in yaml file

Task: How many pods are created by Deployment?

Solution
kubectl get rs
kubectl get pods

Task: Which nodes are pods running on?

Solution
kubectl get pods -o wide

Task: Find details on Deployment created in this lab

Solution
kubectl describe deployment demo

this command will provide details of deployment

Task: Use kubectl command to get Deployment details in yaml format.

Solution
 kubectl get deployment demo -o yaml

Task: Use kubectl command to get Deployment details in json format.

Solution
```javascript
kubectl get deployment demo -o json

Task: Scale Deployment to 5 replicas

verify with below command

kubectl get deployment
Solution

```javascript
kubectl scale deployment demo --replicas=5

Task: How many pods are managed by Deployment?

Solution
kubectl get pods

Task: Confirm that pod is managed by Replicaset

Solution
kubectl describe pods demo-XXXX-YYY
kubectl describe rs <name of Replicaset from previous step>

Task: Delete Deployment we created in this lab

Solution
kubectl delete deployment demo

Task: Delete all open nodes/instances and close session

  1. Select the node and click on DELETE
  2. Repeat same for any other open nodes
  3. click close session

cleanup}}


Click on ‘Submit Feedback’ on the bottom left of the page to submit any questions/feedback.