Kubernetes java-api update container image

12/3/2015

I'm trying to automate deployment of test builds in CI with Gradle and the Fabric8 Java kubernetes-client.

I'm trying to find the right syntax to update the RC with the new Docker image tag (not :latest).

Something like...

client.replacationControllers()
      .inNamespace('default')
      .withName('mycirc')
      .edit()
      .editSpec()
      .editTemplate()
        .editSpec()
          .withContainer('mycontainername')
            .withImage('myimage:newtag')
          .endContainer()   // <--- Not sure how to do this previous line
        .endSpec()
      .endTemplate()
      .endSpec()
      .done()

Can we update containers without having to totally delete and rebuild it?

-- hugheba
api
client
fabric8
java
kubernetes

2 Answers

6/5/2018

You can also do rolling-update on replica-set by following code

    private static void updateRc(KubernetesClient client){
        System.out.println("updating rollinh");
       // client.replicationControllers().inNamespace("default").withName("my-nginx").rolling().updateImage("nginx:latest");
        client.extensions().replicaSets().inNamespace("default").withName("fgrg-73-nginxcontainer1-74-97775d4d8").rolling().updateImage("nginx:latest");
        System.out.println("done");
    }
-- Rishi Anand
Source: StackOverflow

2/2/2016

There's an example of updating an image here: https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-examples/src/main/java/io/fabric8/kubernetes/examples/FullExample.java#L136

            // Update the RC - change the image to apache
            client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").edit().editSpec().editTemplate().withNewSpec()
                    .addNewContainer().withName("nginx").withImage("httpd")
                    .addNewPort().withContainerPort(80).endPort()
                    .endContainer()
                    .endSpec()
                    .endTemplate()
                    .endSpec().done();

Though as was pointed out in the comments, this probably doesn't update the pods immediately, unless the client is doing it.

It looks like the client supports rolling update, as well, which will update the pods: client.replicationControllers().inNamespace("thisisatest").withName("nginx-controller").rolling().updateImage("nginx");

-- briangrant
Source: StackOverflow