<p>I am running kubectl version 1.7</p>

<p>I am trying to add an init container to my deployment via <code>kubectl patch</code> but no matter how I try it it simply returns "not patched". </p>

<p><code>kubectl patch deployment my-deployment --patch "$(cat ./init-patch.yaml)"</code>
<strong>deployment "my-deployment" not patched</strong></p>

<p><code>spec:
  template:
    spec:
      initContainers:
        - name: my-mount-init
          image: "my-image"
          command:
            - "sh"
            - "-c"
            - "mkdir /mnt/data &amp;&amp; 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"</code></p>

<p>This is to allow a custom linux user rights to read and write to the volume instead of needing to be the root user.</p>

<p>Wish there was a better response as to why it is not being patched..</p>

<p>Kubectl is not idempotent. If the element to be patched already contains the patch, kubectl patch fails. </p>

<p>The solution can be read in Natim's comment, but it took me a while to realise that was indeed my problem.</p>
