Kubectl kustomize: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(12 intermediate revisions by the same user not shown)
Line 2: Line 2:


* https://kubernetes.io/blog/2018/05/29/introducing-kustomize-template-free-configuration-customization-for-kubernetes/
* https://kubernetes.io/blog/2018/05/29/introducing-kustomize-template-free-configuration-customization-for-kubernetes/
* https://github.com/kubernetes-sigs/kustomize
* https://github.com/kubernetes-sigs/kustomize/tree/master/docs


=Internal=
=Internal=
Line 16: Line 16:
The directory specified as argument must contain <tt>kustomization.yaml</tt>.
The directory specified as argument must contain <tt>kustomization.yaml</tt>.


A <tt>kustomization.yaml</tt> example follows:
kustomize has the concept of overlay and base. Both are represented by kustomization files. The base declares the things that all possible output manifest variants (example development, staging and production) share, which include common customizations and resources, and the overlays declare the differences. The kustomization files are maintained in directories named "base", "overlays", in which each overlay has its own sub-directory.


  <font color=Burlywood># add the specified labels to all resources</font>
A patch is a general instruction to modify a resource. More specifically, a patch is a partial resource declaration that once applied, modifies just a subset of the configuration. .kustomize supports [[Kubernetes Strategic Merge Patch|strategic merge patches]] and [[JSON Patch|JSON patches]].
 
=kustomization.yaml Example=
 
  <font color=burlywood># add the specified labels to all resources</font>
  commonLabels:
  commonLabels:
   app: hello
   app: hello
  # add the specified annotations to all resources
  <font color=burlywood># add the specified annotations to all resources</font>
  commonAnnotations:
  commonAnnotations:
   ...
   ...
  # add the specified common prefix to all resource names
  <font color=burlywood># add the specified common prefix to all resource names</font>
  namePrefix:
  namePrefix: <font color=teal>blue-</font>
<font color=burlywood># ?</font>
namespace: ... 
<font color=burlywood># ?</font>
images:
- name: <font color=teal>something</font>
  newTag: <font color=teal>some-new-tag</font>
<font color=burlywood># ?</font>
patches:
- patch-file-1.yaml
<font color=burlywood># ?</font>
patchesStrategicMerge:
- patch-file-2.yaml
  resources:
  resources:
  - deployment.yaml
  - deployment-manifest.yaml
  - configMap.yaml
  - configmap-manifest.yaml
  - service.yaml
  - service-manifest.yaml
 
=kustomization.yaml Example=
 
<syntaxhighlight lang='yaml'>
namePrefix:
images:
- name: something
  newTag: ...
namespace: ... 
resources:
- manifest-1.yaml
- manifest-2.yaml
patchesStrategicMerge:
- file1.yaml
</syntaxhighlight>


=TODO=
=TODO=


<font color=darkgray>It seems to add prefixes to names, update image tags, adds namespace metadata, "yaml-cleans" according to rules that have yet to be elucidated.</font>
<font color=darkgray>It seems to add prefixes to names, update image tags, adds namespace metadata, "yaml-cleans" according to rules that have yet to be elucidated.</font>

Latest revision as of 18:26, 23 August 2019

External

Internal

Overview

The "kustomize" logic reads a series of source API resource manifests, instructions from a kustomization.yaml file and generates syntactically valid and complete API resource manifests at stdout. The generated content may contain multiple resource representations, separated by ---. The output can be further processed by other tools or streamed directly into kubectl for deployment to a cluster.

kubectl kustomize <dirname> > output.yaml

The directory specified as argument must contain kustomization.yaml.

kustomize has the concept of overlay and base. Both are represented by kustomization files. The base declares the things that all possible output manifest variants (example development, staging and production) share, which include common customizations and resources, and the overlays declare the differences. The kustomization files are maintained in directories named "base", "overlays", in which each overlay has its own sub-directory.

A patch is a general instruction to modify a resource. More specifically, a patch is a partial resource declaration that once applied, modifies just a subset of the configuration. .kustomize supports strategic merge patches and JSON patches.

kustomization.yaml Example

# add the specified labels to all resources
commonLabels:
  app: hello
# add the specified annotations to all resources
commonAnnotations:
  ...
# add the specified common prefix to all resource names
namePrefix: blue-
# ?
namespace: ...   
# ?
images:
- name: something
  newTag: some-new-tag
# ?
patches:
- patch-file-1.yaml
# ?
patchesStrategicMerge:
- patch-file-2.yaml
resources:
- deployment-manifest.yaml
- configmap-manifest.yaml
- service-manifest.yaml

TODO

It seems to add prefixes to names, update image tags, adds namespace metadata, "yaml-cleans" according to rules that have yet to be elucidated.