之前在 Ubuntu Server 18.04上部署 minikube
启动指令 minikube start --image-mirror-country=cn
它会自动设置为阿里云镜像
直接会有提示
... Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers ...
但是在 Ubuntu Server 20.04 上死活不行,所以,很慢很慢,甚至就卡死了!
为了让他能够跑起来,直接 Docker pull
docker pull registry.cn-hangzhou.aliyuncs.com/k8s-minikube/kicbase docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28 gcr.io/k8s-minikube/kicbase:v0.0.28
起来是起来了,但是,还是很慢!
主要是在 Pulling base image 之后,那个 index…卡住!
...
Pulling base image ...
> index.docker.io/kicbase/sta...: 0 B [______________________] ?% ? p/s 50s
> index.docker.io/kicbase/sta...: 46.27 MiB / 355.78 MiB 13.01% 1.92 MiB p
> index.docker.io/kicbase/sta...: 0 B [_____________________] ?% ? p/s 4m9s
...
对比 2 个服务器上的 minikube logs 和 config
$ minikube logs |grep config.json
I1125 14:13:57.333886 14781 profile.go:147] Saving config to /home/dhbm/.minikube/profiles/minikube/config.json ...
I1125 14:13:59.187657 14781 profile.go:147] Saving config to /home/dhbm/.minikube/profiles/minikube/config.json ...
可以看到,在 start 的时候会将本次的设置保存到 config.json
在 ubuntu 20.04 上是这样的
$ cat /home/dhbm/.minikube/profiles/minikube/config.json
...
{
"Name": "minikube",
"KeepContext": false,
"EmbedCerts": false,
"MinikubeISO": "",
"KicBaseImage": "docker.io/kicbase/stable:v0.0.28",
而在 ubuntu 18.04 上是这样的
$ cat /home/dhbm/.minikube/profiles/minikube/config.json
…
{
“Name”: “minikube”,
“KeepContext”: false,
“EmbedCerts”: false,
“MinikubeISO”: “”,
“KicBaseImage”: “registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28@sha256:4780f1897569d2bf77aafb3d133a08d42b4fe61127f06fcfc90c2c5d902d893c”,
可见, 20.04 上config 并没有改变 KicBaseImage 配置
将和国内镜像有关的配置全部加到指令中,终于快起来了!如下!
命令
minikube start --image-mirror-country=cn
不行就换
minikube start --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --base-image='registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28'
总有一个会适合你!
$ minikube start --image-mirror-country=‘cn’ --image-repository=‘registry.cn-hangzhou.aliyuncs.com/google_containers’ --base-image=‘registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28’
minikube v1.24.0 on Ubuntu 20.04 (vbox/amd64)
✨ Automatically selected the docker driver. Other choices: ssh, none
✅ Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
Starting control plane node minikube in cluster minikube
Pulling base image ...
Creating docker container (CPUs=2, Memory=2200MB) ...
Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
Verifying Kubernetes components...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
Enabled addons: default-storageclass, storage-provisioner
Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
运行成功之后,再来查看config
$ cat /home/dhbm/.minikube/profiles/minikube/config.json
"Name": "minikube",
...
"KicBaseImage": "registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28",
...
"KubernetesConfig": {
"KubernetesVersion": "v1.22.3",
...
"ImageRepository": "registry.cn-hangzhou.aliyuncs.com/google_containers",
...
},
...
$minikube stop 之后,config.json 依然存在!
重新start ,即使使用最简单的方式 $minikube start ,速度一样会比较快!
说明之前 N 次重复,因为已经保存了相关设置
$ minikube delete 之后,config.json 不存在了!
这次再使用最简单的方式 $minikube start ,就很慢很慢了!
改成带选项的命令,就会变化,并且变快了!
所以,解决 start 慢的方法是使用阿里云镜像,简单粗暴的方式是:
minikube delete
docker pull registry.cn-hangzhou.aliyuncs.com/k8s-minikube/kicbase
docker tag registry.cn-hangzhou.aliyuncs.com/k8s-minikube/kicbase gcr.io/k8s-minikube/kicbase:v0.0.28
minikube start --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --base-image='registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28'
只要成功了,本次的那些参数就会保存到 config ,除非删除 Cluster!
为了方便,设置alias
$ sudo vim .bashrc
加上 2 条 alias
# 20211125
alias minikube.cn="minikube start --image-mirror-country='cn' --image-repository='registry.cn-hangzhou.aliyuncs.com/google_containers' --base-image='registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28'"
alias kubectl="minikube kubectl --"
启动生效
$ source .bashrc
$ alias |grep mini
alias kubectl='minikube kubectl --'
alias minikube.cn='minikube start --image-mirror-country='\''cn'\'' --image-repository='\''registry.cn-hangzhou.aliyuncs.com/google_containers'\'' --base-image='\''registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28'\'''
后续关机重启后,全部使用 minikube.cn 指令启动
不能开启 swap ,错误如下
…
stderr:
[WARNING Swap]: running with swap on is not supported. Please disable swap
[WARNING SystemVerification]: failed to parse kernel config: unable to load kernel module: “configs”, output: “modprobe: FATAL: Module configs not found in directory /lib/modules/5.11.0-41-generic\n”, err: exit status 1
关闭 swap
swapoff -a
vim /etc/fstab
注释掉 swap 那行
按照以上方式的命令,出现更奇怪的错误
一大堆 output: invalid reference format
minikube start --image-mirror-country=‘cn’ --image-repository=‘registry.cn-hangzhou.aliyuncs.com/google_containers’ --base-image=‘registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.28’
stderr:
[WARNING SystemVerification]: failed to parse kernel config: unable to load kernel module: "configs", output: "modprobe: FATAL: Module configs not found in directory /lib/modules/5.11.0-41-generic\n", err: exit status 1
[WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/kube-apiserver:v1.22.3: output: invalid reference format
, error: exit status 1
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/kube-controller-manager:v1.22.3: output: invalid reference format
, error: exit status 1
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/kube-scheduler:v1.22.3: output: invalid reference format
, error: exit status 1
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/kube-proxy:v1.22.3: output: invalid reference format
, error: exit status 1
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/pause:3.5: output: invalid reference format
, error: exit status 1
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/etcd:3.5.0-0: output: invalid reference format
, error: exit status 1
[ERROR ImagePull]: failed to pull image ‘registry.cn-hangzhou.aliyuncs.com/google_containers’/coredns:v1.8.4: output: invalid reference format
, error: exit status 1
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher
最后居然又换回去简单的指定国家就好了,cn 不能带引号!
$ minikube start --image-mirror-country=cn
minikube v1.24.0 on Ubuntu 20.04 (vbox/amd64)
✨ Automatically selected the docker driver. Other choices: none, ssh
✅ Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
Starting control plane node minikube in cluster minikube
Pulling base image ...
> registry.cn-hangzhou.aliyun...: 355.78 MiB / 355.78 MiB 100.00% 584.67 K
Creating docker container (CPUs=2, Memory=2200MB) ...
Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
Verifying Kubernetes components...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
Enabled addons: default-storageclass, storage-provisioner
Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default