From 9859e441e1951c413a63e182804c4b354141a467 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Sun, 8 Apr 2018 17:16:27 -0500 Subject: [PATCH] Clarify the bonus exercises We had two open-ended exercises (questions without answers). We have added more explanations, as well as solutions for the exercises. It lets us show a few more tricks with selectors, and how to apply changes to sets of resources. --- slides/kube/daemonset.md | 45 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/slides/kube/daemonset.md b/slides/kube/daemonset.md index d2723aa0..93945f4b 100644 --- a/slides/kube/daemonset.md +++ b/slides/kube/daemonset.md @@ -416,8 +416,47 @@ The timestamps should give us a hint about how many pods are currently receiving --- -## More labels, more selectors, more problems? +## Cleaning up -- Bonus exercise 1: clean up the pods of the "old" daemon set +- The pods of the "old" daemon set are still running -- Bonus exercise 2: how could we have done this to avoid creating new pods? +- We are going to identify them programmatically + +.exercise[ + +- List the pods with `run=rng` but without `isactive=yes`: + ```bash + kubectl get pods -l run=rng,isactive!=yes + ``` + +- Remove these pods: + ```bash + kubectl get pods -l run=rng,isactive!=yes -o name | + xargs kubectl delete + ``` + +] + +--- + +## Avoiding extra pods + +- When we changed the definition of the daemon set, it immediately created new pods + +- How could we have avoided this? + +-- + +- By adding the `isactive: "yes"` label to the pods before changing the daemon set! + +- This can be done programmatically with `kubectl patch`: + + ```bash + PATCH=' + metadata: + labels: + isactive: "yes" + ' + kubectl get pods -l run=rng -o name | + xargs kubectl patch -p "$PATCH" + ```