kustomize patching a specific container other than by array (/containers/0)
This is more of a Json6902 patch limitation together with the fact that containers are defined in a K8s pod as an Array and not a Hash where something like this would work:
path: /spec/containers/${NAME_OF_CONTAINER}/command
You could just try a StrategicMergePatch. which essentially what kubectl apply
does.
cat <<EOF > deployment.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: my-appspec: selector: matchLabels: run: my-app replicas: 2 template: metadata: labels: run: my-app spec: containers: - name: my-container image: myimage ports: - containerPort: 80EOF
cat <<EOF > set_command.yamlapiVersion: apps/v1kind: Deploymentmetadata: name: my-nginxspec: template: spec: containers: - name: my-app command: ["sh", "-c", "tail -f /dev/null"]EOF
cat <<EOF >./kustomization.yamlresources:- deployment.yamlpatchesStrategicMerge:- set_command.yamlEOF
✌️