为什么将"kubectl"与模拟("--as=")一起使用会导致错误:"The connection to the server localhost:8080 was refused"?



为什么在只配置了default服务帐户的主机上,将kubectl与模拟--as=一起使用会导致"拒绝连接到服务器localhost:8080"?

我已将kubectl下载到只配置了default服务帐户的主机上。如果我试图模拟任何用户,例如system:anonymous,将返回以下错误消息:"与服务器localhost:8080的连接被拒绝"。

我可以通过使用kubectl proxy --port=8080启动本地代理来解决这个问题,但是,我希望避免这种情况。

为什么kubectl在使用模拟(--as=(时会尝试连接到localhost:8080

kube@ctf1-k8s-deploy1-545977f47-g9dpl:~$ kubectl config view
apiVersion: v1
clusters: null
contexts: null
current-context: ""
kind: Config
preferences: {}
users: null
kube@ctf1-k8s-deploy1-545977f47-g9dpl:~$ ls /var/run/secrets/kubernetes.io/serviceaccount/
ca.crt  namespace  token
kube@ctf1-k8s-deploy1-545977f47-g9dpl:~$ kubectl auth can-i --list --as=system:anonymous
The connection to the server localhost:8080 was refused - did you specify the right host or port?

clusters需要有Kubernetes API服务器的主机和端口。

clusters:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://API_SERVER_HOST:PORT

编辑:

--as作为参数添加到kubectl auth can-i时,kubectl不再使用集群内配置,这就是为什么它引用localhost:8080而不是正确的API服务器IP。

目前,kubectl有一个问题,任何客户端配置覆盖标志(例如--as、--request timeout…(都会禁用自动回退到集群内配置。

请参阅Kubernetes Github问题

最新更新