Mac上使用Docker Desktop启动Kubernetes

正常启动会一直显示 starting,无法启动成功

主要是因为启动所需要的镜像无法正常下载成功

下图为 k8s 所需要的镜像

 

 

 

 

下载镜像

将仓库克隆下来:

git clone https://github.com/hummerstudio/k8s-docker-desktop-for-mac.git

然后看一下文件image_list上的版本跟自己安装的版本能不能对得上,建议直接更新Docker Desktop为最新版本。

cat image_list

 

 没有问题就可以执行脚本拉取相关镜像

./load_images.sh

等待下载完成就可以了,然后 k8s 就可以正常启动了

 

安装Dashboard

host 增加

# Kubernetes
127.0.0.1 kubernetes.docker.internal

Dashboard并不是必须的,它可以方便我们查看和操作,建议还是安装。

kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.6.1/aio/deploy/recommended.yaml

启用 Dashboard

kubectl proxy

 建议使用下面命令启动,不然会一直占着终端:

nohup kubectl proxy >/dev/null &

也可以指定url的ip端口:

kubectl proxy --address="192.168.0.101" -p 8001 --accept-hosts='^*$'

这样就使用下面的url来打开dashboard:

http://192.168.0.101:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

 

 

kubectl 会使得 Dashboard 可以通过 http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/ 访问。

UI 只能 通过执行这条命令的机器进行访问。更多选项参见 kubectl proxy --help

 

打开dashboard登录界面如下,有一个“跳过”按钮可以跳过登录:

 

 

如果不想设置--enable-skip-login,想用token来登录,那么可以通过以下命令来获取token

kubectl get secret -n kube-system | grep deployment-controller-token

kubectl describe secret deployment-controller-token-8467t -n kube-system

 

或者输入命令直接获取 token

kubectl -n kube-system describe secret default| awk '$1=="token:"{print $2}'

  

将token复制到登录框即可。

这种登录方式,每次都需要输入token,除非浏览器有缓存。

 

 配置一个拥有完整权限的token

创建一个dashboard管理用户

kubectl create serviceaccount dashboard-admin -n kube-system

绑定用户为集群管理用户

kubectl create clusterrolebinding dashboard-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:dashboard-admin

查看 token

kubectl describe -n=kube-system  secret dashboard-admin

登录后就可以看到具体的界面了

 

 

 

 

 

参考资料:

https://kubernetes.io/zh-cn/docs/tasks/access-application-cluster/web-ui-dashboard/

https://blog.wayneshao.com/posts/10324.html

https://juejin.cn/post/6845166891023990798

https://www.cnblogs.com/tylerzhou/p/11117956.html 

posted @ 2022-10-10 01:44  Ryan_zheng  阅读(753)  评论(0编辑  收藏  举报