<p>I am working locally with minikube and every time i make a change on the code, i delete the service (and the deployment) and create a new one.</p>

<p>This operation generate a new IP for each container so i also need to update my frontend, and also to insert new data in my db container, since i loose every data every time i delete the service.</p>

<p>It’s way too much wasted time to work efficiently.</p>

<p>I would like to know if there is a way to update a container without generating new IPs, and without deleting the pod (because i don't want to delete my db container everytime i update the backend code)?</p>

Ludo
<p>It's easy to update the existing <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployment</a> with a new image without necessity to delete it.</p>

<p>Imagine we have a YAML <a href="https://github.com/kubernetes/website/blob/master/content/en/docs/concepts/workloads/controllers/nginx-deployment.yaml" rel="nofollow noreferrer">file</a> with the Deployment.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
</code></pre>

<p>To run this deployment, run the following command: </p>

<pre><code>$ kubectl create -f nginx-deployment.yaml --record
</code></pre>

<p>(<code>--record</code> - appends the current command to the annotations of the created or updated resource. This is useful for future reviews, such as investigating which commands were executed in each Deployment revision, and for making a rollback.)</p>

<p>To see the Deployment rollout status, run </p>

<pre><code>$ kubectl rollout status deployment/nginx-deployment
</code></pre>

<p>To update nginx image version, just run the command: </p>

<pre><code>$ kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
</code></pre>

<p>Or you can edit existing Deployment with the command:</p>

<pre><code>$ kubectl edit deployment/nginx-deployment
</code></pre>

<p>To see the status of the Deployment update process, run the command:</p>

<pre><code>$ kubectl rollout status deployment/nginx-deployment
Waiting for rollout to finish: 2 out of 3 new replicas have been updated...
deployment "nginx-deployment" successfully rolled out
</code></pre>

<p>or </p>

<pre><code>$ kubectl get deployments
NAME               DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
nginx-deployment   3         3         3            3           36s
</code></pre>

<p>Each time you update the Deployment, it updates the Pods by creating new ReplicaSet, scaling it to 3 replicas, and scaling down old ReplicaSet to 0. If you update the Deployment again during the previous update in progress, it starts to create new ReplicaSet immediately, without waiting for completion of the previous update.</p>

<pre><code>$ kubectl get rs
NAME                          DESIRED   CURRENT   READY   AGE
nginx-deployment-1180356465   3         3         3       4s
nginx-deployment-2538420311   0         0         0       56s
</code></pre>

<p>If you made a typo while editing the Deployment (for example, nginx:1.91) you can rollback it to the previous good version.<br>
First, check the revisions of this deployment:</p>

<pre><code>$ kubectl rollout history deployment/nginx-deployment
deployments "nginx-deployment"
REVISION    CHANGE-CAUSE
1           kubectl create -f nginx-deployment.yaml --record
2           kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
3           kubectl set image deployment/nginx-deployment nginx=nginx:1.91
</code></pre>

<p>Because we recorded the command while creating this Deployment using --record, we can easily see the changes we made in each revision.</p>

<p>To see the details of each revision, run:</p>

<pre><code>$ kubectl rollout history deployment/nginx-deployment --revision=2
deployments "nginx-deployment" revision 2
  Labels:       app=nginx
          pod-template-hash=1159050644
  Annotations:  kubernetes.io/change-cause=kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
  Containers:
   nginx:
    Image:      nginx:1.9.1
    Port:       80/TCP
     QoS Tier:
        cpu:      BestEffort
        memory:   BestEffort
    Environment Variables:      &lt;none&gt;
  No volumes.
</code></pre>

<p>Now you can rollback to the previous version using command:</p>

<pre><code>$ kubectl rollout undo deployment/nginx-deployment
deployment "nginx-deployment" rolled back
</code></pre>

<p>Or you can rollback to a specific version:</p>

<pre><code>$ kubectl rollout undo deployment/nginx-deployment --to-revision=2
deployment "nginx-deployment" rolled back
</code></pre>

<p>For more information, please read the part of Kubernetes documentation related to <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">Deployment</a></p>
