question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rolling update image for multi container pod

See original GitHub issue

Is there any way to do a rolling update on the Docker image for a multi-container pod?

I was looking at FullExample.java in the tests where it does a rolling update at https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/FullExample.java#L146-L153.

However, there is no way shown to do an update for a multi container pod. From my understanding, the way to do this would be to:

  • Read the entire pod spec first (store it in an object)
  • Update the spec with the new image (find container by name)
  • Do a rolling update withNewSpec
PodSpec podSpec = client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").get().getSpec().getTemplate().getSpec();

List<Container> containers = podSpec.getContainers();
/* Logic to iterate, find container by name and update the image comes here.. */

client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller")
.rolling()
.edit().
editSpec().
editTemplate().
withNewSpecLike(podSpec)
.endSpec()
.endTemplate()
.endSpec()
.done();

Is there a better way to do this? For example,

client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller")
.rolling()
.updateImageForContainerName("nginx", "container-name");

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
iocanelcommented, Jan 20, 2016

@parikhyash: a slightly more elegant yet powerful approach would be to use something like:

client.replicationControllers().withName("name").rolling().edit().accept(new Visitor<ContainerBuilder>() {
  @Override
  public void visit(ContainerBuilder o) {
    o.withImage("myImage");
  }
});

This is a pure visitor pattern implementation. The visit method will be called for every single nested visitor in the structure. In the example above we are explicit that we are interested in container builders, so it will be called just for the nested container builder.

If you have multiple containers in the structure, it will visit all of them, so you may want to wrap the statement in an if clause.

The benefit if not obvious, is that it allows you to write code that is decoupled from the internal structure and is also boilerplate free.

0reactions
sumangit789commented, Jun 4, 2018

@parikhyash, may i please know , any blog posted on this issue? @iocanel,is the same can be done using client.extensions().replicaset()?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I update container image in a multi container pod
I am running a pod that has three containers. need to update the image of one of the container without doing a rolling...
Read more >
Performing a Rolling Update - Kubernetes
Rolling updates allow Deployments' update to take place with zero downtime by incrementally updating Pods instances with new ones.
Read more >
Live Update Multiple Containers Per Pod - Tilt Blog
10.0, you can use Live Update on as many containers per pod as you want! This feature didn't change much on the surface...
Read more >
Rolling Updates - Kubernetes
A rolling update applies changes to the configuration of pods being managed by a ... Specifying --image with multi-container pods returns an error....
Read more >
Performing rolling updates | Google Kubernetes Engine (GKE)
You can perform a rolling update to update the images, configuration, labels, annotations, and resource limits/requests of the workloads in your clusters.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found