Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a set of pods running in kubernetes?

What is the preferred way of updating a set of pods (e.g. after making code changes & pushing underlying docker image to docker hub) controlled by a replication controller in kubernetes cluster?

I can see 2 ways:

  1. Deleting & re-creating replication controller manually
  2. Using kubectl rolling-update

With the rolling-update I have to change the replication controller name. Since I'm storing replication controller definition in YAML file and not generating it manually, having to change the file to push out a code update seems to bring about bad habits like alternating between 2 names for the replication controller (e.g. controllerA and controllerB) to avoid name conflict.

What is the better way?

like image 787
Madis Nõmme Avatar asked May 12 '15 07:05

Madis Nõmme


People also ask

How do I update my pods in Kubernetes?

If you have the rc file, you change any part of the pod using kubectl rolling-update -f rc_spec. yaml . You do still have to change the rc name and one of the selector fields (typically that would be a 'version' or 'deployment' field).

How do I update my Kubernetes code?

Updating an application You can use kubectl apply to update a resource by applying a new or updated configuration. Note: To update a resource with kubectl apply , the resource must be created using kubectl apply or kubectl create --save-config . Replace MANIFEST with the name of the manifest file.

What is update strategy in Kubernetes?

The rolling update strategy is a gradual process that allows you to update your Kubernetes system with only a minor effect on performance and no downtime. Rolling update strategy flowchart. In this strategy, the Deployment selects a Pod with the old programming, deactivates it, and creates an updated Pod to replace it.

How do I edit a deployment in Kubernetes?

Updating a Kubernetes Deployment You can edit a Deployment by changing the container image from one version to the other, decreasing or increasing the number of instances by changing the ReplicaSet value. etc. For example, the container image nginx we have been using in our exercises has many versions.


Video Answer


1 Answers

Update: kubectl rolling-update has been deprecated and the replacement command is kubectl rollout. Also note that since I wrote the original answer the Deployment resource has been added and is a better choice than ReplicaSets as the rolling update is performed server side instead of by the client.


You should use kubectl rolling-update. We recently added a feature to do a "simple rolling update" which will update the image in a replication controller without renaming it. It's the last example shown in the kubectl help rolling-update output:

// Update the pods of frontend by just changing the image, and keeping the old name
$ kubectl rolling-update frontend --image=image:v2

This command also supports recovery -- if you cancel your update and restart it later, it will resume from where it left off. Even though it creates a new replication controller behind the scenes, at the end of the update the new replication controller takes the name of the old replication controller so it appears as pure update rather than switching to an entirely new replication controller.

like image 60
Robert Bailey Avatar answered Sep 30 '22 20:09

Robert Bailey