You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kubernetes-hands-on/14-pdb
Vincent Camus 400f5c94ea
fix(14): kind api version (#62)
I got this error without the change:

$ ~/go/bin/kind create cluster --config 14-pdb/kind.yml
ERROR: failed to create cluster: unknown apiVersion: kind.sigs.k8s.io/v1alpha3
4 years ago
..
01-pdb.yml chore: reorder the sections 5 years ago
README.md Update README.md (#45) 5 years ago
kind.yml fix(14): kind api version (#62) 4 years ago

README.md

Pod distruption budget (PDB)

Introduction

In Kubernetes pods are mortal and can be terminated at any time. When a pod is terminated it is called a “disruption”.

Disruptions can either be voluntary or involuntary. Involuntary means that it was not something anyone could expect (hardware failure for example). Voluntary means it was initiated by someone or something, like the upgrade of a node, a new deployment, etc.

Defining a “Pod Disruption Budget” helps Kubernetes manage your pods when a voluntary disruption happens. Kubernetes will try to ensure that not too many pods, matching a given selector, are unavailable at the same time

PDB

A PDB is configured as this:

apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
  name: nginx-pdb
spec:
  minAvailable: 2 # or maxUnavailable
  selector:
    matchLabels:
      app: nginx

A PDB is composed of two configurations:

  • the selector to know on which pods to apply this PDB
  • a number either minAvailable or maxUnavailable. It can either be a fixed number like 2 in the example, or a percentage like 20%

If you want to see the effect of a PDB, you will need a multi-node Kubernetes. As those lines are written minikube is a single node cluster. To have locally a multi-node cluster you can install kind.

Use the configuration file provided to create your cluster:

kind create cluster --config 14-pdb/kind.yml

Review and apply the manifests in 01-pdb.yml. Why did we specify a soft anti-affinity?

In a terminal run the command:

kubectl get pods -owide -w

It will display all the pods with the node where it's deployed. The -w is to watch the changes of those resources.

In another termimal run the command:

kubectl drain kind-worker2 --ignore-daemonsets

This command will remove, drain, the node kind-worker2 from the cluster. Watch the output of this command and the changes in the kubectl get pods -owide -w.

What do you see? How can you explain this?

Clean up

kubectl delete service,deployment,pod --all