Minikube及kubectl安装 (Windows 10)
一、Minikube
Minikube在使用国内镜像时,由于k8s1.28之后版本仓库路径的变化,minikube start 时会出各种问题 https://developer.aliyun.com/mirror/kubernetes 推荐安装minikube1.27版本。
下面为一种 minikube 1.27.0 的安装策略。
- 下载 https://storage.googleapis.com/minikube/releases/latest/minikube-installer.exe
- 运行上述程序,安装最新版Minikube,记住安装的位置
- 下载 https://github.com/kubernetes/minikube/releases/download/v1.27.0/minikube-windows-amd64.exe
- 该程序为
1.27.0
版的minikube的二进制文件minikube-windows-amd64.exe
,将其复制到之前安装Minikube的目录下,替换原有的minikube.exe
。即删除原来的minikube.exe
并将minikube-windows-amd64.exe
更名为minikube.exe
- 任意路径下cmd运行
minikube version
查看版本,为v1.27.0即可。 - cmd运行
minikube delete
清除之前的运行痕迹。 - Start the Docker service,可直接运行docker desktop。
- cmd运行
minikube start --driver=docker --image-mirror-country=cn
- 若报错
Unable to resolve the current Docker CLI context "default": context "default": context not found: on Windows
,使用如下指令docker context use default
更新上下文。 https://stackoverflow.com/questions/77208746/unable-to-resolve-the-current-docker-cli-context-default-context-default-c - 下载镜像速度正常,且不报错即可,网速正常的情况下几分钟应该就能运行结束。
参考输出:(如果此时还没装kubectl,可能不会有最后一条warning)
* Microsoft Windows 10 Home China 10.0.19045 Build 19045 上的 minikube v1.27.0
! Kubernetes 1.25.0 has a known issue with resolv.conf. minikube is using a workaround that should work for most use cases.
! For more information, see: https://github.com/kubernetes/kubernetes/issues/112135
* 根据现有的配置文件使用 docker 驱动程序
* Starting control plane node minikube in cluster minikube
* Pulling base image ...
* docker "minikube" container is missing, will recreate.
* Creating docker container (CPUs=2, Memory=4000MB) ...
* 正在 Docker 20.10.17 中准备 Kubernetes v1.25.0…
* Verifying Kubernetes components...
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
* Enabled addons: storage-provisioner, default-storageclass
! D:\Kubectl\kubectl.exe is version 1.29.1, which may have incompatibilites with Kubernetes 1.25.0.
- Want kubectl v1.25.0? Try 'minikube kubectl -- get pods -A'
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
二、kubectl
Note: Docker Desktop for Windows adds its own version of
kubectl
toPATH
. If you have installed Docker Desktop before, you may need to place yourPATH
entry before the one added by the Docker Desktop installer or remove the Docker Desktop’skubectl
.下面为一种 kubectl 的安装策略。
- 下载https://dl.k8s.io/release/v1.29.3/bin/windows/amd64/kubectl.exe
- 将上述文件复制到某个目录下
- 将上述目录添加到系统环境变量
- 将刚刚添加的环境变量优先度上移,可以直接移到最上方。
- 测试:任意文件夹下打开cmd,输入
kubectl version --client
,不报错即可。若程序拒绝访问则是kubectl目录在系统环境变量中的优先度不够。