gpt4 book ai didi

java - 在GKE集群中运行的Java应用程序如何以编程方式应用yaml文件?

转载 作者:行者123 更新时间:2023-12-02 12:28:12 25 4
gpt4 key购买 nike

我在Google Kubernetes Engine集群上部署了Java应用程序。如何使该应用程序以编程方式应用Yaml?等同于

kubectl apply -f deployment.yaml

我遇到了这个客户端库,但是找不到说明如何实现它的文档的一部分。 https://github.com/googleapis/google-api-java-client-services/tree/master/clients/google-api-services-container/v1

编辑:

感谢Guillaume和Mickey的指导。我尝试了 Kubernetes Java Client library,但获得了“禁止”。请参见下面的代码和响应:

    @RequestMapping(value = "/list-pods", method = GET, produces = TEXT_PLAIN_VALUE)
public String listPods() throws Exception {
KubeConfig.registerAuthenticator(new GCPAuthenticator());
final CoreV1Api api = new CoreV1Api(Config.defaultClient());
V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
StringBuilder builder = new StringBuilder("Pods: \n\n");
for (V1Pod item : list.getItems()) builder.append(item.getMetadata().getName());
return builder.toString();
}

这是抛出的异常:
2020-04-10 07:52:46.655 ERROR 1 --- [nio-8080-exec-7] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is io.kubernetes.client.ApiException: Forbidden] with root cause

io.kubernetes.client.ApiException: Forbidden
at io.kubernetes.client.ApiClient.handleResponse(ApiClient.java:886) ~[client-java-5.0.0.jar!/:na]
at io.kubernetes.client.ApiClient.execute(ApiClient.java:802) ~[client-java-5.0.0.jar!/:na]
at io.kubernetes.client.apis.CoreV1Api.listPodForAllNamespacesWithHttpInfo(CoreV1Api.java:18720) ~[client-java-api-5.0.0.jar!/:na]
at io.kubernetes.client.apis.CoreV1Api.listPodForAllNamespaces(CoreV1Api.java:18698) ~[client-java-api-5.0.0.jar!/:na]
at com.ngserve.clapps.ws.WS.listPods(WS.java:53) ~[classes!/:0.0.1-SNAPSHOT]

最佳答案

我终于按照FL3SH的建议配置了必需的rbac使其工作了。 https://kubernetes.io/docs/reference/access-authn-authz/rbac/

关于java - 在GKE集群中运行的Java应用程序如何以编程方式应用yaml文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61107200/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com