如何使用用户名和密码对 Kubernetes kubectl 进行身份验证?

How do I authenticate with Kubernetes kubectl using a username and password?

我有用户名和密码,如何使用它们对 kubectl 进行身份验证?

我要执行哪个命令 运行?

我已经通读了:https://kubernetes.io/docs/reference/access-authn-authz/authorization/ and https://kubernetes.io/docs/reference/access-authn-authz/authentication/虽然在该案例中找不到任何相关信息。


kubectl config set-credentials cluster-admin --username=admin --password=uXFGweU9l35qcif

https://kubernetes-v1-4.github.io/docs/user-guide/kubectl/kubectl_config_set-credentials/


以上似乎不起作用: kubectl 获取 pods<br> 来自服务器的错误(禁止):pods 被禁止:用户 "client" 无法在命名空间 "default" 中列出 pods:未知用户 "client"

Kubernetes 提供了许多不同的身份验证机制。直接向集群提供用户名和密码(而不是使用 OIDC 提供商)将表明您正在使用基本身份验证,这并不是许多版本的默认选项。

假设集群支持基本身份验证,您列出的语法是正确的。

您看到的错误与 here 类似,这可能表明您正在使用的集群当前不支持您正在使用的身份验证方法。

关于您正在使用的 Kubernetes 发行版和版本的更多信息可以更轻松地提供更好的答案,因为 k8s 处理身份验证的方式多种多样。

您应该为验证用户设置一个组。

示例:

password1,user1,userid1,system:masters

密码2、用户2、用户id2

参考:

"Use a credential with the system:masters group, which is bound to the cluster-admin super-user role by the default bindings." https://kubernetes.io/docs/reference/access-authn-authz/rbac/