这是关于 Kubernetes Java 客户端版本 0.2 的。我猜想在 Java API 中使用基本身份验证的方法就是这样做
ApiClient client = Config.fromUserPassword( "https://....:6443", "user", "password", false );
Configuration.setDefaultApiClient( client );
CoreV1Api api = new CoreV1Api();
// Make api call like
api.listNode(...)
但是上面的代码总是返回 403 Forbidden。从响应消息来看,请求中似乎没有使用用户/密码。
{"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"nodes is forbidden: User \"system:anonymous\" cannot list nodes at the cluster scope","reason":"Forbidden","details":{"kind":"nodes"},"code":403}
我还对代码进行了一些调试,我可能会回答我自己的问题,但看起来在 CoreV1Api 的方法中,它从不添加基本身份验证作为身份验证方法,而仅使用 BearerToken。是否支持基本身份验证或者我应该使用其他 API 类?
最佳答案
许多 kubernetes 集群不设置基本身份验证,仅设置不记名 token 身份验证。您确定您的集群配置了基本身份验证吗?
https://kubernetes.io/docs/admin/authentication/#static-password-file
关于java - Kubernetes Java API 不使用提供的用户名密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48217465/