I am running kubectl version 1.7
I am trying to add an init container to my deployment via kubectl patch
but no matter how I try it it simply returns "not patched".
kubectl patch deployment my-deployment --patch "$(cat ./init-patch.yaml)"
deployment "my-deployment" not patched
spec: template: spec: initContainers: - name: my-mount-init image: "my-image" command: - "sh" - "-c" - "mkdir /mnt/data && chmod -R a+rwx /mnt/data" volumeMounts: - name: "my-volume" mountPath: "/mnt/data" securityContext: runAsUser: 0 resources: limits: cpu: "0.2" memory: "256Mi" requests: cpu: "0.1" memory: "128Mi"
This is to allow a custom linux user rights to read and write to the volume instead of needing to be the root user.
Wish there was a better response as to why it is not being patched..
I have a similar issue, my patch is even simpler:
$ kubectl patch deployment backoffice-deployment \
--patch '{"spec":{"template":{"spec":{"containers":[{"name":"backoffice","image":"eu.gcr.io/ID/image:dev"}]}}}}' --v=7
I0924 18:59:37.260341 15253 loader.go:357] Config loaded from file ~/.kube /config
I0924 18:59:37.267166 15253 round_trippers.go:384] GET https://35.205.207.230/apis/extensions/v1beta1/namespaces/default/deployments/backoffice-deployment
I0924 18:59:37.267181 15253 round_trippers.go:391] Request Headers:
I0924 18:59:37.267189 15253 round_trippers.go:394] User-Agent: kubectl/v1.10.7 (linux/amd64) kubernetes/0c38c36
I0924 18:59:37.267196 15253 round_trippers.go:394] Accept: application/json
I0924 18:59:37.323660 15253 round_trippers.go:409] Response Status: 200 OK in 56 milliseconds
I0924 18:59:37.326175 15253 round_trippers.go:384] PATCH https://35.205.207.230/apis/extensions/v1beta1/namespaces/default/deployments/backoffice-deployment
I0924 18:59:37.326217 15253 round_trippers.go:391] Request Headers:
I0924 18:59:37.326242 15253 round_trippers.go:394] Content-Type: application/strategic-merge-patch+json
I0924 18:59:37.326265 15253 round_trippers.go:394] User-Agent: kubectl/v1.10.7 (linux/amd64) kubernetes/0c38c36
I0924 18:59:37.326287 15253 round_trippers.go:394] Accept: application/json
I0924 18:59:37.343313 15253 round_trippers.go:409] Response Status: 200 OK in 16 milliseconds
deployment.extensions "backoffice-deployment" not patched
F0924 18:59:37.349946 15253 helpers.go:119]
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.7", GitCommit:"0c38c362511b20a098d7cd855f1314dad92c2780", GitTreeState:"clean", BuildDate:"2018-08-20T10:09:03Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"10+", GitVersion:"v1.10.7-gke.1", GitCommit:"7221ffe8776f399448d61b4dc9edb5c69232aece", GitTreeState:"clean", BuildDate:"2018-08-29T23:11:12Z", GoVersion:"go1.9.3b4", Compiler:"gc", Platform:"linux/amd64"}
Kubectl is not idempotent. If the element to be patched already contains the patch, kubectl patch fails.
The solution can be read in Natim's comment, but it took me a while to realise that was indeed my problem.