kustomization.yaml
docs
kustomization.yaml · The Kubectl Book 日本語訳
GPT-4.icon
構成要素は3つに分類される
table:_
用語 意味
Generator K8sリソースを生成(例:resources, configMapGeneratorなど)
Transformer 生成したリソースを加工(例:namespace, images, commonLabelsなど)
Meta GeneratorやTransformerの挙動を制御(例:generatorOptions, configurationsなど)
Generator(リソース生成)
resources
任意のYAMLファイル(Kubernetesリソース)を読み込む。
code:yaml
resources:
- deployment.yaml
- service.yaml
bases
他のkustomization.yamlを参照する。「DockerのFROM」的な概念。
code:yaml
bases:
- ../base
- https://github.com/org/repo//kustomize/base
configMapGenerator
secretGenerator
Secretを生成。ConfigMapと同様にenv, files, literalsを利用可能。
code:yaml
secretGenerator:
- name: app-secret
env: secrets.env
🧪 Transformer(リソース加工)
commonLabels / commonAnnotations
すべてのリソースに共通のlabel / annotationを追加。
code:yaml
commonLabels:
app: my-app
namespace
全リソースにnamespaceを適用。
code:yaml
namespace: production
namePrefix / nameSuffix
名前の前後に文字列を追加。
code:yaml
namePrefix: dev-
nameSuffix: -v1
images
使用するDockerイメージを一括変更。
code:yaml
images:
- name: nginx
newTag: 1.19
patchesStrategicMerge
「差分YAML(上書き)」によるカスタマイズ。
code:yaml
patchesStrategicMerge:
- patch_deployment.yaml
patchesJson6902
JSON Patch(RFC 6902)形式で差分指定。
code:yaml
patchesJson6902:
- target:
kind: Deployment
name: my-deploy
path: patch.json
vars
リソースの名前などを、Pod内で使える環境変数のように扱う仕組み。
code:yaml
vars:
- name: MY_SECRET_NAME
objref:
kind: Secret
name: my-secret
apiVersion: v1
⚙️ Meta(ふるまい制御)
generatorOptions
ConfigMapやSecret生成時のオプション設定。
code:yaml
generatorOptions:
disableNameSuffixHash: true
configurations
Kustomizeの挙動を拡張(CRDの特定フィールドにもlabelを追加など)。
code:yaml
configurations:
- custom-config.yaml
custom-config.yamlには例えば次のように書く:
code:yaml
commonLabels:
- path: metadata/labels
create: true