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

Kustomizing your Kubernetes Deployments

Kustomizing your Kubernetes Deployments

How to parametrize your Kubernetes object definitions using kustomize, a template-free customization tool.

Talk presented at the Cloud Native Computing Meetup November 2018.

David Schweikert

November 22, 2018
Tweet

More Decks by David Schweikert

Other Decks in Technology

Transcript

  1. Kustomizing your Kubernetes Deployments Cloud Native Computing Switzerland Meetup, 22

    November 2018 David Schweikert @dschweikert AdNovum Informatik AG
  2. Me in 2017: ! § OpenShift Templates § Helm §

    Self-made? Jinja2? § Even thinking of using Ansible…
  3. Ansible Forge Helm K8comp KPM KY Kapitan Kdeploy Kedge Kenv

    Kexpand Kit-Deploymentizer Kompose Konfd Kontemplate Ksonnet Ktmpl Kubecfg Kubegen Kubernetes-deploy Kubetpl Kustomize Mortar OpenShift templates Psykube Spread Terraform …
  4. kind: Service apiVersion: v1 metadata: name: my-service spec: selector: app:

    MyApp ports: - protocol: TCP port: 80 targetPort: 9376 my-service.yaml:
  5. local params = std.extVar("__ksonnet/params").components.demo; local k = import "k.libsonnet"; local

    service = k.core.v1.service; local servicePort = k.core.v1.service.mixin.spec.portsType; local targetPort = params.containerPort; local labels = {app: params.name}; local appService = service .new( params.name, labels, servicePort.new(params.servicePort, targetPort)) .withType(params.type); k.core.v1.list.new([appService]) Ksonnet:
  6. Helm: § forget about kubectl, now you need to always

    use “helm install”, “helm ls”, “helm status”
  7. apiVersion: v1 kind: Service metadata: name: {{ template "grafana.fullname" .

    }} labels: app: {{ template "grafana.name" . }} chart: {{ template "grafana.chart" . }} release: {{ .Release.Name }} heritage: {{ .Release.Service }} {{- if .Values.service.labels }} {{ toYaml .Values.service.labels | indent 4 }} {{- end }} {{- with .Values.service.annotations }} annotations: {{ toYaml . | indent 4 }} {{- end }} spec: {{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }} type: ClusterIP {{- if .Values.service.clusterIP }} clusterIP: {{ .Values.service.clusterIP }} {{end}} {{- else if eq .Values.service.type "LoadBalancer" }} …
  8. Overlays myApp | ├── base │ ├── deployment.yaml │ ├──

    kustomization.yaml │ └── service.yaml | ├── development │ ├── ingress.yaml │ └── kustomization.yaml | └── production ├── ingress.yaml └── kustomization.yaml resources: - deployment.yaml - service.yaml
  9. Overlays myApp | ├── base │ ├── deployment.yaml │ ├──

    kustomization.yaml │ └── service.yaml | ├── development │ ├── ingress.yaml │ └── kustomization.yaml | └── production ├── ingress.yaml └── kustomization.yaml bases: - ../base resources: - ingress.yaml bases: - ../base resources: - ingress.yaml
  10. $ kustomize build development apiVersion: v1 kind: Service metadata: …

    --- apiVersion: apps/v1 kind: Deployment metadata: … --- apiVersion: apps/v1 kind: Ingress metadata: …
  11. Transformations myApp| ├── base │ ├── deployment.yaml │ └── kustomization.yaml

    | ├── development │ └── kustomization.yaml bases: - ../base namePrefix: dev- § All resource names are now prefixed with “dev-”
  12. Transformations It’s what makes kustomize so powerful: § Because it

    knows Kubernetes semantics § A single line, use-case specific (e.g. namePrefix) causes big changes § All references are preserved
  13. Generators kustomization.yaml: configMapGenerator: - name: myconfig files: - configs/configfile -

    configs/another_configfile § generates: myconfig-b62k6t7g8f (and fixes all references to it) § b62k6t7g8f is a hash of the contents
  14. Generators kustomization.yaml: configMapGenerator: - name: myconfig files: - configs/configfile -

    configs/another_configfile § generates: myconfig-b62k6t7g8f (and fixes all references to it) § b62k6t7g8f is a hash of the contents !!!
  15. Patches myApp| ├── base │ ├── deployment.yaml │ └── kustomization.yaml

    | ├── development | ├── deployment.patch.yaml │ └── kustomization.yaml bases: - ../base patches: - deployment.patch.yaml
  16. Patches myApp| ├── base │ ├── deployment.yaml │ └── kustomization.yaml

    | ├── development | ├── deployment.patch.yaml │ └── kustomization.yaml apiVersion: apps/v1 kind: Deployment metadata: name: myapp spec: replicas: 1
  17. Challenges § Things that Kustomize doesn’t know about § OpenShift

    objects § CRDs It is now possible to extend Kustomize knowledge about Kubernetes objects see also: https://github.com/adnovum/kustomize-openshift
  18. Summary When to use kustomize § It’s the perfect tool

    to parametrize your own application When not to use kustomize § Packaging an application for the general public (use Helm for that)
  19. Questions? More about this topic: § Declarative application management in

    Kubernetes August 2017, by Brian Grant § Introducing kustomize; Template-free Configuration Customization for Kubernetes May 2018, by Jeff Regan and Phil Wittrock Contacting me: § [email protected], @dschweikert