繁体   English   中英

Kubernetes Java API更新容器映像

[英]Kubernetes java-api update container image

我正在尝试使用Gradle和Fabric8 Java kubernetes-client在CI中自动部署测试版本。

我正在尝试找到正确的语法,以使用新的Docker image标签更新RC(不是:latest)。

就像是...

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()

我们可以更新容器而不必完全删除并重建它吗?

这里有一个更新图像的示例: 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();

尽管正如评论中指出的那样,除非客户端正在这样做,否则这可能不会立即更新Pod。

客户端似乎也支持滚动更新,这将更新pod:client.replicationControllers()。inNamespace(“ thisisatest”)。withName(“ nginx-controller”)。rolling()。updateImage(“ nginx”) ;

您还可以通过以下代码对副本集进行滚动更新

  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"); } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM