安装前准备
确保本地已经安装并启动好了Docker Desktop
拉取k8s镜像(如果本地网络好可以正常拉取到k8s官方镜像,可以跳过这一步)
克隆git仓库到本地
git clone https://github.com/gotok8s/k8s-docker-desktop-for-mac.git
进入项目目录,执行
./load_images.sh
部署k8s
进入Docker Decktop
的设置页面,勾选Kubernetes
设置页的配置,点击右下角的Apply & Restart
按钮,等待k8s完成部署
完成以后可以验证一下部署状态
kubectl cluster-info
kubectl get nodes
kubectl describe node
安装k8s Dashboard
应用推荐配置,这里需要注意修改v2.6.0
为兼容上面安装的kubelet的版本,具体可查看https://github.com/kubernetes/dashboard/releases
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.0/aio/deploy/recommended.yaml
获取登录token
开启代理并且设置代理端口为8001
kubectl proxy --port=8001
打开新的命令窗口,执行
获取token不带参数
curl 'http://127.0.0.1:8001/api/v1/namespaces/kube-system/serviceaccounts/kubernetes-dashboard/token' -H "Content-Type:application/json" -X POST -d '{}'
获取token带参数
curl 'http://127.0.0.1:8001/api/v1/namespaces/kube-system/serviceaccounts/kubernetes-dashboard/token' -H "Content-Type:application/json" -X POST -d '{"kind":"TokenRequest","apiVersion":"authentication.k8s.io/v1","metadata":{"name":"kubernetes-dashboard","namespace":"kube-system"},"spec":{"audiences":["https://kubernetes.default.svc.cluster.local"],"expirationSeconds":7600}}'
登录k8s Dashboard
复制上一步返回的token信息,浏览器访问如下地址,填入token即可登录
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/#/login