From d3526aac009b9cfbba37070bfb2e92c253566a3c Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Sat, 22 Feb 2020 07:43:27 -0600 Subject: [PATCH] Add exercises --- slides/k8s/exercise-configmap.md | 31 +++++++++++++ slides/k8s/exercise-helm.md | 63 ++++++++++++++++++++++++++ slides/k8s/exercise-wordsmith.md | 39 ++++++++++++++++ slides/k8s/exercise-yaml.md | 77 ++++++++++++++++++++++++++++++++ slides/kube-fullday.yml | 4 ++ slides/kube-selfpaced.yml | 4 ++ slides/kube-twodays.yml | 4 ++ 7 files changed, 222 insertions(+) create mode 100644 slides/k8s/exercise-configmap.md create mode 100644 slides/k8s/exercise-helm.md create mode 100644 slides/k8s/exercise-wordsmith.md create mode 100644 slides/k8s/exercise-yaml.md diff --git a/slides/k8s/exercise-configmap.md b/slides/k8s/exercise-configmap.md new file mode 100644 index 00000000..c885f157 --- /dev/null +++ b/slides/k8s/exercise-configmap.md @@ -0,0 +1,31 @@ +# Exercise — ConfigMaps + +- In this exercise, we will use a ConfigMap to store static assets + +- While there are some circumstances where this can be useful ... + +- ... It is generally **not** a good idea! + +- Once you've read that warning, check the next slide for instructions :) + +--- + +## Exercise — ConfigMaps + +This will use the wordsmith app. + +We want to store the static files (served by `web`) in a ConfigMap. + +1. Transform the `static` directory into a ConfigMap. + + (https://github.com/jpetazzo/wordsmith/tree/master/web/static) + +2. Find out where that `static` directory is located in `web`. + + (for instance, by using `kubectl exec` to investigate) + +3. Update the definition of the `web` Deployment to use the ConfigMap. + + (note: fonts and images will be broken; that's OK) + +4. Make a minor change in the ConfigMap (e.g. change the text color) diff --git a/slides/k8s/exercise-helm.md b/slides/k8s/exercise-helm.md new file mode 100644 index 00000000..b41e429f --- /dev/null +++ b/slides/k8s/exercise-helm.md @@ -0,0 +1,63 @@ +# Exercise — Helm charts + +Let's write a Helm chart for wordsmith! + +We will need the YAML manifests that we wrote earlier. + +Level 1: create a chart to deploy wordsmith. + +Level 2: make it so that the number of replicas can be set with `--set replicas=X`. + +Level 3: change the colors of the lego bricks. + +(For level 3, fork the repository and use ctr.run to build images.) + +See next slide if you need hints! + +--- + +## Hints + +*Scroll one slide at a time to see hints.* + +-- + +Use `helm create` to create a new chart. + +-- + +Delete the content of the `templates` directory and put your YAML instead. + +-- + +Install the resulting chart. Voilà! + +-- + +Use `{{ .Values.replicas }}` in the YAML manifest for `words`. + +-- + +Also add `replicas: 5` to `values.yaml` to provide a default value. + +--- + +## Changing the color + +- Fork the repository + +- Make sure that your fork has valid Dockerfiles + + (or identify a branch that has valid Dockerfiles) + +- Use the following images: + + ctr.run/yourgithubusername/wordsmith/db:branchname + + (replace db with web and words for the other components) + +- Change the images and/or CSS in `web/static` + +- Commit, push, trigger a rolling update + + (`imagePullPolicy` should be `Always`, which is the default) diff --git a/slides/k8s/exercise-wordsmith.md b/slides/k8s/exercise-wordsmith.md new file mode 100644 index 00000000..4e6f98b7 --- /dev/null +++ b/slides/k8s/exercise-wordsmith.md @@ -0,0 +1,39 @@ +# Exercise — deploying on Kubernetes + +Let's deploy the wordsmith app on Kubernetes! + +As a reminder, we have the following components: + +| Name | Image | Port | +|-------|---------------------------------|------| +| db | jpetazzo/wordsmith-db:latest | 5432 | +| web | jpetazzo/wordsmith-web:latest | 80 | +| words | jpetazzo/wordsmith-words:latest | 8080 | + +We need `web` to be available from outside the cluster. + +See next slide if you need hints! + +--- + +## Hints + +*Scroll one slide at a time to see hints.* + +-- + +- For each component, we need to create a deployment and a service + +-- + +- Deployments can be created with `kubectl create deployment` + +-- + +- Services can be created with `kubectl expose` + +-- + +- Public services (like `web`) need to use a special type + + (e.g. `NodePort`) diff --git a/slides/k8s/exercise-yaml.md b/slides/k8s/exercise-yaml.md new file mode 100644 index 00000000..65db1e33 --- /dev/null +++ b/slides/k8s/exercise-yaml.md @@ -0,0 +1,77 @@ +# Exercise — writing YAML + +Let's write YAML manifests for the wordsmith app! + +It can be a single YAML file or multiple files in a directory. + +See next slides for testing instructions and hints. + +--- + +## How to test our YAML + +If `XYZ` is that YAML file (or directory with YAML files), we should be able to: + +1. Create a new namespace, e.g. `foo123` + +2. Deploy wordsmith with a single command + + (e.g. `kubectl apply --namespace foo123 -f XYZ`) + +3. Find out the connection information for `web` + + (e.g. `kubectl get service web --namespace`) + +4. Connect to it and see the wordsmith app + +See next slide for hints. + +--- + +## Strategies + +There are at least three methods to write our YAML. + +1. Dump the YAML of existing wordsmith deployments and services. + + (we can dump YAML with `kubectl get -o yaml ...`) + +2. Adapt existing YAML (from the docs or dockercoins). + + (for reference, kubercoins is at https://github.com/jpetazzo/kubercoins) + +3. Write it entirely from scratch. + +See next slide for more hints. + +--- + +## Adapting YAML + +*Scroll one slide at a time to see hints.* + +-- + +One option is to start with the YAML from kubercoins. + +(see https://github.com/jpetazzo/kubercoins) + +-- + +Adapt the YAML of a deployment (e.g. worker) to run "web". + +-- + +We need to change the name, labels, selectors, and image. + +-- + +Then adapt the YAML of a service (e.g. webui). + +-- + +We need to change the name, labels, selectors, possibly port number. + +-- + +Repeat for the other components. diff --git a/slides/kube-fullday.yml b/slides/kube-fullday.yml index a46ab89b..71bfcfee 100644 --- a/slides/kube-fullday.yml +++ b/slides/kube-fullday.yml @@ -44,6 +44,7 @@ chapters: #- k8s/buildshiprun-selfhosted.md - k8s/buildshiprun-dockerhub.md - k8s/ourapponkube.md + #- k8s/exercise-wordsmith.md - - k8s/yamldeploy.md - k8s/setup-k8s.md @@ -53,6 +54,7 @@ chapters: - shared/hastyconclusions.md - k8s/daemonset.md #- k8s/dryrun.md + #- k8s/exercise-yaml.md #- k8s/localkubeconfig.md #- k8s/accessinternal.md #- k8s/kubectlproxy.md @@ -69,6 +71,7 @@ chapters: #- k8s/helm-create-basic-chart.md #- k8s/helm-create-better-chart.md #- k8s/helm-secrets.md + #- k8s/exercise-helm.md #- k8s/create-chart.md #- k8s/create-more-charts.md #- k8s/netpol.md @@ -77,6 +80,7 @@ chapters: #- k8s/openid-connect.md #- k8s/podsecuritypolicy.md - k8s/volumes.md + #- k8s/exercise-configmap.md #- k8s/build-with-docker.md #- k8s/build-with-kaniko.md - k8s/configuration.md diff --git a/slides/kube-selfpaced.yml b/slides/kube-selfpaced.yml index 2d8ed86e..aba675c2 100644 --- a/slides/kube-selfpaced.yml +++ b/slides/kube-selfpaced.yml @@ -45,6 +45,7 @@ chapters: - k8s/buildshiprun-selfhosted.md - k8s/buildshiprun-dockerhub.md - k8s/ourapponkube.md + #- k8s/exercise-wordsmith.md - k8s/yamldeploy.md - - k8s/setup-k8s.md @@ -54,6 +55,7 @@ chapters: - shared/hastyconclusions.md - k8s/daemonset.md - k8s/dryrun.md + #- k8s/exercise-yaml.md - - k8s/rollout.md - k8s/healthchecks.md @@ -72,6 +74,7 @@ chapters: - k8s/helm-create-basic-chart.md - k8s/helm-create-better-chart.md - k8s/helm-secrets.md + #- k8s/exercise-helm.md - - k8s/netpol.md - k8s/authn-authz.md @@ -81,6 +84,7 @@ chapters: - k8s/control-plane-auth.md - - k8s/volumes.md + #- k8s/exercise-configmap.md - k8s/build-with-docker.md - k8s/build-with-kaniko.md - diff --git a/slides/kube-twodays.yml b/slides/kube-twodays.yml index 7ebfecc4..eb20a874 100644 --- a/slides/kube-twodays.yml +++ b/slides/kube-twodays.yml @@ -44,6 +44,7 @@ chapters: #- k8s/buildshiprun-selfhosted.md - k8s/buildshiprun-dockerhub.md - k8s/ourapponkube.md + #- k8s/exercise-wordsmith.md - - k8s/yamldeploy.md #- k8s/setup-k8s.md @@ -53,6 +54,7 @@ chapters: - shared/hastyconclusions.md - k8s/daemonset.md - k8s/dryrun.md + #- k8s/exercise-yaml.md - - k8s/localkubeconfig.md - k8s/accessinternal.md @@ -70,6 +72,7 @@ chapters: - k8s/helm-create-basic-chart.md - k8s/helm-create-better-chart.md - k8s/helm-secrets.md + #- k8s/exercise-helm.md - - k8s/netpol.md - k8s/authn-authz.md @@ -78,6 +81,7 @@ chapters: #- k8s/podsecuritypolicy.md - - k8s/volumes.md + #- k8s/exercise-configmap.md #- k8s/build-with-docker.md #- k8s/build-with-kaniko.md - k8s/configuration.md