Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introduction to kustomize

Introduction to kustomize

A talk at Kubernetes Meetup Tokyo #12
https://k8sjp.connpass.com/event/90631/

Seigo Uchida

July 11, 2018
Tweet

More Decks by Seigo Uchida

Other Decks in Technology

Transcript

  1. • 3 environments (dev, stg, prod) • 1 deployment resource

    • different replicas by environments Example Requirements
  2. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml File Structure
  3. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml File Structure
  4. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml File Structure
  5. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml File Structure
  6. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml Base
  7. # hello-world/base/deployment.yaml apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec:

    replicas: 1 selector: matchLabels: app: hello-world template: .. Base
  8. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml Staging
  9. $ kustomize build -h Print current configuration per contents of

    kustomization.yaml Usage: kustomize build [path] [flags] $ kustomize build
  10. apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: replicas: 3

    selector: matchLabels: app: hello-world template: .. Print staging configuration
  11. hello-world/ ├── base │ ├── deployment.yaml │ └── kustomization.yaml └──

    overlays ├── production │ ├── replica_count.yaml │ └── kustomization.yaml └── staging ├── replica_count.yaml └── kustomization.yaml Production
  12. apiVersion: apps/v1 kind: Deployment metadata: name: hello-world spec: replicas: 7

    selector: matchLabels: app: hello-world template: .. Print production configuration
  13. • Helm • Ksonnet • Kapitan • Forge • Ktmpl

    • etc… Another Tools are required
  14. 1. I have to learn new tools… 2. I have

    to learn new DSL… (complicated!) 3. I have to teach new concepts to teams… Drawbacks of those tools
  15. apiVersion: apps/v1 kind: Deployment metadata: name: prod-hello-world spec: replicas: 7

    selector: matchLabels: app: hello-world template: .. Name Prefix
  16. apiVersion: apps/v1 kind: Deployment metadata: name: hello-world labels: owner: spesnova

    spec: replicas: 7 selector: matchLabels: app: hello-world template: .. Common Labels
  17. apiVersion: apps/v1 kind: Deployment metadata: name: hello-world annotations: description: This

    is Hello World App spec: replicas: 7 selector: matchLabels: app: hello-world template: … Common Annotations
  18. apiVersion: v1 data: hello.config: | name=hello-world region=tokyo kind: ConfigMap metadata:

    creationTimestamp: null name: hello-config-4g5t58m8t5 --- apiVersion: apps/v1 kind: Deployment … ConfigMap Generator
  19. apiVersion: v1 data: hello.config: | name=hello-world region=tokyo kind: ConfigMap metadata:

    creationTimestamp: null name: hello-config-4g5t58m8t5 --- apiVersion: apps/v1 kind: Deployment … Hash suffix
  20. apiVersion: v1 data: hello.config: | name=hello-world region=tokyo kind: ConfigMap metadata:

    creationTimestamp: null name: hello-config-bdmmkghm2m --- apiVersion: apps/v1 kind: Deployment … Hash suffix
  21. @@ -3,7 +3,7 @@ metadata: name: hello-world spec: - replicas:

    1 + replicas: 7 selector: matchLabels: app: hello-world $ kustomize diff
  22. 1. Can only override parameterized config 2. DSL is too

    complicated for human 3. Most tools can not read DSL Drawbacks of Templating
  23. 1. I’m using official Redis Helm chart 2. I want

    to add annotation 3. Annotations are not defined in the chart… 4. …Fork? Example
  24. 1. There is a config file “hello.config” 2. Copy contents

    of the file 3. Paste it into configMap 4. … I have 2 config sources… Before kustomize
  25. apiVersion: v1 data: hello.config: | name=hello-world region=tokyo kind: ConfigMap metadata:

    creationTimestamp: null name: hello-config-4g5t58m8t5 --- apiVersion: apps/v1 kind: Deployment … ConfigMap Generator
  26. 1. There is a config file “hello.config” 2. Run “kustomize

    build” 3. kustomize generates configMap 4. The config source is only “hello.config” After kustomize
  27. 1. Update contents of existing configMap 2. Deployment itself is

    not changed… 3. Deployment still reads old configMap… Updating existing configMap
  28. apiVersion: v1 data: hello.config: | name=hello-world region=tokyo kind: ConfigMap metadata:

    creationTimestamp: null name: hello-config-4g5t58m8t5 --- apiVersion: apps/v1 kind: Deployment … Hash suffix
  29. 1. Update contents of configMap 2. kustomize prints new configMap

    3. Update configMap name in deployment 4. Deployment reads new configMap Rolling ConfigMap Update
  30. kustomize exposes and teaches native k8s APIs, rather than hiding

    them. IUUQTHJUIVCDPNLVCFSOFUFTTJHTLVTUPNJ[FCMPCNBTUFSEPDTHMPTTBSZNE
  31. kustomize rollback is very good for GitOps. However, I also

    like heroku style rollback such as “helm status”, “helm history”, “helm rollback”. Helm provides us logical group of k8s resources as “application”. kustomize doesn’t. Rollback
  32. Kustomize was initially developed as its own cli, however once

    it has matured, it should be published as a subcommand of kubectl or as a statically linked plugin. IUUQTHJUIVCDPNLVCFSOFUFTDPNNVOJUZCMPCNBTUFSLFQTTJHDMJLVTUPNJ[FNEJNQMFNFOUBUJPOEFUBJMTOPUFTDPOTUSBJOUTPQUJPOBM
  33. It’s awesome! If kustomize looks easy to use for you,

    I think it comes from good design!
  34. End