
屏幕快照 2020-05-28 上午11.00.04.png
1、安装 snap
如果 ubuntu 上没有 snap , 需要先安装 snap (ubuntu 18 已自带 snap)。 另外如果系统是 ubuntu 14,建议先升级到 16 或 18。
国内snap加速可以用 腾讯云 (https://mirrors.cloud.tencent.com/help/ubuntu.html
)的源,很快!
1 2 3 4 | $ sudo apt update $ sudo apt install snapd ... $ sudo systemctl restart snapd |
2、安装 microk8s
1 | $ sudo snap install microk8s --classic |
详细的权限设置可以 参看 microk8s 官网
https://microk8s.io/docs
出于简化的目的,我们可以用 kubectl 替代 microk8s.kubectl
1 | $ sudo snap alias microk8s.kubectl kubectl |
3、检查 microk8s 状态
1 | $ sudo microk8s.inspect |
如果报了一些警告,请按照警告进行修改
1 2 3 4 5 6 7 8 9 | ... WARNING: IPtables FORWARD policy is DROP. Consider enabling traffic forwarding with: sudo iptables -P FORWARD ACCEPT The change can be made persistent with: sudo apt-get install iptables-persistent WARNING: Docker is installed. Add the following lines to /etc/docker/daemon.json: { "insecure-registries" : ["localhost:32000"] } and then restart docker with: sudo systemctl restart docker |
4、配置 microk8s 内置 docker 的 registry.mirrors
编辑 /var/snap/microk8s/current/args/containerd-template.toml 文件
在 endpoint 添加 新的 国内 registry.mirrors , 如 "https://docker.mirrors.ustc.edu.cn"
1 2 3 4 5 6 7 8 | ... [plugins.cri.registry] [plugins.cri.registry.mirrors] [plugins.cri.registry.mirrors."docker.io"] endpoint = [ "https://docker.mirrors.ustc.edu.cn", "https://registry-1.docker.io" ] |
然后,先停止 microk8s,再启动 microk8s
1 2 | $ sudo microk8s stop $ sudo microk8s start |
5、启动 microk8s dns
先安装一个 最必要 的 dns 插件
1 | $ sudo microk8s.enable dns |
观察启动的情况
1 2 3 4 | $ sudo kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-87fcbc976-pckpj 0/1 ContainerCreating 0 60m |
会发现 coredns 一直处于 ContainerCreating 状态, 查看 pods 情况
1 2 3 4 5 6 | $ sudo kubectl describe pods coredns-87fcbc976-pckpj -n kube-system ... Warning FailedCreatePodSandBox 58s kubelet, doudong Failed to create pod sandbox: rpc error: code = Unknown desc = failed to get sandbox image "k8s.gcr.io/pause:3.1": failed to pull image "k8s.gcr.io/pause:3.1": failed to resolve image "k8s.gcr.io/pause:3.1": no available registry endpoint: failed to do request: Head "https://k8s.gcr.io/v2/pause/manifests/3.1": dial tcp 64.233.189.82:443: i/o timeout |
发现由于某种原因 无法获取 指定镜像 k8s.gcr.io/pause:3.1
6、手动下载镜像
步骤如下:
6.1、下载docker hub 上的 镜像
1 | $ sudo docker pull mirrorgooglecontainers/pause:3.1 |
6.2、修改镜像 tag
1 | $ sudo docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1 |
6.3、保存镜像为 tar 文件
1 | $ sudo docker save k8s.gcr.io/pause > pause.tar |
6.4、将tar 文件上传到 microk8s 的 docker 中
1 2 | $ sudo microk8s.ctr image import pause.tar unpacking k8s.gcr.io/pause:3.1 (sha256:3efe4ff64c93123e1217b0ad6d23b4c87a1fc2109afeff55d2f27d70c55d8f73)...done |
6.5、过一下,再观察 coredns 状态,会发现已经成功的 running (如果还不成功,则继续 通过 kubectl describe pods ... 观察 pods 的状态,如果有下载不成功的镜像,再如法炮制一遍。
6.6 如果 coredns 成功启动,会显示如下
1 2 3 | $ sudo kubectl get pods -n kube-system NAME READY STATUS RESTARTS AGE coredns-87fcbc976-pckpj 1/1 Running 0 90m |
7、microk8s 启动 istio
先用 microk8s 下载 istio
1 2 3 4 5 6 7 | $ sudo microk8s.enable istio Enabling Istio Fetching istioctl version v1.3.4. % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 635 100 635 0 0 292 0 0:00:02 0:00:02 --:--:-- 292 7 36.3M 7 2667k 0 0 23557 0 0:26:59 0:01:55 0:25:04 25609 |
下载速度取决于你的网络情况,但是成功下载是没有问题的。
安装完成后,查看 istio 容器情况
1 | $ sudo kubectl get pods -n istio-system |
由于要拉取镜像,所以全部容器启动完成,需要一些时间,这也取决于你的网络状况。
全部正常启动后的情况如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | NAME READY STATUS RESTARTS AGE grafana-78758665bb-5vp4j 1/1 Running 0 9h istio-citadel-799bf7ddb9-2v2mm 1/1 Running 1 9h istio-egressgateway-78d46d89bf-w44bp 1/1 Running 1 9h istio-galley-cbf67694f-4lfnp 1/1 Running 1 9h istio-grafana-post-install-1.3.4-8wpbm 0/1 Completed 0 9h istio-ingressgateway-5d86f5f694-2fhnl 1/1 Running 1 9h istio-pilot-5867df8f85-hjj69 2/2 Running 2 9h istio-policy-54d878f564-q6p42 2/2 Running 8 9h istio-security-post-install-1.3.4-d2bw2 0/1 Completed 0 9h istio-sidecar-injector-66bc6cf76b-4nzbc 1/1 Running 2 9h istio-telemetry-647b9c8ccd-mzs4v 2/2 Running 9 9h istio-tracing-6cb4f885d4-5tv7g 1/1 Running 1 9h kiali-68d8fc4d54-p8q8n 1/1 Running 1 9h prometheus-5c8fb8f746-jk89s 1/1 Running 1 9h |
总结
通过 microk8s 安装 istio 过程中最重要的其实是在 第5步 的 安装 dns 插件, 只要装好了 dns 插件(需要手动 或 通过代理安装),后续的安装工作基本上都能顺利完成。