簡體   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