部署dashboard

wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.7.0/aio/deploy/recommended.yaml

创建sa、clusterrolebing、secret

kubectl create serviceaccount dashboard -n kubernetes-dashboard
kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kubernetes-dashboard:dashboard

token登录

kubectl -n kubernetes-dashboard create token dashboard

kubeconfig登录

kubectl apply -f-
apiVersion: v1
kind: Secret
metadata:
  name: dashboard
  namespace: kubernetes-dashboard
  annotations:
    kubernetes.io/service-account.name: "dashboard"
type: kubernetes.io/service-account-token
kubectl describe secrets -n kubernetes-dashboard dashboard
cp ~/.kube/config ~/kubeconfig
vim kubeconfig
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: xxxx
    server: https://xx.xx.xx.xx:6443
  name: kubernetes
contexts:
- context:
    cluster: kubernetes
    user: kubernetes-admin
  name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
  user:
    client-certificate-data: xxxx
    client-key-data: xxxx
    token: 新增token