'how to replace or find correct path for kustomize
I have deployment and I want to replace "path" value in liveness probe section. What is correct path for this in kustomize?
- patch: |-
- op: replace
path: ??????????
value:
https://xyz.staging.something.eu/ping
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-http
spec:
containers:
- name: liveness
image: k8s.gcr.io/liveness
args:
- /server
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
Solution 1:[1]
It is the yaml path. You follow the nodes from the parent down to the leaf-node you want to specify.
Since you want the path
node on httpGet
of livenessProbe
it will end with livenessProbe.httpGet.path
.
The parent node of livenessProbe is a bit trickier, notice it is an element of the list containers
. You can specify it either through an index or through an attribute (EG name
). So either containers[0]
or containers[name=liveness]
.
By now we have containers[0].livenessProbe.httpGet.path
. The missing root node is spec
, so spec.containers[0].livenessProbe.httpGet.path
will do it.
There is a bunch of other ways that this could be expressed as well. https://github.com/wwkimball/yamlpath#illustration seems like a good more in-depth explanation.
Solution 2:[2]
I am trying out the syntax containers[name=xx]
and its failing when containers/0
works. I am not sure if im missing something or this is not supported, couldn't find any more examples about this syntax for Kustomize.
Below the details
Checked with kustomize versions:
- v4.5.4
- v4.5.2
test.yaml:
---
apiVersion: v1
kind: Pod
metadata:
name: test-pod
spec:
containers:
- name: test-container
env:
- name: environment
value: stage
- name: api_port
value: "8080"
image: docker.io/bitname/posgresql:latest
...
...
kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
...
...
patchesJson6902:
- target:
version: v1
kind: Pod
name: test-pod
path: replace.yaml
replace.yaml
- op: replace
path: "/spec/containers[name=test-container]/env/0/value"
value: "dev"
# doesn't work: `Error: replace operation does not apply: doc is missing path" /spec/containers[name=test-container]/env/0/value: missing value
- op: replace
path: "/spec/containers/0/env/0/value"
value: "dev"
# works as expected
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | chicocvenancio |
Solution 2 | Mauro |