解决microk8s 报错error: You must be logged in to the server (Unauthorized)

After modifying kubeconfig, an error occurred when executing the kubectl command

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

1. kubectl config view to view all configurations

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 to view the default configuration

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

3. Replace the name and password with the token in microk8s.config

kubectl config set-credentials admin --token=VTUmtJN0p0cm1ab01aTThoUWgKNkx0c3ZjRllhN3JrQURZdUFpcFc3Zj

Executing kubectl get node again did not report an error, and the problem was solved.

Guess you like

Origin blog.csdn.net/weixin_45000409/article/details/127392946