牛魔今天为了部署一个kubeflow,把docker和k8s彻底配置了一天,各种方法都尝试了,包括不限于下载国内的k8s组件,并通过tag绑定到国外的名字上,这样拉一个k8s集群就会直接用本地的,但这种方法不知道为什么失败了。

其次docker的网络也有问题,镜像源不稳定,最终得到尝试通过代理的方法,找到代理软件的端口,在docker- setting-proxy中配置走代理的ip,这样之后稳定了一些。

具体成功的流程:

首先配置docker镜像源以及代理的端口,都在docker desktop中配置:

镜像源:

  "builder": {
"gc": {
"defaultKeepStorage": "20GB",
"enabled": true
}
},
"experimental": false,
"registry-mirrors": [
"https://mirror.aliyuncs.com",
"https://hub-mirror.c.163.com",
"https://dockerproxy.com/",
"https://mirror.baidubce.com/",
"https://docker.mirrors.sjtug.sjtu.edu.cn/",
"https://mirror.ccs.tencentyun.com",
"https://docker-0.unsee.tech",
"https://docker.mirrors.ustc.edu.cn/"
]
}

代理配置:

  1. 开启你的代理软件,并确认它开启了“允许局域网连接”或者你知道它的 HTTP 代理端口(通常是 7890 或 1087 等)。
  2. 打开 Docker Desktop 设置 -> Resources -> Proxies
  3. 开启 Manual proxy configuration
  4. 在 Web Server (HTTP) 和 Secure Web Server (HTTPS) 中填入你的本地代理地址,例如:http://127.0.0.1:7890 (端口号请根据你的软件实际情况填写)
  5. 在 Bypass proxy settings 里,务必保留或填入:
    localhost,127.0.0.1

这一步之后docker的网络应该是没问题了,下一步就是安装minikube,Minikube 是一个轻量级工具,它会在你的 Docker 里启动一个容器,把这个容器当作一台 K8s 机器。是一个本地测试k8s环境的轻量化工具。

第一步:安装 Minikube

打开终端,Homebrew 安装:

MAC:

brew install minikube

第二步:启动集群(关键步骤)

既然你想要“指定版本”且“网络通畅”,请直接复制下面的命令执行。

# 1. 先删掉之前的残留(防止网络冲突)
minikube delete --all
docker network prune -f

# 2. 启动(注意:不要加 proxy 环境变量,避免干扰)
minikube start \
--driver=docker \
--image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers \
--kubernetes-version=v1.28.0

这条命令做了三件事:

  1. –driver=docker:告诉它,不要搞虚拟机,直接在我的 Docker 里跑(前提是你 Docker Desktop 已经开着,但不需要开 K8s 功能)。
  2. –image-mirror-country=’cn’:核心魔法。它会自动把下载地址切换到阿里云(registry.cn-hangzhou.aliyuncs.com)。
  3. –kubernetes-version=v1.28.0:你可以把这里换成任何你想要的版本(比如 v1.23.0, v1.30.0 等)。

得到的结果是:

😄  minikube v1.37.0 on Darwin 15.6.1 (arm64)
✨ Using the docker driver based on user configuration
✅ Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
📌 Using Docker Desktop driver with root privileges
👍 Starting "minikube" primary control-plane node in "minikube" cluster
🚜 Pulling base image v0.0.48 ...
🔥 Creating docker container (CPUs=2, Memory=4000MB) ...
🐳 Preparing Kubernetes v1.28.0 on Docker 28.4.0 ...
🔗 Configuring bridge CNI (Container Networking Interface) ...
🔎 Verifying Kubernetes components...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
🌟 Enabled addons: storage-provisioner, default-storageclass

❗ /opt/homebrew/bin/kubectl is version 1.34.3, which may have incompatibilities with Kubernetes 1.28.0.
▪ Want kubectl v1.28.0? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
(base) mag1code@zhanghaoyangdeMacBook-Air ~ % kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 2m14s v1.28.0