我正在尝试使用用户名和密码在kubeconfig文件中添加新集群及其上下文,但失败了。下面是我用来设置上下文的命令。
kubectl config set-cluster lab101 --server=https://api-kube.example.com:8443 --insecure-skip-tls-verify --context=lab101
kubectl config set-credentials kubeadmin --username=kubeadmin --password=xxxxxxx --cluster=lab101
kubectl config set-context lab101 --cluster=lab101 --namespace=default --user=kubeadmin
kubectl config use-context lab101
日志:
GET https://api-kube.example.com:8443/api?timeout=32s 403 Forbidden in 19 milliseconds
I0422 11:37:31.741005 18972 round_trippers.go:411] Response Headers:
I0422 11:37:31.741005 18972 round_trippers.go:414] Cache-Control: no-cache, private
I0422 11:37:31.741005 18972 round_trippers.go:414] Content-Type: application/json
I0422 11:37:31.741005 18972 round_trippers.go:414] X-Content-Type-Options: nosniff
I0422 11:37:31.741005 18972 round_trippers.go:414] Content-Length: 188
I0422 11:37:31.741005 18972 round_trippers.go:414] Date: Wed, 22 Apr 2020 15:37:31 GMT
I0422 11:37:31.762977 18972 request.go:897] Response Body: {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"forbidden: User \"system:anonymous\" cannot get path \"/api\"","reason":"Forbidden","details":{},"code":403}
注意:如果我使用相同的用户,则密码oc login
可以正常工作。不明白为什么手动设置kubeconfig不能正常工作。
答案 0 :(得分:1)
OpenShift Kubernetes不太可能允许使用https://react-bootstrap.github.io/components/toasts/进行身份验证。 oc login
命令使用用户名和密码向username and password内部进行身份验证,以获取承载令牌,该令牌自动存储在kubectl使用的kubeconfig文件中。当您执行任何kubectl命令时,该令牌将用于与Kubernetes集群进行身份验证。
您可以通过oc config view
检查令牌。您可以获取令牌并使用kubectl config set-credentials kubeadmin --token=bearertoken
进行设置,它应该可以工作。
请参阅文档oAuth server。
或者,您也可以按照此文档here来获得不记名令牌。