基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题

估计各方应用会慢慢搞好苹果M系列产品的支持,因为工作和学习的需要换了高点配置的18版Mac Mini,所以本文只针对Intel的MacOS产品。

1 简介

1.1 Docker Desktop

从功能上来看Docker Desktop是Docker Machine和Docker Toolbox的结合体,帮助系统安装Docker环境、Docker引擎,并进行管理。

1.2 k8s-for-docker-desktop

打开k8s-for-docker-desktop的介绍切换为英文简介就知道这是阿里为了国内本地Kubernetes能正常在Docker Desktop下启动的项目。

1.3 问题

回到标题,docker-desktop是可以为我们启动本地Kubernetes环境的,但是从官网下载下或更新后的docker-desktop会出现Kubernetes is starting,并最终启动失败,我总结了两个原因

  • docker-desktop无法正常下载本地Kubernetes所需要的docker镜像
  • docker-desktop版本与本地Kubernetes镜像版本不一致

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第1张图片 

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第2张图片

2 解决方案

2.1 docker-desktop无法正常下载本地Kubernetes镜像

1. 在新的电脑下载docker的时候他的镜像源地址会是国外地址,这也是docker-desktop启动失败的主要原因,我们要修改docker的镜像源地址

{
  "debug": true,
  "experimental": false,
  "registry-mirrors": [
    "http://hub-mirror.c.163.com"
  ]
}

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第3张图片 

2. 启动本地Kubernetes,等待docker-desktop自动下载本地Kubernetes镜像

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第4张图片

2.1 如果发现配置了镜像源地址后发现启动失败,可以查看一下当前docker中的镜像,目前需要启动的镜像为11个。那就是docker-desktop拉取镜像失败了,这个时候就可以使用k8s-for-docker-desktop来拉取,到达clone下来的文件夹执行

kirra@KenhodeMac-mini k8s-for-docker-desktop % ./load_images.sh         
images.properties found.
3.7: Pulling from google_containers/pause
Digest: sha256:bb6ed397957e9ca7c65ada0db5c5d1c707c9c8afc80a94acbe69f3ae76988f0c
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.7
registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.7
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.7
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/pause@sha256:bb6ed397957e9ca7c65ada0db5c5d1c707c9c8afc80a94acbe69f3ae76988f0c
v1.24.0: Pulling from google_containers/kube-controller-manager
Digest: sha256:df044a154e79a18f749d3cd9d958c3edde2b6a00c815176472002b7bbf956637
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.24.0
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager@sha256:df044a154e79a18f749d3cd9d958c3edde2b6a00c815176472002b7bbf956637
v1.24.0: Pulling from google_containers/kube-scheduler
Digest: sha256:db842a7c431fd51db7e1911f6d1df27a7b6b6963ceda24852b654d2cd535b776
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.24.0
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler@sha256:db842a7c431fd51db7e1911f6d1df27a7b6b6963ceda24852b654d2cd535b776
v1.24.0: Pulling from google_containers/kube-proxy
Digest: sha256:c957d602267fa61082ab8847914b2118955d0739d592cc7b01e278513478d6a8
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.24.0
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy@sha256:c957d602267fa61082ab8847914b2118955d0739d592cc7b01e278513478d6a8
v1.24.0: Pulling from google_containers/kube-apiserver
Digest: sha256:a04522b882e919de6141b47d72393fb01226c78e7388400f966198222558c955
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.24.0
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.24.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver@sha256:a04522b882e919de6141b47d72393fb01226c78e7388400f966198222558c955
3.5.3-0: Pulling from google_containers/etcd
Digest: sha256:13f53ed1d91e2e11aac476ee9a0269fdda6cc4874eba903efd40daf50c55eee5
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.3-0
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.3-0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.5.3-0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/etcd@sha256:13f53ed1d91e2e11aac476ee9a0269fdda6cc4874eba903efd40daf50c55eee5
1.8.6: Pulling from google_containers/coredns
Digest: sha256:5b6ec0d6de9baaf3e92d0f66cd96a25b9edbce8716f5f15dcd1a616b3abd590e
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.8.6
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/coredns@sha256:5b6ec0d6de9baaf3e92d0f66cd96a25b9edbce8716f5f15dcd1a616b3abd590e
v1.2.0: Pulling from google_containers/nginx-ingress-controller
8663204ce13b: Pull complete 
84179402ed35: Pull complete 
d77f49ad4de1: Pull complete 
1ccd9bf31a02: Pull complete 
b19121afa234: Pull complete 
181c59e50a5d: Pull complete 
4f4fb700ef54: Pull complete 
d56037635072: Pull complete 
bd3a69071f57: Pull complete 
6a351a692218: Pull complete 
dcd58390a200: Pull complete 
a1970f0aa3ab: Pull complete 
e5dfb0a8ce00: Pull complete 
46d2a52230bc: Pull complete 
f6ce04c8e75e: Pull complete 
Digest: sha256:d8196e3bc1e72547c5dec66d6556c0ff92a23f6d0919b206be170bc90d5f9185
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.2.0
registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.2.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller:v1.2.0
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/nginx-ingress-controller@sha256:d8196e3bc1e72547c5dec66d6556c0ff92a23f6d0919b206be170bc90d5f9185
v1.1.1: Pulling from google_containers/kube-webhook-certgen
ec52731e9273: Pull complete 
b90aa28117d4: Pull complete 
Digest: sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660
Status: Downloaded newer image for registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen:v1.1.1
Untagged: registry.cn-hangzhou.aliyuncs.com/google_containers/kube-webhook-certgen@sha256:64d8c73dca984af206adf9d6d7e46aa550362b1d7a01f3a0a91b20cc67868660
kirra@KenhodeMac-mini k8s-for-docker-desktop % kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.5.1/aio/deploy/recommended.yaml
The connection to the server raw.githubusercontent.com was refused - did you specify the right host or port?
kirra@KenhodeMac-mini k8s-for-docker-desktop % kubectl apply -f kubernetes-dashboard.yaml
namespace/kubernetes-dashboard created
serviceaccount/kubernetes-dashboard created
service/kubernetes-dashboard created
secret/kubernetes-dashboard-certs created
secret/kubernetes-dashboard-csrf created
secret/kubernetes-dashboard-key-holder created
configmap/kubernetes-dashboard-settings created
role.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrole.rbac.authorization.k8s.io/kubernetes-dashboard created
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created

3 当发现Kubernetes为绿则证明启动成功

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第5张图片

 

2.2 docker-desktop版本与本地Kubernetes镜像版本不一致

一般第一种解决方式基本就能解决问题,出现这个原因就是docker-desktop更新后镜像又下载失败,使用旧版k8s-for-docker-desktop配置来进行镜像更新,其根本原因就是就是k8s-for-docker-desktop的配置没有更新为新版本对应的配置。

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第6张图片

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第7张图片例如我们启动docker-desktop 3.6.0版本的Kubernetes,我们需要在k8s-for-docker-desktop寻找对应的版本,切换到对应的分支,把配置复制到我们本地k8s-for-docker-desktop配置当中。

基于k8s-for-docker-desktop解决Intel版MacOS启动DockerDesktop下Kubernetes因镜像欠缺失启动失败的问题_第8张图片并重新执行

./load_images.sh

当然最稳健的方式还是重试clone对应分支的所有内容

3 访问与使用

访问与使用Kubernetes可以参考我此前的博文Kubernetes可视化界面Kubernetes Dashboard

参考:https://zh.m.wikipedia.org/zh/Docker

https://github.com/AliyunContainerService/k8s-for-docker-desktop 

你可能感兴趣的:(MAC,云原生,docker,kubernetes,运维)