kustomize

23 commands

23 shown

Build kustomization Render all manifests for an overlay to stdout kustomize build ./overlays/prod #kustomize Apply kustomization Build and apply kustomization in one step via kubectl kubectl apply -k ./overlays/prod #kustomize Diff kustomization Show what changes before applying kubectl diff -k ./overlays/prod #kustomize#debug Add resource to kustomization Append a resource file to kustomization.yaml kustomize edit add resource ./deployment.yaml #kustomize Set image in kustomization Update image tag in kustomization.yaml kustomize edit set image myapp=registry/myapp:v2.0.0 #kustomize Set namespace Override namespace for all resources in the overlay kustomize edit set namespace production #kustomize Add label to all resources Inject a common label into all generated resources kustomize edit add label env:production #kustomize Add patch Register a strategic merge patch in kustomization.yaml kustomize edit add patch --path patch.yaml --kind Deployment --name <name> #kustomize List resources List all settable fields in the kustomization kustomize cfg list-setters . #kustomize Build and apply Build kustomize overlay and apply directly to cluster kubectl apply -k ./overlays/prod #kustomize#k8s#deploy Preview output Render kustomize output without applying kubectl kustomize ./overlays/prod | head -100 #kustomize#k8s#preview Set image tag Update image tag in kustomization.yaml kustomize edit set image myapp=myapp:v1.2.3 #kustomize#k8s#image#deploy Add configMapGenerator Add a ConfigMap generator entry to kustomization.yaml kustomize edit add configmap my-config --from-literal=key=value #kustomize#k8s#configmap List resources in overlay Quickly list all resource kinds in a kustomize build kustomize build ./overlays/prod | grep "^kind:" #kustomize#k8s#resources Apply strategic merge patch Use patchesStrategicMerge to partially override base resources # Add patchesStrategicMerge in kustomization.yaml #kustomize#k8s#patch#strategic-merge Apply strategic merge patch Create a strategic merge patch and register it in kustomization.yaml cat > patch.yaml <<EOF apiVersion: apps/v1 kind: Deployment metadata: name: myapp spec: replicas: 3 template: spec: containers: - name: myapp resources: limits: memory: 512Mi EOF echo 'patches:\n- path: patch.yaml' >> kustomization.yaml #kustomize#k8s#patch#strategic-merge Inflate Helm charts in kustomize build Render helmCharts: block to manifests; note: needs helm in PATH kustomize build --enable-helm ./overlay #kustomize#gitops#k8s Apply a reusable component overlay Mixin reusable patches/resources via components: (Kustomize v4+) cat <<'EOF' >> kustomization.yaml components: - ../../components/monitoring EOF #kustomize#gitops#k8s Copy a field with replacements modern: replacements: copies a field cross-resource, replaces deprecated vars: cat <<'EOF' >> kustomization.yaml replacements: - source: {kind: ConfigMap, name: cfg, fieldPath: data.host} targets: - select: {kind: Deployment} fieldPaths: [spec.template.spec.containers.0.env.0.value] EOF #kustomize#gitops#k8s Inline patch with target selector JSON6902 patch applied to all matching targets, no separate file cat <<'EOF' >> kustomization.yaml patches: - target: {kind: Deployment, labelSelector: app=api} patch: |- - op: replace path: /spec/replicas value: 3 EOF #kustomize#gitops#k8s Pin image by digest and rename Pin by immutable digest; newName+digest also settable in images: block kustomize edit set image app=registry.example.com/app@sha256:<id> #kustomize#gitops#security#k8s Secret generator without hash suffix note: disableNameSuffixHash keeps stable name but breaks rollout-on-change cat <<'EOF' >> kustomization.yaml secretGenerator: - name: db-creds literals: [PASSWORD=s3cr3t] generatorOptions: disableNameSuffixHash: true EOF #kustomize#secrets#gitops#k8s Register CRD OpenAPI for merge keys Teach kustomize CRD merge/list semantics so patches merge correctly cat <<'EOF' >> kustomization.yaml openapi: path: crd-schema.json EOF #kustomize#gitops#k8s
no commands match