本篇内容:记录一下minikube安装过程中遇到的坑。
安装环境:minikube1.9.2 ,kubernetes:v1.18.0,os:CentOS Linux release 7.7.1908,Docker:19.03.8
由于国内不能直连gcr.io,通过minikube部署k8s时会报错。通过执行minikube start --help命令可以查看到,在国内使用minikube时需要我们在启动时(执行minikube start)添加以下配置项:
···
--image-mirror-country='': Country code of the image mirror to be used. Leave empty to use the global one. For
Chinese mainland users, set it to cn.
--image-repository='': Alternative image repository to pull docker images from. This can be used when you have
limited access to gcr.io. Set it to "auto" to let minikube decide one for you. For Chinese mainland users, you may use
local gcr.io mirrors such as registry.cn-hangzhou.aliyuncs.com/google_containers
--iso-url=[https://storage.googleapis.com/minikube/iso/minikube-v1.9.0.iso,https://github.com/kubernetes/minikube/releases/download/v1.9.0/minikube-v1.9.0.iso,https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.9.0.iso]:
Locations to fetch the minikube ISO from.
···
根据提示设置配置项,最终的启动命令如下:
minikube start --image-mirror-country='cn' \
--iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.9.0.iso \
--image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'
执行完上面的命令依然报错,提示无法下载镜像gcr.io/k8s-minikube/kicbase:v0.0.8,这是需要我们手动下载这个镜像到本地docker仓库(当然由于国内网络问题,直接下载是不行的,这时需要通过代理或者从其他机器下载下来在导入到宿主机中。该kicbase:v0.0.8版本的镜像包可以从这里下载: dGhpcyBpcyBhIGV4YW1wbGVodHRwczovL3Bhbi5iYWlkdS5jb20vcy8xQ09MNTM1T1ZKLWo4RmluYXQ2WHNfZyDmj5Dlj5bnoIHvvJpneW1h)
导入镜像包:$docker load -i kicbasev0.0.8.tar;
此时再次执行上面的minikube start命令,依然会报错,这里参考网友的解决方法https://listenerri.com/2020/04/07/minikube-%E5%90%AF%E5%8A%A8%E5%A4%B1%E8%B4%A5/
sudo vim /var/lib/docker/image/overlay2/repositories.json
在gcr.io/k8s-minikube/kicbase的信息中加入以下内容:
{"gcr.io/k8s-minikube/kicbase@sha256:2f3380ebf1bb0c75b0b47160fd4e61b7b8fef0f1f32f9def108d3eada50a7a81":"sha256:76e0495113c1fa67112825d33be526054eb0cdfacd2fea171f0107d23e84b1e1","gcr.io/k8s-minikube/kicbase:v0.0.8":"sha256:76e0495113c1fa67112825d33be526054eb0cdfacd2fea171f0107d23e84b1e1"}
需要注意两点:
1. 别忘了逗号(上面黄色部分最后一个字符);
2. 绿色部分内容是不固定的,需要根据实际情况配置。
修改完之后,执行命令sudo systemctl restart docker.service 以重启docker服务,然后再尝试执行启动命令即可成功启动。
minikube start --image-mirror-country='cn' \
--iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.9.0.iso \
--image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers'