美文网首页
macos docker 一直处于 kubernetes sta

macos docker 一直处于 kubernetes sta

作者: 中v中 | 来源:发表于2020-08-09 08:50 被阅读0次

    文章目录

    背景说明

    在macos上安装docker desktop最新的稳定版docker desktop 2.2.0.3 stable 时,发现kubernetes 一直处于starting状态,无法启动。在网上也找了些资料来解决,问题一直没有得到解决,因此将自己的解决方式记录下来,以帮助更多的人。
    
    

    版本信息

    1. os版本:macos catalina 10.15.4
    2. docer版本:docker desktop community 2.2.0.3 stable
    3. kubernetes版本:kubernetes v1.15.5
    在这里插入图片描述 docker版本号

    问题现象

    docker 菜单栏,kubernetes一直处于starting状态如下:


    docker desktop 菜单界面

    docker preferences配置界面,也一直在转圈,等待kubernetes启动完成,无法进行配置。


    docker preference界面

    docker troubleshoot界面状态:


    docker kubernetes troubleshoot界面

    尝试方案一 git下载K8s版本对应的镜像

    1. 打开docker desktop
      ~略
    2. 下载git代码 ~~ 实质就是拉拉k8s相关的镜像包
    git clone https://github.com/maguowei/k8s-docker-for-mac.git
    
    

    $ codeStations % git clone https://github.com/maguowei/k8s-docker-for-mac.git
    Cloning into ‘k8s-docker-for-mac’…
    remote: Enumerating objects: 7, done.
    remote: Counting objects: 100% (7/7), done.
    remote: Compressing objects: 100% (5/5), done.
    remote: Total 220 (delta 0), reused 4 (delta 0), pack-reused 213
    Receiving objects: 100% (220/220), 850.37 KiB | 33.00 KiB/s, done.
    Resolving deltas: 100% (81/81), done.

    1. 检查kuberntes镜像版本和docker镜像版本是否一致,若不一致则修改
    # 切换目录
    cd k8s-docker-for-mac 
    # 查看版本镜像
    cat images
    # 替换版本镜像 ~~ 若使用阿里云docker仓库,则可将k8s.gcr.io替换为mirrorgooglecontainers
    sed -i '' "s/v1.16.5/v1.15.5/g" images
    
    

    $ k8s-docker-for-mac % cat images
    mirrorgooglecontainers/kube-proxy:v1.15.5=gotok8s/kube-proxy:v1.15.5
    mirrorgooglecontainers/kube-controller-manager:v1.15.5=gotok8s/kube-controller-manager:v1.15.5
    mirrorgooglecontainers/kube-scheduler:v1.15.5=gotok8s/kube-scheduler:v1.15.5
    mirrorgooglecontainers/kube-apiserver:v1.15.5=gotok8s/kube-apiserver:v1.15.5
    mirrorgooglecontainers/coredns:1.6.2=gotok8s/coredns:1.6.2
    mirrorgooglecontainers/pause:3.1=gotok8s/pause:3.1
    mirrorgooglecontainers/etcd:3.3.15-0=gotok8s/etcd:3.3.15-0

    1. 拉取镜像
    # 拉取镜像
    ./load_images.sh
    
    

    修改daocke镜像标签

    docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
    docker tag 1399a72fa1a9 k8s.gcr.io/kube-controller-manager:v1.15.5
    docker tag fab2dded59dd k8s.gcr.io/kube-scheduler:v1.15.5
    docker tag cbd7f21fec99 k8s.gcr.io/kube-proxy:v1.15.5
    docker tag e534b1952a0d k8s.gcr.io/kube-apiserver:v1.15.5
    docker tag 2c4adeb21b4f k8s.gcr.io/etcd:3.3.10
    docker tag eb516548c180 k8s.gcr.io/coredns:1.3.1
    docker tag f9aed6605b81 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
    
    

    镜像标签修改成功:

    $ k8s-docker-for-mac % docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    k8s.gcr.io/kube-controller-manager v1.15.5 1399a72fa1a9 6 months ago 159MB
    k8s.gcr.io/kube-proxy v1.15.5 cbd7f21fec99 6 months ago 82.4MB
    k8s.gcr.io/kube-apiserver v1.15.5 e534b1952a0d 6 months ago 207MB
    k8s.gcr.io/kube-scheduler v1.15.5 fab2dded59dd 6 months ago 81.1MB
    k8s.gcr.io/etcd 3.3.15-0 b2756210eeab 7 months ago 247MB
    k8s.gcr.io/coredns 1.6.2 bf261d157914 8 months ago 44.1MB
    k8s.gcr.io/pause 3.1 da86e6ba6ca1 2 years ago 742kB

    1. 重启docker ~等待2-5分钟,kubernetes启动成功(对我的版本无用)

      静静等待半小时也无用

    方案二 删除配置文件,重置仓库

    1. 检查hosts,是否如下
    127.0.0.1       localhost
    255.255.255.255 broadcasthost
    ::1             localhost
    127.0.0.1 kubernetes.docker.internal
    
    
    1. 删除kuberntes环境
    rm -rf ~/.kube
    rm -rf ~/Library/Group\ Containers/group.com.docker/pki/
    
    
    1. 重启docker ~ 对我的电脑起作用了。 大约5分
      docker -> troubleshoot -> reset kubernetes cluster
      docker -> restart

    方案三 更新docker软件版本,有效

    docker -> preferences -> troubleshoot -> uninstall 卸载docker desktop


    卸载docker

    卸载后点击图标,docker依然可用 ~~ 若有不同的情况,则重新安装即可


    docker desktop 2.2.0.5 stable

    新建镜像拉取脚本docker-images-k8s.sh

    #!/bin/bash
    set -e
    KUBE_VERSION=v1.15.5
    KUBE_DASHBOARD_VERSION=v1.10.1
    KUBE_PAUSE_VERSION=3.1
    ETCD_VERSION=3.3.10
    COREDNS_VERSION=1.3.1
    # 这里为了使国内拉取镜像更快,使用了mirrorgooglecontainers进行拉取
    GCR_URL=mirrorgooglecontainers
    #GCR_URL=k8s.gcr.io
    ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
    #get images
    images=(kube-proxy:${KUBE_VERSION}
    kube-scheduler:${KUBE_VERSION}
    kube-controller-manager:${KUBE_VERSION}
    kube-apiserver:${KUBE_VERSION}
    pause:${KUBE_PAUSE_VERSION}
    etcd:${ETCD_VERSION}
    coredns:${COREDNS_VERSION}
    kubernetes-dashboard-amd64:${KUBE_DASHBOARD_VERSION})
    for imageName in ${images[@]} ; do
    docker pull $ALIYUN_URL/$imageName
    docker tag $ALIYUN_URL/$imageName $GCR_URL/$imageName
    docker rmi $ALIYUN_URL/$imageName
    done
    docker images
    
    

    执行拉取镜像

    # 脚本赋权
    chmod 755 docker-images-k8s.sh
    # 拉取镜像
    ./docker-images-k8s.sh 
    
    

    $ docker-images-k8s % ./docker-images-k8s.sh
    v1.15.5: Pulling from google_containers/kube-proxy
    39fafc05754f: Pull complete
    db3f71d0eb90: Pull complete
    d61d3783fe96: Pull complete
    Digest: sha256:5a5daccba435ec29c869a1009b5e0abf0501eaf5c74b50a59b954e1f9954d116
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.5
    registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy@sha256:5a5daccba435ec29c869a1009b5e0abf0501eaf5c74b50a59b954e1f9954d116
    v1.15.5: Pulling from google_containers/kube-scheduler
    39fafc05754f: Already exists
    820be6fac024: Pull complete
    Digest: sha256:e6ddeb4b9634e6d9992825c10a5e5e4790b48ad792467287e056d4c96fcd7ade
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.5
    registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler@sha256:e6ddeb4b9634e6d9992825c10a5e5e4790b48ad792467287e056d4c96fcd7ade
    v1.15.5: Pulling from google_containers/kube-controller-manager
    39fafc05754f: Already exists
    dfc48811dd58: Pull complete
    Digest: sha256:3e9e0d60e09ec41183b20bc29c1c1772263eeb22e08240b6d2ce65179d7ff05c
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.5
    registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager@sha256:3e9e0d60e09ec41183b20bc29c1c1772263eeb22e08240b6d2ce65179d7ff05c
    v1.15.5: Pulling from google_containers/kube-apiserver
    39fafc05754f: Already exists
    88e18b69dd95: Pull complete
    Digest: sha256:d9fccd50f56c0f16dd55d2d708f4f71106c518ae92bf7a8d11d5db9d9dfb0fbc
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.5
    registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.15.5
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver@sha256:d9fccd50f56c0f16dd55d2d708f4f71106c518ae92bf7a8d11d5db9d9dfb0fbc
    3.1: Pulling from google_containers/pause
    cf9202429979: Pull complete
    Digest: sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
    registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause@sha256:759c3f0f6493093a9043cc813092290af69029699ade0e3dbe024e968fcb7cca
    3.3.10: Pulling from google_containers/etcd
    90e01955edcd: Pull complete
    6369547c492e: Pull complete
    bd2b173236d3: Pull complete
    Digest: sha256:240bd81c2f54873804363665c5d1a9b8e06ec5c63cfc181e026ddec1d81585bb
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
    registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.3.10
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd@sha256:240bd81c2f54873804363665c5d1a9b8e06ec5c63cfc181e026ddec1d81585bb
    1.3.1: Pulling from google_containers/coredns
    e0daa8927b68: Pull complete
    3928e47de029: Pull complete
    Digest: sha256:638adb0319813f2479ba3642bbe37136db8cf363b48fb3eb7dc8db634d8d5a5b
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
    registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.3.1
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns@sha256:638adb0319813f2479ba3642bbe37136db8cf363b48fb3eb7dc8db634d8d5a5b
    v1.10.1: Pulling from google_containers/kubernetes-dashboard-amd64
    9518d8afb433: Pull complete
    Digest: sha256:0ae6b69432e78069c5ce2bcde0fe409c5c4d6f0f4d9cd50a17974fea38898747
    Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
    registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64:v1.10.1
    Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kubernetes-dashboard-amd64@sha256:0ae6b69432e78069c5ce2bcde0fe409c5c4d6f0f4d9cd50a17974fea38898747
    REPOSITORY TAG IMAGE ID CREATED SIZE
    mirrorgooglecontainers/kube-proxy v1.15.5 cbd7f21fec99 6 months ago 82.4MB
    mirrorgooglecontainers/kube-controller-manager v1.15.5 1399a72fa1a9 6 months ago 159MB
    mirrorgooglecontainers/kube-apiserver v1.15.5 e534b1952a0d 6 months ago 207MB
    mirrorgooglecontainers/kube-scheduler v1.15.5 fab2dded59dd 6 months ago 81.1MB
    mirrorgooglecontainers/coredns 1.3.1 eb516548c180 15 months ago 40.3MB
    mirrorgooglecontainers/kubernetes-dashboard-amd64 v1.10.1 f9aed6605b81 16 months ago 122MB
    mirrorgooglecontainers/etcd 3.3.10 2c4adeb21b4f 16 months ago 258MB
    mirrorgooglecontainers/pause 3.1 da86e6ba6ca1 2 years ago 742kB

    修改daocke镜像标签

    docker tag da86e6ba6ca1 k8s.gcr.io/pause:3.1
    docker tag 1399a72fa1a9 k8s.gcr.io/kube-controller-manager:v1.15.5
    docker tag fab2dded59dd k8s.gcr.io/kube-scheduler:v1.15.5
    docker tag cbd7f21fec99 k8s.gcr.io/kube-proxy:v1.15.5
    docker tag e534b1952a0d k8s.gcr.io/kube-apiserver:v1.15.5
    docker tag 2c4adeb21b4f k8s.gcr.io/etcd:3.3.10
    docker tag eb516548c180 k8s.gcr.io/coredns:1.3.1
    docker tag f9aed6605b81 k8s.gcr.io/kubernetes-dashboard-amd64:v1.10.1
    
    

    重启docker后,恢复正常

    docker kubernetes处于running状态

    说明:方案一和方案三,容器镜像和docker小版本更新,本质上无明显差别,但仅方案三有效,网友们若有新的见解,欢迎在评论区补充指正,谢谢。


    对方案三补充指正

    感谢裤裆三重奏补充指正: ~~ 评论中摘抄
      修改 sh 的 GCR_URL 为 k8s.gcr.io,再运行即可
    新建镜像拉取脚本docker-images-k8s.sh

    #!/bin/bash
    set -e
    KUBE_VERSION=v1.15.5
    KUBE_DASHBOARD_VERSION=v1.10.1
    KUBE_PAUSE_VERSION=3.1
    ETCD_VERSION=3.3.10
    COREDNS_VERSION=1.3.1
    # 这里为了使国内拉取镜像更快,使用了mirrorgooglecontainers进行拉取
    GCR_URL=k8s.gcr.io  # 此处修改为了k8s.gcr.io
    #GCR_URL=k8s.gcr.io
    ALIYUN_URL=registry.cn-hangzhou.aliyuncs.com/google_containers
    #get images
    images=(kube-proxy:${KUBE_VERSION}
    kube-scheduler:${KUBE_VERSION}
    kube-controller-manager:${KUBE_VERSION}
    kube-apiserver:${KUBE_VERSION}
    pause:${KUBE_PAUSE_VERSION}
    etcd:${ETCD_VERSION}
    coredns:${COREDNS_VERSION}
    kubernetes-dashboard-amd64:${KUBE_DASHBOARD_VERSION})
    for imageName in ${images[@]} ; do
    docker pull $ALIYUN_URL/$imageName
    docker tag $ALIYUN_URL/$imageName $GCR_URL/$imageName
    docker rmi $ALIYUN_URL/$imageName
    done
    docker images
    

    参考:
    https://blog.csdn.net/myhes/article/details/105593944?utm_medium=distribute.pc_relevant.none-task-blog-baidulandingword-3&spm=1001.2101.3001.4242

    相关文章

      网友评论

          本文标题:macos docker 一直处于 kubernetes sta

          本文链接:https://www.haomeiwen.com/subject/pxqldktx.html