Kustomizing your Kubernetes Deployments Cloud Native Computing Switzerland Meetup, 22 November 2018 David Schweikert @dschweikert AdNovum Informatik AG
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:
Transformations myApp| ├── base │ ├── deployment.yaml │ └── kustomization.yaml | ├── development │ └── kustomization.yaml bases: - ../base namePrefix: dev- § All resource names are now prefixed with “dev-”
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
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
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 !!!
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
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)
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