minikube 使用 VirtualBox 安装迷你版 Kubernetes 集群
minikube Kubernetes VirtualBox About 11,318 words说明
本文基于Windows
平台和VirtualBox
虚拟机,minikube v1.26.0
。
官方文档
https://minikube.sigs.k8s.io/docs
choco 方式安装
choco install minikube
exe 方式安装
https://storage.googleapis.com/minikube/releases/latest/minikube-installer.exe
启动 minikube
默认不带参数启动
minikube start --driver="virtualbox" --memory=2048
添加镜像等参数
minikube start --driver=virtualbox --no-vtx-check --cpus=2 --memory=2048 --image-mirror-country="cn" --registry-mirror=https://hub-mirror.c.163.com --registry-mirror=https://docker.mirrors.ustc.edu.cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --insecure-registry=registry.cn-hangzhou.aliyuncs.com --insecure-registry=registry.k8s.io
--driver
:如果不写会自动检测,可选值virtualbox
,vmwarefusion
,hyperv
,vmware
。--no-vtx-check
:不指定该参数会抛出This computer doesn't have VT-X/AMD-v enabled
异常。--cpus
:设置CPU
数量。--memory
:设置虚机内存大小。--image-mirror-country
:需要使用的镜像镜像的国家/地区代码。留空以使用全球代码。对于中国大陆用户,请将其设置为cn
。--registry-mirror
:Docker Registry
的镜像源,集群安装后拉取镜像加速用,可以使用其它加速器地址。这里使用中科大镜像。--image-repository
:用来拉取Kubernetes
集群所需镜像的仓库。--insecure-registry
:允许不校验HTTPS
证书,否则拉取镜像时会报x509: certificate signed by unknown authority
错误。
输出:
😄 Microsoft Windows 10 上的 minikube v1.26.0
✨ 根据现有的配置文件使用 virtualbox 驱动程序
👍 Starting control plane node minikube in cluster minikube
🔥 Creating virtualbox VM (CPUs=2, Memory=2048MB, Disk=20000MB) ...
❗ This VM is having trouble accessing https://registry.cn-hangzhou.aliyuncs.com/google_containers
💡 To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
> kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubeadm: 42.31 MiB / 42.31 MiB [--------------] 100.00% 6.96 MiB p/s 6.3s
> kubelet: 110.96 MiB / 110.96 MiB [------------] 100.00% 10.34 MiB p/s 11s
> kubectl: 43.59 MiB / 43.59 MiB [---------------] 100.00% 3.01 MiB p/s 15s
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│ │
│ You have selected "virtualbox" driver, but there are better options ! │
│ For better performance and support consider using a different driver: │
│ - hyperv │
│ │
│ To turn off this warning run: │
│ │
│ $ minikube config set WantVirtualBoxDriverWarning false │
│ │
│ │
│ To learn more about on minikube drivers checkout https://minikube.sigs.k8s.io/docs/drivers/ │
│ To see benchmarks checkout https://minikube.sigs.k8s.io/docs/benchmarks/cpuusage/ │
│ │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
可能的错误
This computer doesn't have VT-X/AMD-v enabled
异常,添加--no-vtx-check
参数,不检查vtx
。
😿 Failed to start virtualbox VM. Running "minikube delete" may fix it: creating host: create: precreate: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory
❌ Exiting due to HOST_VIRT_UNAVAILABLE: Failed to start host: creating host: create: precreate: This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory
💡 建议:Virtualization support is disabled on your computer. If you are running minikube within a VM, try '--driver=docker'. Otherwise, consult your systems BIOS manual for how to enable virtualization.
🍿 相关问题:
▪ https://github.com/kubernetes/minikube/issues/3900
▪ https://github.com/kubernetes/minikube/issues/4730
create host timed out in 360.000000 seconds
异常,删除用户目录下的.minikube\machines\minikube
文件夹,使用minikube start
重新执行命令。
PS C:\Users\zhangb76> minikube delete --all 🔥 正在移除 C:\Users\zhangb76.minikube\machines\minikube… 💀 Removed all traces of the "minikube" cluster. 🔥 成功删除所有配置文件
🤦 StartHost failed, but will try again: creating host: create host timed out in 360.000000 seconds
😿 Failed to start virtualbox VM. Running "minikube delete" may fix it: error loading existing host. Please try running [minikube delete], then run [minikube start] again: filestore "minikube": open C:\Users\fendoudebb\.minikube\machines\minikube\config.json: The system cannot find the file specified.
❌ Exiting due to GUEST_NOT_FOUND: Failed to start host: error loading existing host. Please try running [minikube delete], then run [minikube start] again: filestore "minikube": open C:\Users\fendoudebb\.minikube\machines\minikube\config.json: The system cannot find the file specified.
💡 建议:minikube is missing files relating to your guest environment. This can be fixed by running 'minikube delete'
🍿 Related issue: https://github.com/kubernetes/minikube/issues/9130
查看集群状态
minikube kubectl -- get pods -A
开启网页 dashboard
会自动打开浏览器
minikube dashboard
输出:
PS C:\Users\fendoudebb> minikube dashboard
🔌 正在开启 dashboard ...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-scraper:v1.0.8
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/dashboard:v2.6.0
🤔 正在验证 dashboard 运行情况 ...
🚀 Launching proxy ...
🤔 正在验证 proxy 运行状况 ...
🎉 Opening http://127.0.0.1:51859/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
只获取url
地址,不自动打开浏览器
minikube dashboard --url
输出:
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
http://127.0.0.1:61689/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
进入虚拟机
进入虚拟机后可以执行Linux
命令。
minikube ssh
输出:
PS C:\Users\fendoudebb> minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
暂停 Kubernetes
minikube pause
恢复 Kubernetes
minikube unpause
停止 Kubernetes
minikube stop
调整内存大小
需要重启实例
minikube config set memory 16384
删除 Kubernetes
删除所有Kubernetes
实例
minikube delete --all
输出:
✋ Stopping node "minikube" ...
🛑 Powering off "minikube" via SSH ...
🔥 Deleting "minikube" in hyperv ...
💀 Removed all traces of the "minikube" cluster.
🔥 Successfully deleted all profiles
退后后再次启动
如果虚拟机关闭后,再次开启虚拟机后需再执行minikube start
命令启动Kubernetes
。
minikube start
查看插件列表
minikube addons list
输出:
PS C:\Users\fendoudebb> minikube addons list
|-----------------------------|----------|--------------|--------------------------------|
| ADDON NAME | PROFILE | STATUS | MAINTAINER |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador | minikube | disabled | 3rd party (Ambassador) |
| auto-pause | minikube | disabled | Google |
| csi-hostpath-driver | minikube | disabled | Kubernetes |
| dashboard | minikube | enabled ✅ | Kubernetes |
| default-storageclass | minikube | enabled ✅ | Kubernetes |
| efk | minikube | disabled | 3rd party (Elastic) |
| freshpod | minikube | disabled | Google |
| gcp-auth | minikube | disabled | Google |
| gvisor | minikube | disabled | Google |
| headlamp | minikube | disabled | kinvolk.io |
| helm-tiller | minikube | disabled | 3rd party (Helm) |
| inaccel | minikube | disabled | InAccel <info@inaccel.com> |
| ingress | minikube | disabled | 3rd party (unknown) |
| ingress-dns | minikube | disabled | Google |
| istio | minikube | disabled | 3rd party (Istio) |
| istio-provisioner | minikube | disabled | 3rd party (Istio) |
| kong | minikube | disabled | 3rd party (Kong HQ) |
| kubevirt | minikube | disabled | 3rd party (KubeVirt) |
| logviewer | minikube | disabled | 3rd party (unknown) |
| metallb | minikube | disabled | 3rd party (MetalLB) |
| metrics-server | minikube | disabled | Kubernetes |
| nvidia-driver-installer | minikube | disabled | Google |
| nvidia-gpu-device-plugin | minikube | disabled | 3rd party (Nvidia) |
| olm | minikube | disabled | 3rd party (Operator Framework) |
| pod-security-policy | minikube | disabled | 3rd party (unknown) |
| portainer | minikube | disabled | Portainer.io |
| registry | minikube | disabled | Google |
| registry-aliases | minikube | disabled | 3rd party (unknown) |
| registry-creds | minikube | disabled | 3rd party (UPMC Enterprises) |
| storage-provisioner | minikube | enabled ✅ | Google |
| storage-provisioner-gluster | minikube | disabled | 3rd party (unknown) |
| volumesnapshots | minikube | disabled | Kubernetes |
|-----------------------------|----------|--------------|--------------------------------|
kubectl
Linux
下可以使用alias
alias kubectl="minikube kubectl --"
Windows
下可以使用doskey
起别名,但比较麻烦,可以直接下载exe
二进制文件,加入到环境变量中即可使用kubectl
https://kubernetes.io/docs/tasks/tools/install-kubectl-windows
开源地址
https://github.com/kubernetes/minikube
阿里镜像
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓