<p>I use ConfigMap as Volume in the deployment.
I'm trying to update a deployment with different Volume and VolumeMount.(see example below) </p>

<p>I tried all the following ways:</p>

<p>(I use io.fabric8.kubernetes.api to do the operations on kubernetes.)</p>

<p>1)</p>

<blockquote>
  <p>client().extensions().deployments().inNamespace(namespaceName).withName(deploymentName).<strong>replace(deployment)</strong>;</p>
</blockquote>

<p>2) </p>

<blockquote>
  <p>client().extensions().deployments().inNamespace(namespaceName).withName(deploymentName).<strong>createOrReplace(deployment)</strong>;</p>
</blockquote>

<p>3) </p>

<blockquote>
  <p>client().extensions().deployments().inNamespace(namespaceName).withName(deploymentName).<strong>cascading(false).replace(deployment)</strong>;</p>
</blockquote>

<p>4) </p>

<blockquote>
  <p>client().extensions().deployments().inNamespace(namespaceName).withName(deploymentName).<em>edit().editSpec().editTemplate().editSped().<strong>removeAllFromVolumes(volumes)</strong>.endSpec().endTemplate().endTemplate().endSpec().done()</em>;</p>
</blockquote>

<p>5) </p>

<blockquote>
  <p>client().extensions().deployments().inNamespace(namespaceName).withName(deploymentName).<em>edit().editSpec().editTemplate().editSped().<strong>removeFromVolumes(volume)</strong>.endSpec().endTemplate().endTemplate().endSpec().done()</em>;</p>
</blockquote>

<p>All the above commands don't work!...</p>

<p>I also tried :</p>

<blockquote>
  <p>client().extensions().deployments().inNamespace(namespaceName).withName(deploymentName).<em>edit().editSpec().editTemplate().editSped().<strong>AddToVolumes(volume)</strong>.endSpec().endTemplate().endTemplate().endSpec().done()</em>;</p>
</blockquote>

<p>and it works.</p>

<p>i.e. only ADD works, but REMOVE doesn't work....</p>

<p>Is it a BUG or not ?
Did I use it in the right way?
I just want to update the deployment with different Volume (ConfigMap type) and VolumeMount, how should I do?
Thank you!</p>

<p>Example:
The old Deployment is like this: (I only show the main part)</p>

<pre><code>kind: Deployment
metadata:
  name: d2
  namespace: n1
  spec:
    replicas: 1
    template:
      metadata:
        creationTimestamp: null
      spec:
        containers:
        - image: x.x.x.x
          imagePullPolicy: IfNotPresent
          name: c2
          volumeMounts:
          - mountPath: /var
            name: configmapvolume1
          - mountPath: /var/a
            name: configmapvolume2
        volumes:
        - configMap:
            defaultMode: 420
            items:
            - key: a.yml
              path: a.yml
            name: a
          name: configmapvolume1
        - configMap:
            defaultMode: 420
            items:
            - key: c.yml
              path: c.yml
            name: a
          name: configmapvolume2
</code></pre>

<p>The new Deployment is like this:(I only show the main part)</p>

<pre><code>kind: Deployment
metadata:
  name: d2
  namespace: n1
  spec:
    replicas: 1
    template:
      metadata:
        creationTimestamp: null
      spec:
        containers:
        - image: x.x.x.x
          imagePullPolicy: IfNotPresent
          name: c2
          volumeMounts:
          - mountPath: /var/b
            name: configmapvolume1
        volumes:
        - configMap:
            defaultMode: 420
            items:
            - key: b.yml
              path: b.yml
            name: b
          name: configmapvolume1
</code></pre>

Sha Huang
<p>If you add --save-config when you create your deployment for the first time, you’ll be able to adjust its specification later:</p>

<pre><code>kubectl create -f deploymentv1.yaml --save-config
</code></pre>

<p>To update it with adjusted yaml file run the following command:</p>

<pre><code>kubectl apply -f deploymentv2.yaml
</code></pre>

<p>This way new pod will be created from the adjusted specification. The old pod will be terminated then.</p>

<p>I’ll update my answer when I figure out how to apply <code>--save-config</code> option using java code.</p>
