修改kubeconfig后发现执行kubectl命令出现错误

kubectl get pod -A
error: You must be logged in to the server (Unauthorized)

1、kubectl config view查看全部配置

apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://127.0.0.1:16443
  name: microk8s-cluster
contexts:
- context:
    cluster: microk8s-cluster
    user: admin
  name: microk8s
current-context: microk8s
kind: Config
preferences: {}
users:
- name: admin
  user:
    password: password
    username: username
    

2、sudo microk8s.config 查看默认配置

kind: Config
preferences: {}
users:
- name: admin
  user:
    token:VTUmtJN0p0cm1ab01aTThoUWgKNkx0c3ZjRllhN3JrQURZdUFpcFc3Zj

3、用microk8s.config里的token替换掉name和password即可

kubectl config set-credentials admin --token=VTUmtJN0p0cm1ab01aTThoUWgKNkx0c3ZjRllhN3JrQURZdUFpcFc3Zj

在次执行kubectl get node没有报错,问题解决。

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐