在docker desktop中一键启动k8s环境很简单。
下面介绍如何启动dashboard,dashboard仪表盘是新手学习k8s至关重要的一个工具。
1、配置控制台
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml
2、开启 API Server 访问代理
kubectl proxy
3、通过如下 URL 访问 Kubernetes dashboard
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
4、授权kube-system
默认服务账号
kubectl apply -f kube-system-default.yaml
kube-system-default.yaml:
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata:name: kube-system-defaultlabels:k8s-app: kube-system roleRef:apiGroup: rbac.authorization.k8s.iokind: ClusterRolename: cluster-admin subjects:- kind: ServiceAccountname: defaultnamespace: kube-system---apiVersion: v1 kind: Secret metadata:name: defaultnamespace: kube-systemlabels:k8s-app: kube-systemannotations:kubernetes.io/service-account.name: default type: kubernetes.io/service-account-token
5、获取token
TOKEN=$(kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}')
kubectl config set-credentials docker-desktop --token="${TOKEN}"
echo $TOKEN
6、登录dashboard