Turorial - Understanding Kubernetes volumes

imt

1. Objective

Understand Kubernetes deployments.

This tutorial directly uses a subset of the examples of the book “Kubernetes in action” written by Marko Lukša. All examples of the book can be found here.

2. Create a deployment

Create a manifest file 11-kubia-deployment-v1.yaml with the following content:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubia
spec:
  selector:
    matchLabels:
      app: kubia
  replicas: 3
  template:
    metadata:
      name: kubia
      labels:
        app: kubia
    spec:
      containers:
      - image: luksa/kubia:v1
        name: nodejs

> kubectl create -f 11-kubia-deployment-v1.yaml

3. Doing a rolling update on a deployment

To be able to watch the rolling update we first have to slow down the update process of the Deployment resource to 10 seconds:

> kubectl patch deployment kubia -p '{"spec": {"minReadySeconds": 10}}'

Open four terminals and run the following commands:

First to watch changes in the version of pods

> watch -n1 curl http://35.223.11.253/

Note
if not working > while true; do curl http://35.223.11.253/; done

Second to watch changes in the list of replicasets

> watch -n1 kubectl get rs

Third to start the rolling update

> kubectl set image deployment kubia nodejs=luksa/kubia:v2

Fourth, a command to follow the update

> kubectl rollout status deployment kubia

4. Doing a rollback

Let’s update to a v3 version that is bugged. You can open the same 4 terminals to follow the update.

> kubectl set image deployment kubia nodejs=luksa/kubia:v3

We can rollback our deployment to a valid version:

> kubectl rollout undo deployment kubia

You can also rollback to a chosen revision

> kubectl rollout undo deployment kubia --to-revision=1