2018刚开始,Docker团队就献出了一份大礼:Docker for Mac 内置支持Kubernetes了,而且通过Edge版本的reset按钮,可以快速恢复原始安装状态,对于Docker和Kubernetes的开发简直是太方便了。这里介绍将可视化面板也安装上去的方法。

开启 Kubernetes

从Docker官方站点下载并安装Docker for Mac
我自己用的是该版本(18.09.0)

docker for mac 安装 kubernetes、kubernetes dashboard

运行下列脚本可以从阿里云镜像服务下载Kubernetes安装所需Docker镜像,然后切换到docker 对应的分支

git clone https://github.com/AliyunContainerService/k8s-for-docker-desktop
cd k8s-for-docker-desktop
git checkout 18.09

加载镜像

./load_images.sh

在Docker for Mac中开启 Kubernetes,等待如下消息

docker for mac 安装 kubernetes、kubernetes dashboard

等待几分钟后,出现如下消息

docker for mac 安装 kubernetes、kubernetes dashboard

成功后就如第一张图了,可以看到docker和k8s对应的版本了

docker for mac 安装 kubernetes、kubernetes dashboard

你可能已经包含若干不同的 Kubernetes context 配置,可以通过如下命令切换到 docker-for-desktop

kubectl config use-context docker-for-desktop

验证 Kubernetes 安装

➜  ~ kubectl cluster-info
Kubernetes master is running at https://localhost:6443
KubeDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
➜  ~ kubectl get nodes
NAME                 STATUS    ROLES     AGE       VERSION
docker-for-desktop   Ready     master    2h        v1.10.3
➜  ~

部署 Kubernetes dashboard ,开启API Server的本地监听端口

➜  ~ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v1.10.1/src/deploy/recommended/kubernetes-dashboard.yaml
secret "kubernetes-dashboard-certs" created
serviceaccount "kubernetes-dashboard" created
role.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" created
rolebinding.rbac.authorization.k8s.io "kubernetes-dashboard-minimal" created
deployment.apps "kubernetes-dashboard" created
service "kubernetes-dashboard" created
➜  ~ kubectl proxy
F0811 21:24:56.155415   12529 proxy.go:154] listen tcp 127.0.0.1:8001: bind: address already in use
➜  ~ sudo lsof -i:8001
Password:
COMMAND  PID     USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
kubectl 3958 diycoder    3u  IPv4 0x8104a8ce68c3a563      0t0  TCP localhost:vcom-tunnel (LISTEN)
➜  ~ kill 3958
➜  ~ kubectl proxy
Starting to serve on 127.0.0.1:8001

之后打开浏览器访问

http://localhost:8001/api/v1/namespaces/kube-system/services/https:kubernetes-dashboard:/proxy/

获取令牌,然后登陆 kubernetes dashboard

docker for mac 安装 kubernetes、kubernetes dashboard

将 token 部分复制到登录页的 token 输入框,登陆即可

docker for mac 安装 kubernetes、kubernetes dashboard

docker for mac 安装 kubernetes、kubernetes dashboard

参考链接:

https://yq.aliyun.com/articles/508460
https://www.cnblogs.com/cag2050/p/10170130.html
https://github.com/kubernetes/dashboard