From c367ad1156514713f8cb9b7ddb2a5ef656d1f283 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Mon, 22 Apr 2019 05:18:45 -0500 Subject: [PATCH] Show quick demo of Kustomize Use Replicated Ship to generate the base and overlays from the kubercoins GitHub repo. The namespaces chapter has been slightly tweaked so that we can use it for either Helm or Kustomize demo. --- slides/k8s/create-chart.md | 71 ++++++++++++++++++ slides/k8s/helm.md | 74 ------------------- slides/k8s/kustomize.md | 148 +++++++++++++++++++++++++++++++++++++ slides/k8s/namespaces.md | 34 ++++++++- slides/kube-fullday.yml | 2 + slides/kube-halfday.yml | 2 + slides/kube-selfpaced.yml | 2 + slides/kube-twodays.yml | 2 + 8 files changed, 259 insertions(+), 76 deletions(-) create mode 100644 slides/k8s/create-chart.md create mode 100644 slides/k8s/kustomize.md diff --git a/slides/k8s/create-chart.md b/slides/k8s/create-chart.md new file mode 100644 index 00000000..35ea3878 --- /dev/null +++ b/slides/k8s/create-chart.md @@ -0,0 +1,71 @@ +## Creating a chart + +- We are going to show a way to create a *very simplified* chart + +- In a real chart, *lots of things* would be templatized + + (Resource names, service types, number of replicas...) + +.exercise[ + +- Create a sample chart: + ```bash + helm create dockercoins + ``` + +- Move away the sample templates and create an empty template directory: + ```bash + mv dockercoins/templates dockercoins/default-templates + mkdir dockercoins/templates + ``` + +] + +--- + +## Exporting the YAML for our application + +- The following section assumes that DockerCoins is currently running + +.exercise[ + +- Create one YAML file for each resource that we need: + .small[ + ```bash + + while read kind name; do + kubectl get -o yaml --export $kind $name > dockercoins/templates/$name-$kind.yaml + done < +`Error: release loitering-otter failed: services "hasher" already exists` + +- To avoid naming conflicts, we will deploy the application in another *namespace* diff --git a/slides/k8s/helm.md b/slides/k8s/helm.md index 04feccd6..004abb58 100644 --- a/slides/k8s/helm.md +++ b/slides/k8s/helm.md @@ -176,77 +176,3 @@ The chart's metadata includes an URL to the project's home page. ``` ] - ---- - -## Creating a chart - -- We are going to show a way to create a *very simplified* chart - -- In a real chart, *lots of things* would be templatized - - (Resource names, service types, number of replicas...) - -.exercise[ - -- Create a sample chart: - ```bash - helm create dockercoins - ``` - -- Move away the sample templates and create an empty template directory: - ```bash - mv dockercoins/templates dockercoins/default-templates - mkdir dockercoins/templates - ``` - -] - ---- - -## Exporting the YAML for our application - -- The following section assumes that DockerCoins is currently running - -.exercise[ - -- Create one YAML file for each resource that we need: - .small[ - ```bash - - while read kind name; do - kubectl get -o yaml --export $kind $name > dockercoins/templates/$name-$kind.yaml - done < -`Error: release loitering-otter failed: services "hasher" already exists` - -- To avoid naming conflicts, we will deploy the application in another *namespace* diff --git a/slides/k8s/kustomize.md b/slides/k8s/kustomize.md new file mode 100644 index 00000000..54843c32 --- /dev/null +++ b/slides/k8s/kustomize.md @@ -0,0 +1,148 @@ +# Kustomize + +- Kustomize lets us transform YAML files representing Kubernetes resources + +- The original YAML files are valid resource files + + (e.g. they can be loaded with `kubectl apply -f`) + +- They are left untouched by Kustomize + +- Kustomize lets us define *overlays* that extend or change the resource files + +--- + +## Differences with Helm + +- Helm Charts use placeholders `{{ like.this }}` + +- Kustomize "bases" are standard Kubernetes YAML + +- It is possible to use an existing set of YAML as a Kustomize base + +- As a result, writing a Helm Chart is more work ... + +- ... But Helm Charts are also more powerful; e.g. they can: + + - use flags to conditionally include resources or blocks + + - check if a given Kubernetes API group is supported + + - [and much more](https://helm.sh/docs/chart_template_guide/) + +--- + +## Kustomize concepts + +- Kustomize needs a `kustomization.yaml` file + +- That file can be a *base* or a *variant* + +- If it's a *base*: + + - it lists YAML resource files to use + +- If it's a *variant* (or *overlay*): + + - it refers to (at least) one *base* + + - and some *patches* + +--- + +## An easy way to get started with Kustomize + +- We are going to use [Replicated Ship](https://www.replicated.com/ship/) to experiment with Kustomize + +- The [Replicated Ship CLI](https://github.com/replicatedhq/ship/releases) has been installed on our clusters + +- Replicated Ship has multiple workflows; here is what we will do: + + - initialize a Kustomize overlay from a remote GitHub repository + + - customize some values using the web UI provided by Ship + + - look at the resulting files and apply them to the cluster + +--- + +## Getting started with Ship + +- We need to run `ship init` in a new directory + +- `ship init` requires an URL to a remote repository containing Kubernetes YAML + +- It will clone that repository and start a web UI + +- Later, it can watch that repository and/or update from it + +- We will use the [jpetazzo/kubercoins](https://github.com/jpetazzo/kubeercoins) repository + + (it contains all the DockerCoins resources as YAML files) + +--- + +## `ship init` + +.exercise[ + +- Change to a new directory: + ```bash + mkdir ~/kubercoins + cd ~/kubercoins + ``` + +- Run `ship init` with the kubercoins repository: + ```bash + ship init https://github.com/jpetazzo/kubercoins + ``` + +] + +--- + +## Access the web UI + +- `ship init` tells us to connect on `localhost:8800` + +- We need to replace `localhost` with the address of our node + + (since we run on a remote machine) + +- Follow the steps in the web UI, and change one parameter + + (e.g. set the number of replicas in the worker Deployment) + +- Complete the web workflow, and go back to the CLI + +--- + +## Inspect the results + +- Look at the content of our directory + +- `base` contains the kubercoins repository + a `kustomization.yaml` file + +- `overlays/ship` contains the Kustomize overlay referencing the base + our patch(es) + +- `rendered.yaml` is a YAML bundle containing the patched application + +- `.ship` contains a state file used by Ship + +--- + +## Using the results + +- We can `kubectl apply -f rendered.yaml` + + (on any version of Kubernetes) + +- Starting with Kubernetes 1.14, we can apply the overlay directly with: + ```bash + kubectl apply -k overlays/ship + ``` + +- But let's not do that for now! + +- We will create a new copy of DockerCoins in another namespace + diff --git a/slides/k8s/namespaces.md b/slides/k8s/namespaces.md index b1961073..3dbd13c9 100644 --- a/slides/k8s/namespaces.md +++ b/slides/k8s/namespaces.md @@ -155,7 +155,7 @@ ## Using our new namespace -- Let's check that we are in our new namespace, then deploy the DockerCoins chart +- Let's check that we are in our new namespace, then deploy a new copy of Dockercoins .exercise[ @@ -164,6 +164,16 @@ kubectl get all ``` +] + +--- + +## Deploy DockerCoins with Helm + +*Follow these instructions if you previously created a Helm Chart.* + +.exercise[ + - Deploy DockerCoins: ```bash helm install dockercoins @@ -176,9 +186,29 @@ we created our Helm chart before. --- +## Deploy DockerCoins with Kustomize + +*Follow these instructions if you previously created a Kustomize overlay.* + +.exercise[ + +- Deploy DockerCoins: + ```bash + kubectl apply -f rendered.yaml + ``` + +- Or, with Kubernetes 1.14, you can also do this: + ```bash + kubectl apply -k overlays/ship + ``` + +] + +--- + ## Viewing the deployed app -- Let's see if our Helm chart worked correctly! +- Let's see if this worked correctly! .exercise[ diff --git a/slides/kube-fullday.yml b/slides/kube-fullday.yml index 7313ce00..bab20a76 100644 --- a/slides/kube-fullday.yml +++ b/slides/kube-fullday.yml @@ -50,6 +50,8 @@ chapters: - k8s/logs-cli.md - k8s/logs-centralized.md #- - k8s/helm.md +# - k8s/create-chart.md +# - k8s/kustomize.md # - k8s/namespaces.md # - k8s/netpol.md # - k8s/authn-authz.md diff --git a/slides/kube-halfday.yml b/slides/kube-halfday.yml index a60816e6..51e93480 100644 --- a/slides/kube-halfday.yml +++ b/slides/kube-halfday.yml @@ -53,6 +53,8 @@ chapters: # Bridget hasn't added EFK yet #- k8s/logs-centralized.md - k8s/helm.md + - k8s/create-chart.md + #- k8s/kustomize.md - k8s/namespaces.md #- k8s/netpol.md - k8s/whatsnext.md diff --git a/slides/kube-selfpaced.yml b/slides/kube-selfpaced.yml index 64dee1a2..aa7cf5e4 100644 --- a/slides/kube-selfpaced.yml +++ b/slides/kube-selfpaced.yml @@ -50,6 +50,8 @@ chapters: - k8s/logs-cli.md - k8s/logs-centralized.md - - k8s/helm.md + #- k8s/create-chart.md + - k8s/kustomize.md - k8s/namespaces.md - k8s/netpol.md - k8s/authn-authz.md diff --git a/slides/kube-twodays.yml b/slides/kube-twodays.yml index ba23a2ab..6ae80ec0 100644 --- a/slides/kube-twodays.yml +++ b/slides/kube-twodays.yml @@ -50,6 +50,8 @@ chapters: - k8s/logs-cli.md - k8s/logs-centralized.md - - k8s/helm.md + #- k8s/create-chart.md + - k8s/kustomize.md - k8s/namespaces.md - k8s/netpol.md - k8s/authn-authz.md