How do I redeploy everything in kubernetes after updating a dockerfile?

9/17/2017

I'm very new to kubernetes and all I want to do at this point is restart my cluster and have it run an updated dockerfile. I'm running kubernetes in google-cloud-platform by the way.

-- hermancain
docker
google-cloud-platform
kubernetes

3 Answers

5/24/2019

First get the values of replicas of running system

kubectl -n <namespace> get deployments
NAME              DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
pgadmin           1         1         1            1           227d
postgresql-db     1         1         1            1           231d

Please try to scale your deployment to 0 like

kubectl -n <namespace>  scale deployment <name_of_deployment> --replicas=0

then enable it again by scaling it back to previous value

kubectl -n <namespace>  scale deployment <name_of_deployment> --replicas=1

kubernetes will kill for you the old one and start a new container

-- matson kepson
Source: StackOverflow

7/8/2019

kubectl from version 1.15 should contain kubectl rollout restart (according to this comment https://github.com/kubernetes/kubernetes/issues/33664#issuecomment-497242094)

-- JakubKnejzlik
Source: StackOverflow

9/17/2017

You can use rolling update mechanism to update the service without outage which will update one pod at a time until the desired state match, and still your services are up and running. Of course we must have to update our containers inside the pod to protect our data and to get latest features out. Kubernetes makes it easy to roll out updates to your applications by modifying the deployments and managing them. It's major update time and we'll use easy way to tweak them.

Suppose you have front end, auth and back-end deployments and there is change into the auth or newer version, so you want to update auth deployment configuration file in which you could change its respective auth container image to newer version after building the new docker image and simply changing the image version in your .yaml file and apply as below

$ kubectl apply -f deployments/auth.yaml

Check that it succeed with the deployment describe command, you could see the rolling update strategy and figure out that right number of pods are always available. That uses the new replica set to ensure that we are running the latest version of auth container.

$ kubectl describe deployments auth

Once, the rolling update is complete, we can view the running pods for the auth service.

$ kubectl get pods

Check the time frame for which it is running. The new version of the auth pod has replaced the previous one. Once again check with the id of the new auth pod and verify. Updating deployment this way keeps us with a clean declarative approach to roll out changes to our application weather you have single or thousands of pods running.

-- mohan08p
Source: StackOverflow