欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Ubuntu 20.04部署minikube配置不上阿里云的minikube镜像

程序员文章站 2022-07-14 16:22:28
...
  1. 之前在 Ubuntu Server 18.04上部署 minikube

    Ubuntu 1804 部署minikube

    启动指令 minikube start --image-mirror-country=cn
    它会自动设置为阿里云镜像

    直接会有提示

     ...
     Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
      ...
    

    但是在 Ubuntu Server 20.04 上死活不行,所以,很慢很慢,甚至就卡死了!

  2. 为了让他能够跑起来,直接 Docker pull

    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

    起来是起来了,但是,还是很慢!
    主要是在 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
         ...
    
  3. 对比 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:[email protected]:4780f1897569d2bf77aafb3d133a08d42b4fe61127f06fcfc90c2c5d902d893c”,

    可见, 20.04 上config 并没有改变 KicBaseImage 配置

  4. 将和国内镜像有关的配置全部加到指令中,终于快起来了!如下!

    $ 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
    
  5. 运行成功之后,再来查看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 ,就很慢很慢了!

    改成带选项的命令,就会变化,并且变快了!

  6. 所以,解决 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!

  7. 为了方便,设置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 指令启动