<p>I am trying to understand how I should deploy containers with Kubernetes. I am new at this topic so at this moment I am testing all these ideas in a virtual machine.</p>

<p>I'm using Git, Jenkins, Docker, Docker Hub and Kubernetes.</p>

<p>Also, I have a Master node and only one Slave node.</p>

<p>I created a YAML deploy file to start the pod and create a new container.</p>

<pre class="lang-sh prettyprint-override"><code>kubectl apply -f deployment.yaml
</code></pre>

<p>Then I expose the deploy.</p>

<pre class="lang-sh prettyprint-override"><code>kubectl expose deployment my-app --type=LoadBalancer --name=my-app
</code></pre>

<p>YAML File for deployment:</p>

<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-app
  labels:
    app: app
spec:
  selector:
    matchLabels:
      app: app
      role: master
      tier: backend
  replicas: 1
  template:
    metadata:
      labels:
        app: app
        role: master
        tier: backend
    spec:
      containers:
      - name: appcontainer
        image: repository:1.0
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        ports:
        - containerPort: 8085
      imagePullSecrets:
      - name: regcred
</code></pre>

<p>Now that I have all working, for example, I give a new update on the image and I need to update this new image, for example, 1.0 to 1.1, on the deployment done. I need to know the proper way to do this action.</p>

<p>Because I think I'm doing it wrong like I'm trying to smash the image on the container created with the new image and I don't know if the proper way is deploying with a new YAML file and if Kubernetes builds a new container with that image and consequently kill the old deploy, but I don't know how I can do that if this the right thing to do.</p>

<p>The easiest way to <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#updating-a-deployment" rel="nofollow noreferrer">update a deployment</a> with new image will be to run:</p>

<pre><code>kubectl set image deployment/my-app appcontainer=repository:1.1 --record
</code></pre>

<p>This way it will first create a new pod(s) with newer version of image and once successfully deployed it will terminate old pod or pods depending on number of replicas you have specified in the <code>replicas</code> field.</p>

<p>You can check status of the update by running </p>

<pre><code>kubectl rollout status deployment.v1.apps/my-app
</code></pre>
