minikube 使用 Hyper-V 安装迷你版 Kubernetes 集群

Kubernetes minikube Windows About 12,162 words

说明

本文基于Windows平台和Hyper-V虚拟机。

官方文档

https://minikube.sigs.k8s.io/docs

choco 方式安装

choco install minikube

exe 方式安装

https://storage.googleapis.com/minikube/releases/latest/minikube-installer.exe

下载安装后

启动 minikube

默认不带参数启动

minikube start --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="Default Switch"

添加镜像等参数

minikube start --vm-driver="hyperv" --memory=4096 --hyperv-virtual-switch="Default Switch" --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
  • --vm-driver:如果不写会自动检测,可选值virtualboxvmwarefusionhypervvmware
  • --memory:设置虚机内存大小。
  • --hyperv-virtual-switch:设置Hyper-v网卡。
  • --image-mirror-country:需要使用的镜像镜像的国家/地区代码。留空以使用全球代码。对于中国大陆用户,请将其设置为cn
  • --registry-mirrorDocker Registry的镜像源,集群安装后拉取镜像加速用,可以使用其它加速器地址。这里使用中科大镜像。
  • --image-repository:用来拉取Kubernetes集群所需镜像的仓库。
  • --insecure-registry:允许不校验HTTPS证书,否则拉取镜像时会报x509: certificate signed by unknown authority错误。

输出:

💿  Downloading VM boot image ...
    > minikube-v1.25.0.iso.sha256: 65 B / 65 B [-------------] 100.00% ? p/s 0s
    > minikube-v1.25.0.iso: 226.25 MiB / 226.25 MiB  100.00% 2.35 MiB p/s 1m37s
👍  Starting control plane node minikube in cluster minikube
🔥  Creating hyperv VM (CPUs=2, Memory=4096MB, 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/
🐳  Preparing Kubernetes v1.23.1 on Docker 20.10.12 ...
    ▪ kubelet.housekeeping-interval=5m
    > kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm: 43.12 MiB / 43.12 MiB [---------------] 100.00% 1.26 MiB p/s 34s
    > kubectl: 44.43 MiB / 44.43 MiB [---------------] 100.00% 1.06 MiB p/s 42s
    > kubelet: 118.75 MiB / 118.75 MiB [-------------] 100.00% 2.65 MiB p/s 45s
    ▪ Generating certificates and keys ...
    ▪ Booting up control plane ...
    ▪ Configuring RBAC rules ...
🔎  Verifying Kubernetes components...
    ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
🌟  Enabled addons: storage-provisioner, default-storageclass
💡  kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄  Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default

查看集群状态

minikube kubectl -- get pods -A

开启网页 dashboard

会自动打开浏览器

minikube dashboard

输出:

🔌  Enabling dashboard ...
    ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/dashboard:v2.3.1
    ▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-scraper:v1.0.7
🤔  Verifying dashboard health ...
🚀  Launching proxy ...
🤔  Verifying proxy health ...
🎉  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\hello> minikube ssh
                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ docker ps
CONTAINER ID   IMAGE                                                           COMMAND                  CREATED
STATUS         PORTS     NAMES
d91132fffea6   7801cfc6d5c0                                                    "/metrics-sidecar"       4 minutes ago   Up 3 minutes             k8s_dashboard-metrics-scraper_dashboard-metrics-scraper-6ccbc78cd8-xk89b_kubernetes-dashboard_718f383e-9d41-4cb5-a27b-dd218bf191bb_1
dbb64f039d73   e1482a24335a                                                    "/dashboard --insecu…"   4 minutes ago   Up 4 minutes             k8s_kubernetes-dashboard_kubernetes-dashboard-6ddd477f4f-4p8sh_kubernetes-dashboard_de53c867-728b-48f6-bb39-045eaf2bec09_1
1625215266ea   6e38f40d628d                                                    "/storage-provisioner"   4 minutes ago   Up 4 minutes             k8s_storage-provisioner_storage-provisioner_kube-system_181f6519-9006-4a3a-b418-4d65b977e490_1
e5b6a8370189   a4ca41631cc7                                                    "/coredns -conf /etc…"   4 minutes ago   Up 4 minutes             k8s_coredns_coredns-65c54cc984-xwd9d_kube-system_5cb214a9-69b9-4a84-aa01-b9692612f325_1
b0f7ef380b44   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_dashboard-metrics-scraper-6ccbc78cd8-xk89b_kubernetes-dashboard_718f383e-9d41-4cb5-a27b-dd218bf191bb_0
94d60637062e   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_kubernetes-dashboard-6ddd477f4f-4p8sh_kubernetes-dashboard_de53c867-728b-48f6-bb39-045eaf2bec09_0
b74467bba95b   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_storage-provisioner_kube-system_181f6519-9006-4a3a-b418-4d65b977e490_0
3a78e003375f   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_coredns-65c54cc984-xwd9d_kube-system_5cb214a9-69b9-4a84-aa01-b9692612f325_0
9326f0996f63   b46c42588d51                                                    "/usr/local/bin/kube…"   4 minutes ago   Up 4 minutes             k8s_kube-proxy_kube-proxy-fcxwx_kube-system_07bab572-4281-4d3b-aa2d-2b3572cb31be_1
365a23f10853   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_kube-proxy-fcxwx_kube-system_07bab572-4281-4d3b-aa2d-2b3572cb31be_0
dca753cd4aa7   71d575efe628                                                    "kube-scheduler --au…"   4 minutes ago   Up 4 minutes             k8s_kube-scheduler_kube-scheduler-minikube_kube-system_caa84024ea92a00a01118194f34ff1d9_1
06d157a944d2   25f8c7f3da61                                                    "etcd --advertise-cl…"   4 minutes ago   Up 4 minutes             k8s_etcd_etcd-minikube_kube-system_4a189f43677546bc364d72a08374a541_1
64bce00be335   f51846a4fd28                                                    "kube-controller-man…"   4 minutes ago   Up 4 minutes             k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_a421b494cb0ac9be23d916f3d3c95c7f_1
e9f9a677f0ca   b6d7abedde39                                                    "kube-apiserver --ad…"   4 minutes ago   Up 4 minutes             k8s_kube-apiserver_kube-apiserver-minikube_kube-system_18b11e66586c2fba1425b6e15d707f12_1
675d30494bb0   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_etcd-minikube_kube-system_4a189f43677546bc364d72a08374a541_0
d5cc0f985c68   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_kube-scheduler-minikube_kube-system_caa84024ea92a00a01118194f34ff1d9_0
01af4298a836   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_kube-controller-manager-minikube_kube-system_a421b494cb0ac9be23d916f3d3c95c7f_0
bd9371112351   registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.6   "/pause"                 4 minutes ago   Up 4 minutes             k8s_POD_kube-apiserver-minikube_kube-system_18b11e66586c2fba1425b6e15d707f12_0

暂停 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

输出:

|-----------------------------|----------|--------------|--------------------------------|
|         ADDON NAME          | PROFILE  |    STATUS    |           MAINTAINER           |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador                  | minikube | disabled     | third-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     | third-party (elastic)          |
| freshpod                    | minikube | disabled     | google                         |
| gcp-auth                    | minikube | disabled     | google                         |
| gvisor                      | minikube | disabled     | google                         |
| helm-tiller                 | minikube | disabled     | third-party (helm)             |
| ingress                     | minikube | disabled     | unknown (third-party)          |
| ingress-dns                 | minikube | disabled     | google                         |
| istio                       | minikube | disabled     | third-party (istio)            |
| istio-provisioner           | minikube | disabled     | third-party (istio)            |
| kubevirt                    | minikube | disabled     | third-party (kubevirt)         |
| logviewer                   | minikube | disabled     | unknown (third-party)          |
| metallb                     | minikube | disabled     | third-party (metallb)          |
| metrics-server              | minikube | disabled     | kubernetes                     |
| nvidia-driver-installer     | minikube | disabled     | google                         |
| nvidia-gpu-device-plugin    | minikube | disabled     | third-party (nvidia)           |
| olm                         | minikube | disabled     | third-party (operator          |
|                             |          |              | framework)                     |
| pod-security-policy         | minikube | disabled     | unknown (third-party)          |
| portainer                   | minikube | disabled     | portainer.io                   |
| registry                    | minikube | disabled     | google                         |
| registry-aliases            | minikube | disabled     | unknown (third-party)          |
| registry-creds              | minikube | disabled     | third-party (upmc enterprises) |
| storage-provisioner         | minikube | enabled ✅   | google                         |
| storage-provisioner-gluster | minikube | disabled     | unknown (third-party)          |
| 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

阿里镜像

https://github.com/AliyunContainerService/minikube

Views: 3,207 · Posted: 2022-03-27

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh