minikube可以快速的在macOS、Linux和Windows上搭建本地的Kubernetes集群,帮助Kubernetes小白快速上手。
需要准备好容器/虚拟机管理器,比如Docker,Podman等,本文使用Docker。
要在RHEL安装Docker,可以参考官网( https://docs.docker.com/engine/install/centos
),也可以参考我另一篇文档( https://blog.csdn.net/duke_ding2/article/details/135208607
)。
打开浏览器,访问 https://minikube.sigs.k8s.io/docs/start
,选择适当的选项:
curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
sudo install minikube-linux-amd64 /usr/local/bin/minikube
分别运行这两条命令,下载并安装minikube。
minikube start
报错如下:
$ minikube start
minikube v1.32.0 on Redhat 9.3
✨ Automatically selected the docker driver. Other choices: none, ssh
⛔ Exiting due to RSRC_INSUFFICIENT_CONTAINER_MEMORY: docker only has 1731MiB available, less than the required 1800MiB for Kubernetes
看起来是内存不够用:
$ free -m
total used free shared buff/cache available
Mem: 1731 1339 114 17 445 392
Swap: 2051 200 1851
我使用的是虚拟机,内存是2GB。加大到3GB:
$ free -m
total used free shared buff/cache available
Mem: 2755 1436 1055 18 499 1318
Swap: 2051 200 1851
再次尝试启动minikube:
$ minikube start
minikube v1.32.0 on Redhat 9.3
✨ Automatically selected the docker driver. Other choices: ssh, none
The requested memory allocation of 2200MiB does not leave room for system overhead (total system memory: 2755MiB). You may face stability issues.
Suggestion: Start minikube with less memory allocated: 'minikube start --memory=2200mb'
Using Docker driver with root privileges
Starting control plane node minikube in cluster minikube
Pulling base image ...
Downloading Kubernetes v1.28.3 preload ...
> preloaded-images-k8s-v18-v1...: 403.35 MiB / 403.35 MiB 100.00% 16.12 M
> index.docker.io/kicbase/sta...: 453.89 MiB / 453.90 MiB 100.00% 1.51 Mi
❗ minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.42, but successfully downloaded docker.io/kicbase/stable:v0.0.42 as a fallback image
Creating docker container (CPUs=2, Memory=2200MB) ...
Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
Configuring bridge CNI (Container Networking Interface) ...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
Verifying Kubernetes components...
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
这次启动成功了,但提示说3GB内存还是不太够用,后来我把虚拟机内存增大到了4GB,就不再警告了。
另外,minikube启动特别慢,因为要pull image。为了提高效率,可以指定国内镜像:
minikube start --image-mirror-country='cn'
本文中,没有使用国内镜像。
输出里还有一个消息,说是没找到 kubectl
,有两种解决办法:
minikube kubectl --
来代替。为了省事,可以设置别名:alias kubectl="minikube kubectl --"
kubectl
:curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
注:如果下载太慢,可以直接找一个现成的。
我使用的第二种方法。
查看 kubectl
版本:
$ kubectl version
Client Version: v1.29.0
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.3
通过 kubectl
,就可以和集群交互了,比如:
$ kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-5dd5756b68-mlw2h 1/1 Running 1 (14m ago) 16m
kube-system etcd-minikube 1/1 Running 1 (14m ago) 16m
kube-system kube-apiserver-minikube 1/1 Running 1 (12m ago) 16m
kube-system kube-controller-manager-minikube 1/1 Running 1 (14m ago) 16m
kube-system kube-proxy-7n9sj 1/1 Running 1 (14m ago) 16m
kube-system kube-scheduler-minikube 1/1 Running 1 (14m ago) 16m
kube-system storage-provisioner 1/1 Running 3 (12m ago) 16m
$ kubectl get deployment -A
NAMESPACE NAME READY UP-TO-DATE AVAILABLE AGE
kube-system coredns 1/1 1 1 17m
(注:如果Linux服务器没有安装图形界面,而且在客户端浏览器也无法直接访问服务器的私有IP地址,则可以通过正向或反向代理,在客户端的浏览器访问服务器的私有IP地址,具体操作可参见我另一篇文档 https://blog.csdn.net/duke_ding2/article/details/135627263
。)
启动dashboard:
$ minikube dashboard
Enabling dashboard ...
▪ Using image docker.io/kubernetesui/dashboard:v2.7.0
▪ Using image docker.io/kubernetesui/metrics-scraper:v1.0.8
Some dashboard features require the metrics-server addon. To enable all features please run:
minikube addons enable metrics-server
Verifying dashboard health ...
Launching proxy ...
Verifying proxy health ...
Opening http://127.0.0.1:35853/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
注意:由于连接国外网络问题,会花很长时间。在等待的时候,可以在另一个终端窗口查看pod:
$ kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-5dd5756b68-mlw2h 1/1 Running 1 (18m ago) 20m
kube-system etcd-minikube 1/1 Running 1 (19m ago) 20m
kube-system kube-apiserver-minikube 1/1 Running 1 (17m ago) 20m
kube-system kube-controller-manager-minikube 1/1 Running 1 (19m ago) 20m
kube-system kube-proxy-7n9sj 1/1 Running 1 (19m ago) 20m
kube-system kube-scheduler-minikube 1/1 Running 1 (19m ago) 20m
kube-system storage-provisioner 1/1 Running 3 (17m ago) 20m
kubernetes-dashboard dashboard-metrics-scraper-7fd5cb4ddc-fvk8z 1/1 Running 0 2m29s
kubernetes-dashboard kubernetes-dashboard-8694d4445c-tljmm 0/1 ContainerCreating 0 2m29s
可见,还在创建容器。
查看该pod:
$ kubectl describe pod kubernetes-dashboard-8694d4445c-tljmm -n kubernetes-dashboard
......
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m18s default-scheduler Successfully assigned kubernetes-dashboard/kubernetes-dashboard-8694d4445c-tljmm to minikube
Normal Pulling 3m18s kubelet Pulling image "docker.io/kubernetesui/dashboard:v2.7.0@sha256:2e500d29e9d5f4a086b908eb8dfe7ecac57d2ab09d65b24f588b1d449841ef93"
可见,还在pull image。
最终,会从命令行自动启动浏览器,打开dashboard:
在命令行按“Ctrl + C”停止dashboard。
注意:按“Ctrl + C”停止进程后,dashboard的pod还在:
kubectl get pod -n kubernetes-dashboard
NAME READY STATUS RESTARTS AGE
dashboard-metrics-scraper-7fd5cb4ddc-fvk8z 1/1 Running 0 19m
kubernetes-dashboard-8694d4445c-tljmm 1/1 Running 0 19m
当下次再启动dashboard时,就会非常快。
如果不想在命令行自动启动浏览器,可以使用 --url
选项:
$ minikube dashboard --url
Verifying dashboard health ...
Launching proxy ...
Verifying proxy health ...
http://127.0.0.1:33181/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
然后手工打开浏览器,访问提供的URL,也是一样的。
注意:默认情况下,dashboard只在内部Kubernetes虚拟网络里可以访问,从 minikube dashboard
的输出里可以看到,创建了一个临时的代理,所以我们在Kubernetes虚拟网络的外部可以访问dashboard。
$ kubectl create deployment hello-node --image=registry.k8s.io/e2e-test-images/agnhost:2.39 -- /agnhost netexec --http-port=8080
deployment.apps/hello-node created
命令立即返回结果,但实际上还并没有完成创建。
注:可以用 kubectl create deployment --help
查看帮助。
查看deployment:
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
hello-node 0/1 1 0 44s
查看pod:
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-node-ccf4b9788-hzgrk 0/1 ErrImagePull 0 98s
查看该pod:
$ kubectl describe pod hello-node-ccf4b9788-hzgrk
......
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 7m27s default-scheduler Successfully assigned default/hello-node-ccf4b9788-hzgrk to minikube
Warning Failed 6m11s (x2 over 6m56s) kubelet Failed to pull image "registry.k8s.io/e2e-test-images/agnhost:2.39": Error response from daemon: Head "https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/e2e-test-images/agnhost/manifests/2.39": dial tcp 64.233.188.82:443: i/o timeout
Warning Failed 3m52s (x4 over 6m56s) kubelet Error: ErrImagePull
Warning Failed 3m52s (x2 over 5m14s) kubelet Failed to pull image "registry.k8s.io/e2e-test-images/agnhost:2.39": Error response from daemon: Head "https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/e2e-test-images/agnhost/manifests/2.39": dial tcp 108.177.125.82:443: i/o timeout
Warning Failed 3m39s (x6 over 6m55s) kubelet Error: ImagePullBackOff
Normal BackOff 3m27s (x7 over 6m55s) kubelet Back-off pulling image "registry.k8s.io/e2e-test-images/agnhost:2.39"
Normal Pulling 2m21s (x5 over 7m27s) kubelet Pulling image "registry.k8s.io/e2e-test-images/agnhost:2.39"
registry.k8s.io
连接不上,I/O超时了。
删除deployment:
kubectl delete deployments hello-node
注意:会连同pod一起删除。
本文采用了一个变通的方法:
registry.k8s.io
的机器上,把 registry.k8s.io/e2e-test-images/agnhost:2.39
pull下来:docker pull registry.k8s.io/e2e-test-images/agnhost:2.39
docker login
docker tag xxxxxxx kaiding1/agnhost:2.39
docker login
docker push kaiding1/agnhost:2.39
这样,就能从dockerhub把它pull下来了。
再次尝试创建deployment:
kubectl create deployment hello-node --image=kaiding1/agnhost:2.39 -- /agnhost netexec --http-port=8080
大约几分钟后,就部署好了。
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
hello-node 1/1 1 1 17m
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-node-5f85cbcdcb-knbcm 1/1 Running 0 17m
$ kubectl get events
LAST SEEN TYPE REASON OBJECT MESSAGE
......
18m Normal Scheduled pod/hello-node-5f85cbcdcb-knbcm Successfully assigned default/hello-node-5f85cbcdcb-knbcm to minikube
18m Normal Pulling pod/hello-node-5f85cbcdcb-knbcm Pulling image "kaiding1/agnhost:2.39"
12m Normal Pulled pod/hello-node-5f85cbcdcb-knbcm Successfully pulled image "kaiding1/agnhost:2.39" in 5m59.928s (5m59.928s including waiting)
12m Normal Created pod/hello-node-5f85cbcdcb-knbcm Created container agnhost
12m Normal Started pod/hello-node-5f85cbcdcb-knbcm Started container agnhost
......
18m Normal ScalingReplicaSet deployment/hello-node Scaled up replica set hello-node-5f85cbcdcb to 1
$ kubectl config view
apiVersion: v1
clusters:
- cluster:
certificate-authority: /home/ding/.minikube/ca.crt
extensions:
- extension:
last-update: Mon, 15 Jan 2024 15:05:08 CST
provider: minikube.sigs.k8s.io
version: v1.32.0
name: cluster_info
server: https://192.168.49.2:8443
name: minikube
contexts:
- context:
cluster: minikube
extensions:
- extension:
last-update: Mon, 15 Jan 2024 15:05:08 CST
provider: minikube.sigs.k8s.io
version: v1.32.0
name: context_info
namespace: default
user: minikube
name: minikube
current-context: minikube
kind: Config
preferences: {}
users:
- name: minikube
user:
client-certificate: /home/ding/.minikube/profiles/minikube/client.crt
client-key: /home/ding/.minikube/profiles/minikube/client.key
$ kubectl logs hello-node-5f85cbcdcb-knbcm
I0115 09:32:18.393297 1 log.go:195] Started HTTP server on port 8080
I0115 09:32:18.394281 1 log.go:195] Started UDP server on port 8081
默认情况下,只能在Kubernetes集群里通过内部IP地址访问pod。要想在Kubernetes虚拟网络之外访问 hello-node
容器,需要把pod暴露为Kubernetes的service。
$ kubectl expose deployment hello-node --type=LoadBalancer --port=8080
service/hello-node exposed
其中, --type=LoadBalancer
选项表示把service暴露到集群之外。
该测试image里的应用代码只监听TCP 8080端口。如果使用 kubectl expose
命令暴露到一个不同的端口,则客户端无法连接到该端口。
查看service:
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node LoadBalancer 10.98.67.193 8080:30161/TCP 3m39s
kubernetes ClusterIP 10.96.0.1 443/TCP 175m
在支持负载均衡的云里,会provision一个外部IP地址来访问service。而对于minikube, minikube service
命令的 LoadBalancer
类型使得service可被外部访问。
$ minikube service hello-node
|-----------|------------|-------------|---------------------------|
| NAMESPACE | NAME | TARGET PORT | URL |
|-----------|------------|-------------|---------------------------|
| default | hello-node | 8080 | http://192.168.49.2:30161 |
|-----------|------------|-------------|---------------------------|
Opening service default/hello-node in default browser...
会自动打开浏览器,访问service:
同理,也可以加上 --url
选项,只显示URL,不打开浏览器。
$ minikube service hello-node --url
http://192.168.49.2:32623
此外,还可以使用 minikube tunnel
命令为deployment创建一个routable IP(我理解就是public IP)。
在另外一个终端窗口,运行:
$ minikube tunnel
[sudo] password for ding:
Status:
machine: minikube
pid: 14161
route: 10.96.0.0/12 -> 192.168.49.2
minikube: Running
services: [hello-node]
errors:
minikube: no errors
router: no errors
loadbalancer emulator: no errors
然后再查看service:
$ kubectl get service hello-node
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-node LoadBalancer 10.106.63.28 10.106.63.28 8080:32623/TCP 6m48s
现在, EXTERNAL-IP
有值了。
可使用该IP地址加8080端口访问hello-node应用:
minikube包含了一套内建的addon。这些addon可以在本地Kubernetes环境里被启用、禁用、打开。
$ minikube addons list
|-----------------------------|----------|--------------|--------------------------------|
| ADDON NAME | PROFILE | STATUS | MAINTAINER |
|-----------------------------|----------|--------------|--------------------------------|
| ambassador | minikube | disabled | 3rd party (Ambassador) |
| auto-pause | minikube | disabled | minikube |
| cloud-spanner | 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 | minikube |
| headlamp | minikube | disabled | 3rd party (kinvolk.io) |
| helm-tiller | minikube | disabled | 3rd party (Helm) |
| inaccel | minikube | disabled | 3rd party (InAccel |
| | | | [[email protected]]) |
| ingress | minikube | disabled | Kubernetes |
| ingress-dns | minikube | disabled | minikube |
| inspektor-gadget | minikube | disabled | 3rd party |
| | | | (inspektor-gadget.io) |
| istio | minikube | disabled | 3rd party (Istio) |
| istio-provisioner | minikube | disabled | 3rd party (Istio) |
| kong | minikube | disabled | 3rd party (Kong HQ) |
| kubeflow | minikube | disabled | 3rd party |
| kubevirt | minikube | disabled | 3rd party (KubeVirt) |
| logviewer | minikube | disabled | 3rd party (unknown) |
| metallb | minikube | disabled | 3rd party (MetalLB) |
| metrics-server | minikube | disabled | Kubernetes |
| nvidia-device-plugin | minikube | disabled | 3rd party (NVIDIA) |
| nvidia-driver-installer | minikube | disabled | 3rd party (Nvidia) |
| 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 | 3rd party (Portainer.io) |
| registry | minikube | disabled | minikube |
| registry-aliases | minikube | disabled | 3rd party (unknown) |
| registry-creds | minikube | disabled | 3rd party (UPMC Enterprises) |
| storage-provisioner | minikube | enabled ✅ | minikube |
| storage-provisioner-gluster | minikube | disabled | 3rd party (Gluster) |
| storage-provisioner-rancher | minikube | disabled | 3rd party (Rancher) |
| volumesnapshots | minikube | disabled | Kubernetes |
|-----------------------------|----------|--------------|--------------------------------|
例如,要启用 metrics-server
:
$ minikube addons enable metrics-server
metrics-server is an addon maintained by Kubernetes. For any concerns contact minikube on GitHub.
You can view the list of minikube maintainers at: https://github.com/kubernetes/minikube/blob/master/OWNERS
▪ Using image registry.k8s.io/metrics-server/metrics-server:v0.6.4
The 'metrics-server' addon is enabled
虽然返回消息说已经启用了,但查看pod和service:
$ kubectl get pod,svc -n kube-system
NAME READY STATUS RESTARTS AGE
pod/coredns-5dd5756b68-mlw2h 1/1 Running 1 (3h21m ago) 3h23m
pod/etcd-minikube 1/1 Running 1 (3h21m ago) 3h23m
pod/kube-apiserver-minikube 1/1 Running 1 (3h20m ago) 3h23m
pod/kube-controller-manager-minikube 1/1 Running 1 (3h21m ago) 3h23m
pod/kube-proxy-7n9sj 1/1 Running 1 (3h21m ago) 3h23m
pod/kube-scheduler-minikube 1/1 Running 1 (3h21m ago) 3h23m
pod/metrics-server-7c66d45ddc-2kqpn 0/1 ImagePullBackOff 0 55s
pod/storage-provisioner 1/1 Running 3 (3h19m ago) 3h23m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kube-dns ClusterIP 10.96.0.10 53/UDP,53/TCP,9153/TCP 3h23m
service/metrics-server ClusterIP 10.98.36.138 443/TCP 55s
可见,多了 metrics-server-7c66d45ddc-2kqpn
pod,但是没有启起来。
$ kubectl describe pod metrics-server-7c66d45ddc-2kqpn
......
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 102s default-scheduler Successfully assigned kube-system/metrics-server-7c66d45ddc-2kqpn to minikube
Warning Failed 28s (x2 over 70s) kubelet Failed to pull image "registry.k8s.io/metrics-server/metrics-server:v0.6.4@sha256:ee4304963fb035239bb5c5e8c10f2f38ee80efc16ecbdb9feb7213c17ae2e86e": Error response from daemon: Get "https://us-west2-docker.pkg.dev/v2/k8s-artifacts-prod/images/metrics-server/metrics-server/manifests/sha256:ee4304963fb035239bb5c5e8c10f2f38ee80efc16ecbdb9feb7213c17ae2e86e": dial tcp 108.177.125.82:443: i/o timeout
Warning Failed 28s (x2 over 70s) kubelet Error: ErrImagePull
Normal BackOff 15s (x2 over 70s) kubelet Back-off pulling image "registry.k8s.io/metrics-server/metrics-server:v0.6.4@sha256:ee4304963fb035239bb5c5e8c10f2f38ee80efc16ecbdb9feb7213c17ae2e86e"
Warning Failed 15s (x2 over 70s) kubelet Error: ImagePullBackOff
Normal Pulling 4s (x3 over 102s) kubelet Pulling image "registry.k8s.io/metrics-server/metrics-server:v0.6.4@sha256:ee4304963fb035239bb5c5e8c10f2f38ee80efc16ecbdb9feb7213c17ae2e86e"
又是 registry.k8s.io
的网络问题。
$ kubectl describe deployment metrics-server -n kube-system
......
Image: registry.k8s.io/metrics-server/metrics-server:v0.6.4@sha256:ee4304963fb035239bb5c5e8c10f2f38ee80efc16ecbdb9feb7213c17ae2e86e
还是用老方法,先在能访问 registry.k8s.io
的机器上把image pull下来,然后再push到docker hub,具体做法参见上面的例子。
接下来, kubectl edit deployment
修改 metrics-server
的源:
kubectl edit deployment metrics-server -n kube-system
找到:
image: registry.k8s.io/metrics-server/metrics-server:v0.6.4@sha256:ee4304963fb035239bb5c5e8c10f2f38ee80efc16ecbdb9feb7213c17ae2e86e
改为:
image: kaiding1/metrics-server:v0.6.4@sha256:7726dcf079af5d81d69797ee9c01d667b27e4bb3318ad51b87e23c732d047b55
注意:digest不一样,说明二者并不是完全一样的。
保存退出,pod就会自动重建:
$ kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-5dd5756b68-mlw2h 1/1 Running 1 (4h34m ago) 4h35m
etcd-minikube 1/1 Running 1 (4h34m ago) 4h36m
kube-apiserver-minikube 1/1 Running 1 (4h32m ago) 4h36m
kube-controller-manager-minikube 1/1 Running 1 (4h34m ago) 4h36m
kube-proxy-7n9sj 1/1 Running 1 (4h34m ago) 4h35m
kube-scheduler-minikube 1/1 Running 1 (4h34m ago) 4h36m
metrics-server-5c7d7988f6-9csdf 0/1 ContainerCreating 0 9s
metrics-server-b48d8d5fb-h86xr 0/1 ImagePullBackOff 0 7m16s
storage-provisioner 1/1 Running 3 (4h32m ago) 4h36m
大约几分钟后,pod起来了。
$ kubectl get pod,svc -n kube-system
NAME READY STATUS RESTARTS AGE
pod/coredns-5dd5756b68-mlw2h 1/1 Running 1 (4h42m ago) 4h44m
pod/etcd-minikube 1/1 Running 1 (4h42m ago) 4h44m
pod/kube-apiserver-minikube 1/1 Running 1 (4h41m ago) 4h44m
pod/kube-controller-manager-minikube 1/1 Running 1 (4h42m ago) 4h44m
pod/kube-proxy-7n9sj 1/1 Running 1 (4h42m ago) 4h44m
pod/kube-scheduler-minikube 1/1 Running 1 (4h42m ago) 4h44m
pod/metrics-server-5c7d7988f6-9csdf 1/1 Running 0 8m17s
pod/storage-provisioner 1/1 Running 3 (4h40m ago) 4h44m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kube-dns ClusterIP 10.96.0.10 53/UDP,53/TCP,9153/TCP 4h44m
service/metrics-server ClusterIP 10.98.36.138 443/TCP 81m
1/1 Running 3 (4h38m ago) 4h42m
还有一个办法,就是打开 hub.docker.com
,搜索对应的image metrics-server:v0.6.4
:
如果找到合适的image,也可以直接用。
启用 metrics-server
后,就可以查看资源消耗情况了,比如:
$ kubectl top pods
NAME CPU(cores) MEMORY(bytes)
hello-node-5f85cbcdcb-knbcm 1m 11Mi
最后,禁用 metrics-server
:
$ minikube addons disable metrics-server
"The 'metrics-server' addon is disabled
kubectl delete service hello-node
kubectl delete deployment hello-node
minikube stop
minikube delete
https://kubernetes.io/docs/tutorials/hello-minikube
https://minikube.sigs.k8s.io/docs/start
https://blog.csdn.net/heiwa110/article/details/127614981
https://blog.csdn.net/icanflyingg/article/details/126370832