Kubernetes java-api update container image
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");
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"); }