title: How to update/replace deployment of Kubernetes in JAVA
body: <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>