From dd0f6d00fa639040d2b2c94e351301ea99f9ae1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Sun, 14 May 2023 20:10:23 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=AD=EF=B8=8F=20Refactor=20the=20Daemon?= =?UTF-8?q?Set=20section?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- slides/k8s/daemonset.md | 100 ++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/slides/k8s/daemonset.md b/slides/k8s/daemonset.md index cf7ac2a5..5b252a9b 100644 --- a/slides/k8s/daemonset.md +++ b/slides/k8s/daemonset.md @@ -52,7 +52,7 @@ -- Unfortunately, as of Kubernetes 1.19, the CLI cannot create daemon sets +- Unfortunately, as of Kubernetes 1.27, the CLI cannot create daemon sets -- @@ -81,33 +81,49 @@ ## Creating the YAML file for our daemon set -- Let's start with the YAML file for the current `rng` resource +- DaemonSets and Deployments should be *pretty similar* + +- They both define how to create Pods + +- Can we transform a Deployment into a DaemonSet? 🤔 + +- Let's try! + +--- + +## Generating a Deployment manifest + +- Let's use `kubectl create deployment -o yaml --dry-run=client` .lab[ -- Dump the `rng` resource in YAML: +- Generate the YAML for a Deployment: ```bash - kubectl get deploy/rng -o yaml >rng.yml + kubectl create deployment rng --image=dockercoins/rng:v0.1 \ + -o yaml --dry-run=client ``` - -- Edit `rng.yml` - + +- Save it to a file: + ```bash + kubectl create deployment rng --image=dockercoins/rng:v0.1 \ + -o yaml --dry-run=client \ + > rng.yaml + ``` + ] --- -## "Casting" a resource to another +## Changing the `kind` -- What if we just changed the `kind` field? - - (It can't be that easy, right?) +- Edit the YAML manifest and replace `Deployment` with `DaemonSet` .lab[ -- Change `kind: Deployment` to `kind: DaemonSet` +- Edit the YAML file and make the change -- Save, quit - -- Try to create our new resource: +- Or, alternatively: ```bash - kubectl apply -f rng.yml + sed -i "s/kind: Deployment/kind: DaemonSet" ``` - +] + +--- + +## Creating the DaemonSet + +- Let's see if our DaemonSet manifest is valid! + +.lab[ + +- Try to `kubectl apply` our new YAML: + ```bash + kubectl apply -f rng.yaml + ``` ] -- -We all knew this couldn't be that easy, right! +- Unfortunately, that doesn't work! --- @@ -150,41 +177,26 @@ We all knew this couldn't be that easy, right! -- -- Workaround: fix the YAML - - - remove the `replicas` field - - remove the `strategy` field (which defines the rollout mechanism for a deployment) - - remove the `progressDeadlineSeconds` field (also used by the rollout mechanism) - - remove the `status: {}` line at the end - --- - -- Or, we could also ... +- Workaround: fix the YAML and remove the `replicas` field --- -## Use the `--force`, Luke +## Fixing the problem -- We could also tell Kubernetes to ignore these errors and try anyway - -- The `--force` flag's actual name is `--validate=false` +- Let's remove the `replicas` field and try again .lab[ -- Try to load our YAML file and ignore errors: +- Edit the `rng.yaml` file and remove the `replicas:` line + +- Then try to create the DaemonSet again: ```bash - kubectl apply -f rng.yml --validate=false + kubectl apply -f rng.yaml ``` ] --- - -🎩✨🐇 - --- - -Wait ... Now, can it be *that* easy? +- This time it should work! --- @@ -255,9 +267,9 @@ daemonset.apps/rng 2 2 2 2 2 -- -The daemon set created one pod per node, except on the master node. +The daemon set created one pod per node, except on the control plane node. -The master node has [taints](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) preventing pods from running there. +The control plane node has [taints](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) preventing pods from running there. (To schedule a pod on this node anyway, the pod will require appropriate [tolerations](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/).)