Kubernetes/kustomize: Difference between revisions
Jump to navigation
Jump to search
(5 intermediate revisions by the same user not shown) | |||
Line 15: | Line 15: | ||
or Install manifest directly: | or Install manifest directly: | ||
# Apply resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml | |||
kubectl apply -k DIR | kubectl apply -k DIR | ||
or string kustomize: | |||
kustomize build DIR [flags] | kubectl apply -f - | |||
# eg. that uses ../../files/tls.key | |||
kustomize build --load-restrictor=LoadRestrictionsNone patches/ssl-patch | |||
== Installation == | == Installation == | ||
Line 39: | Line 39: | ||
Via binary: <ref>https://kubectl.docs.kubernetes.io/installation/kustomize/binaries/</ref> | Via binary: <ref>https://kubectl.docs.kubernetes.io/installation/kustomize/binaries/</ref> | ||
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash | curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash | ||
mv kustomize /usr/local/bin/kustomize | |||
Version: | Version: | ||
Line 72: | Line 73: | ||
- configMap.yaml | - configMap.yaml | ||
</pre> | </pre> | ||
== Envs == | |||
<pre> | |||
cat <<'EOF' >$DEMO_HOME/foo.env | |||
ROUTER_PASSWORD=admin | |||
DB_PASSWORD=iloveyou | |||
EOF | |||
</pre> | |||
<pre> | |||
cat <<'EOF' >$DEMO_HOME/kustomization.yaml | |||
secretGenerator: | |||
- name: mysecrets | |||
envs: | |||
- foo.env | |||
files: | |||
- longsecret.txt | |||
literals: | |||
- FRUIT=apple | |||
- VEGETABLE=carrot | |||
EOF | |||
</pre> | |||
ref: [https://github.com/kubernetes-sigs/kustomize/blob/master/examples/secretGeneratorPlugin.md] | |||
== Patch == | |||
Ingress replace Example: <ref>https://medium.com/@giorgiodevops/kustomize-use-patches-to-add-or-override-resources-48ef65cb634c</ref> | |||
Sample project structure: | |||
<pre> | |||
|-- base | |||
ingress.yaml | |||
deployment.yaml | |||
kustomization.yaml | |||
|-- overlays | |||
|-- prod | |||
ingress-patch.yaml | |||
kustomization.yaml | |||
|-- dev | |||
ingress-patch.yaml | |||
kustomization.yaml | |||
</pre> | |||
ingress: | |||
<pre> | |||
... | |||
spec: | |||
ingressClassName: alb | |||
rules: | |||
- host: app.devopscons.com #it will be dev-app.devopscons.com | |||
... | |||
</pre> | |||
ingress-patch.yaml | |||
<pre> | |||
- op: replace #action | |||
path: /spec/rules/0/host #resouirce we want to change | |||
value: dev-app.devopscons.com #value we want to use for patching | |||
</pre> | |||
add to kustomization.yaml: | |||
<pre> | |||
patches: | |||
- target: | |||
group: networking.k8s.io | |||
version: v1 | |||
kind: Ingress | |||
name: ingress | |||
path: ingress-patch.yaml | |||
</pre> | |||
--- | |||
Resouce Example: <ref>https://medium.com/@giorgiodevops/kustomize-use-patches-to-add-or-override-resources-48ef65cb634c</ref> | |||
some-patch.yaml | |||
<pre> | |||
- op: add #action | |||
path: "/spec/template/spec/nodeSelector" #resouirce we want to change | |||
value: #value we want to use for patching | |||
env: prod | |||
type: spot | |||
version: "3" | |||
</pre> | |||
and add to kuszomization patch section like above. | |||
other references: | |||
* https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/#customizing | |||
== keywords == | == keywords == |
Latest revision as of 04:57, 9 November 2024
kustomize
kubectl kustomize | Kubernetes https://kubernetes.io/docs/reference/kubectl/generated/kubectl_kustomize/
Generate manifest
kubectl kustomize DIR [flags] # or kustomize build DIR [flags]
# then do a " > out.yaml " to save
Install manifest:
kubectl apply -f out.yaml
or Install manifest directly:
# Apply resources from a directory containing kustomization.yaml - e.g. dir/kustomization.yaml kubectl apply -k DIR
or string kustomize:
kustomize build DIR [flags] | kubectl apply -f -
# eg. that uses ../../files/tls.key kustomize build --load-restrictor=LoadRestrictionsNone patches/ssl-patch
Installation
Installation
Kustomize Installation https://kubectl.docs.kubernetes.io/installation/kustomize/
Via Go source: [1]
git clone git@github.com:kubernetes-sigs/kustomize.git cd kustomize make kustomize # git checkout kustomize/v5.0.0 ~/go/bin/kustomize version
Via binary: [2]
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash mv kustomize /usr/local/bin/kustomize
Version:
kustomize version v5.4.2
Kustomize
Kustomize - Kubernetes native configuration management https://kustomize.io/
Kustomize introduces a template-free way to customize application configuration that simplifies the use of off-the-shelf applications. Now, built into kubectl as apply -k.
Hello World
Hello World https://github.com/kubernetes-sigs/kustomize/blob/master/examples/helloWorld/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization metadata: name: arbitrary # Example configuration for the webserver # at https://github.com/monopole/hello commonLabels: app: hello resources: - deployment.yaml - service.yaml - configMap.yaml
Envs
cat <<'EOF' >$DEMO_HOME/foo.env ROUTER_PASSWORD=admin DB_PASSWORD=iloveyou EOF
cat <<'EOF' >$DEMO_HOME/kustomization.yaml secretGenerator: - name: mysecrets envs: - foo.env files: - longsecret.txt literals: - FRUIT=apple - VEGETABLE=carrot EOF
ref: [1]
Patch
Ingress replace Example: [3]
Sample project structure:
|-- base ingress.yaml deployment.yaml kustomization.yaml |-- overlays |-- prod ingress-patch.yaml kustomization.yaml |-- dev ingress-patch.yaml kustomization.yaml
ingress:
... spec: ingressClassName: alb rules: - host: app.devopscons.com #it will be dev-app.devopscons.com ...
ingress-patch.yaml
- op: replace #action path: /spec/rules/0/host #resouirce we want to change value: dev-app.devopscons.com #value we want to use for patching
add to kustomization.yaml:
patches: - target: group: networking.k8s.io version: v1 kind: Ingress name: ingress path: ingress-patch.yaml
---
Resouce Example: [4]
some-patch.yaml
- op: add #action path: "/spec/template/spec/nodeSelector" #resouirce we want to change value: #value we want to use for patching env: prod type: spot version: "3"
and add to kuszomization patch section like above.
other references:
keywords
- ↑ https://kubectl.docs.kubernetes.io/installation/kustomize/source/
- ↑ https://kubectl.docs.kubernetes.io/installation/kustomize/binaries/
- ↑ https://medium.com/@giorgiodevops/kustomize-use-patches-to-add-or-override-resources-48ef65cb634c
- ↑ https://medium.com/@giorgiodevops/kustomize-use-patches-to-add-or-override-resources-48ef65cb634c