UseCases of Kustomize
This is the second article out of three articles on Kubernetes tool : Kustomize. This article covers the usecases.
==============================
UseCase 1 : Config map generation and secreat generation
secretGenerator:
- name: myregistrykey
type: docker-registry
literals:
- docker-server=DOCKER_REGISTRY_SERVER
- docker-username=DOCKER_USER
- docker-password=DOCKER_PASSWORD
- docker-email=DOCKER_EMAIL
This is same as:
kubectl create secret docker-registry myregistrykey --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL
Same as above configMapGenerator
configMapGenerator
- name: profile
files:
- hello.config
We can also merge two configmaps
configMapGenerator:
- name: my-configmap
behavior: merge
files:
- plumbing.properties
- secret.properties
Configmap from literals
configMapGenerator:
- name: my-configmap
literals:
- foo=bar
- baz=qux
==============================
UseCase 2 : Creating multiple variants using overlays.
Edit attributes as per specific file. Here localserv.yaml . Keyword is patchesStrategicMerge
kustomize edit add patch ocalserv.yaml
bases:
- ../../base
patchesStrategicMerge:
- localserv.yaml
Multi Variant Examples:
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/helloWorld/README.md
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/breakfast.md
we can use "kustomize diff base/variant1/variant2" command to see the difference.
==============================
UseCase 3 : edit container image and tag
kustomize edit set image busybox=alpine:3.6
images:
- name: busybox
newName: alpine
newTag: 3.6
==============================
UseCase 4 : Remote Target
kustomize build can be run on a URL.
The effect is the same as cloning the repo, checking out a particular ref (commit hash, branch name, release tag, etc.), then running kustomize build against the desired directory in the local copy.
==============================
UseCase 5 : applying a JSON patch. Replace and add
cat <$DEMO_HOME/ingress_patch.json
[
{"op": "replace", "path": "/spec/rules/0/host", "value": "foo.bar.io"},
{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/servicePort", "value": 8080}
]
EOF
You can also write the patch in YAML format. This example also shows the "add" operation:
cat <$DEMO_HOME/ingress_patch.yaml
- op: replace
path: /spec/rules/0/host
value: foo.bar.io
- op: add
path: /spec/rules/0/http/paths/-
value:
path: '/test'
backend:
serviceName: my-test
servicePort: 8081
EOF
patchesJson6902:
- target:
group: apps
version: v1
kind: Deployment
name: my-nginx
path: patch.yaml
==============================
UseCase 6 : Patch on multiple objects
JSON patch and strategic merge patch can be applied to selected resources
patches:
- path: "PatchFile"
target:
group: "Group"
version: "Version"
kind: "Kind"
name: "Name"
namespace: "Namespace"
labelSelector: "LabelSelector"
annotationSelector: "AnnotationSelector"
==============================
UseCase 7 : Injecting k8s runtime data into containers
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/wordpress/README.md
==============================
UseCase 1 : Config map generation and secreat generation
secretGenerator:
- name: myregistrykey
type: docker-registry
literals:
- docker-server=DOCKER_REGISTRY_SERVER
- docker-username=DOCKER_USER
- docker-password=DOCKER_PASSWORD
- docker-email=DOCKER_EMAIL
This is same as:
kubectl create secret docker-registry myregistrykey --docker-server=DOCKER_REGISTRY_SERVER --docker-username=DOCKER_USER --docker-password=DOCKER_PASSWORD --docker-email=DOCKER_EMAIL
Same as above configMapGenerator
configMapGenerator
- name: profile
files:
- hello.config
We can also merge two configmaps
configMapGenerator:
- name: my-configmap
behavior: merge
files:
- plumbing.properties
- secret.properties
Configmap from literals
configMapGenerator:
- name: my-configmap
literals:
- foo=bar
- baz=qux
==============================
UseCase 2 : Creating multiple variants using overlays.
Edit attributes as per specific file. Here localserv.yaml . Keyword is patchesStrategicMerge
kustomize edit add patch ocalserv.yaml
bases:
- ../../base
patchesStrategicMerge:
- localserv.yaml
Multi Variant Examples:
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/helloWorld/README.md
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/breakfast.md
we can use "kustomize diff base/variant1/variant2" command to see the difference.
==============================
UseCase 3 : edit container image and tag
kustomize edit set image busybox=alpine:3.6
images:
- name: busybox
newName: alpine
newTag: 3.6
==============================
UseCase 4 : Remote Target
kustomize build can be run on a URL.
The effect is the same as cloning the repo, checking out a particular ref (commit hash, branch name, release tag, etc.), then running kustomize build against the desired directory in the local copy.
==============================
UseCase 5 : applying a JSON patch. Replace and add
cat <
[
{"op": "replace", "path": "/spec/rules/0/host", "value": "foo.bar.io"},
{"op": "replace", "path": "/spec/rules/0/http/paths/0/backend/servicePort", "value": 8080}
]
EOF
You can also write the patch in YAML format. This example also shows the "add" operation:
cat <
- op: replace
path: /spec/rules/0/host
value: foo.bar.io
- op: add
path: /spec/rules/0/http/paths/-
value:
path: '/test'
backend:
serviceName: my-test
servicePort: 8081
EOF
patchesJson6902:
- target:
group: apps
version: v1
kind: Deployment
name: my-nginx
path: patch.yaml
==============================
UseCase 6 : Patch on multiple objects
JSON patch and strategic merge patch can be applied to selected resources
patches:
- path: "PatchFile"
target:
group: "Group"
version: "Version"
kind: "Kind"
name: "Name"
namespace: "Namespace"
labelSelector: "LabelSelector"
annotationSelector: "AnnotationSelector"
==============================
UseCase 7 : Injecting k8s runtime data into containers
https://github.com/kubernetes-sigs/kustomize/blob/master/examples/wordpress/README.md
0 comments:
Post a Comment