Merge pull request #455 from jpetazzo/kustomize

Show quick demo of Kustomize
This commit is contained in:
Jérôme Petazzoni
2019-05-16 01:20:05 +02:00
committed by GitHub
8 changed files with 259 additions and 76 deletions

View File

@@ -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 <<EOF
deployment worker
deployment hasher
daemonset rng
deployment webui
deployment redis
service hasher
service rng
service webui
service redis
EOF
```
]
]
---
## Testing our helm chart
.exercise[
- Let's install our helm chart! (`dockercoins` is the path to the chart)
```
helm install dockercoins
```
]
--
- Since the application is already deployed, this will fail:<br>
`Error: release loitering-otter failed: services "hasher" already exists`
- To avoid naming conflicts, we will deploy the application in another *namespace*

View File

@@ -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 <<EOF
deployment worker
deployment hasher
daemonset rng
deployment webui
deployment redis
service hasher
service rng
service webui
service redis
EOF
```
]
]
---
## Testing our helm chart
.exercise[
- Let's install our helm chart! (`dockercoins` is the path to the chart)
```
helm install dockercoins
```
]
--
- Since the application is already deployed, this will fail:<br>
`Error: release loitering-otter failed: services "hasher" already exists`
- To avoid naming conflicts, we will deploy the application in another *namespace*

148
slides/k8s/kustomize.md Normal file
View File

@@ -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/kubercoins) 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

View File

@@ -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[

View File

@@ -51,6 +51,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

View File

@@ -54,6 +54,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

View File

@@ -51,6 +51,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

View File

@@ -51,6 +51,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