minikube 可以在个人电脑(包括Windows、macOS 和 Linux)上运行一个一体化或多节点的本地 Kubernetes 集群,以便试用 Kubernetes,或用于日常开发工作。
物理机配置:Thinkpad E450 16GRam 256SSD,操作系统ubuntu 22.04
andy@ThinkPad:~$ lsb_release -d
Description: Ubuntu 22.04.4 LTS
略过环境的准备,可参考
Install Minikube on Ubuntu Linux for Easy Kubernetes Development - The New Stack
Minikube 版本
andy@ThinkPad:~$ minikube version
minikube version: v1.32.0
commit: 8220a6eb95f0a4d75f7f2d7b14cef975f050512d
Minikube启动
andy@ThinkPad:~$ minikube start --driver=docker --cpus=2 --memory=8192
....
🐳 Preparing Kubernetes v1.28.3 on Docker 24.0.7 ...
▪ env NO_PROXY=localhost,127.0.0.1,::1
▪ 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
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
andy@ThinkPad:~$ kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane 54s v1.28.3
andy@ThinkPad:~$ kubectl cluster-info
Kubernetes control plane is running at https://192.168.49.2:8443
CoreDNS is running at https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
andy@ThinkPad:~$ kubectl get namespace kube-system
NAME STATUS AGE
kube-system Active 112m
andy@ThinkPad:~$ kubectl get pods --namespace kube-system
NAME READY STATUS RESTARTS AGE
coredns-5dd5756b68-m768r 1/1 Running 0 112m
etcd-minikube 1/1 Running 0 112m
kube-apiserver-minikube 1/1 Running 0 112m
kube-controller-manager-minikube 1/1 Running 0 112m
kube-proxy-rk892 1/1 Running 0 112m
kube-scheduler-minikube 1/1 Running 0 112m
storage-provisioner 1/1 Running 1 (111m ago) 112m
andy@ThinkPad:~$
创建svc nginx
andy@ThinkPad:~$ kubectl create deployment nginx-web --image=nginx
deployment.apps/nginx-web created
andy@ThinkPad:~$ kubectl expose deployment nginx-web --type NodePort --port=80
service/nginx-web exposed
andy@ThinkPad:~$ kubectl get deployment,pod,svc
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nginx-web 0/1 1 0 22s
NAME READY STATUS RESTARTS AGE
pod/nginx-web-5b757f798d-tsrx5 0/1 ContainerCreating 0 22s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 94s
service/nginx-web NodePort 10.100.29.187 <none> 80:32156/TCP 9s
安装附加组件
Minkube 还包含许多扩展功能集的附加组件,例如入口、度量服务器和仪表板。要了解有哪些附加组件可用,请执行以下命令:
To find out what add-ons are available, issue the command:
$ minikube addons list
Let’s say you want to add the Dashboard add-on, which can be achieved with the command:
$ minikube addons enable dashboard
或
$ minikube addons enable dashboard --alsologtostderr
查看namespaces所有的pod
andy@ThinkPad:~$ kubectl get pods -A
安装Ingress-Nginx插件
国内的网络访问扩展镜像超时,并无法拉取ingress-nginx
配置proxy,这个问题没有解决。后续配置proxy可以解决了这个问题的话,再更新。
❗ This VM is having trouble accessing https://k8s.gcr.io
💡 To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
处理方法:Minikube安装ingress插件的有效方法 - 掘金
之后将成功启用ingress-nginx插件
andy@ThinkPad:~$ kubectl get pods -o wide --namespace ingress-nginx
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
ingress-nginx-admission-create-wf4pz 0/1 Completed 0 46m 10.244.0.7 minikube <none> <none>
ingress-nginx-admission-patch-6bg5b 0/1 Completed 1 46m 10.244.0.6 minikube <none> <none>
ingress-nginx-controller-654495b6dc-lz97f 1/1 Running 0 46m 10.244.0.8 minikube <none> <none>
andy@ThinkPad:~$
访问仪表板
这将启用仪表盘插件,并在默认网络浏览器中打开代理。
值得注意的是,网络浏览器通常无法以根用户身份正常运行,因此如果你是在以根用户身份运行的环境中,请查看仅 URL 选项。
andy@ThinkPad:~$ minikube dashboard
🤔 Verifying dashboard health ...
🚀 Launching proxy ...
🤔 Verifying proxy health ...
🎉 Opening http://127.0.0.1:37357/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
要停止代理(让仪表盘继续运行),请中止已启动的进程 (Ctrl+C)。
只获取仪表板 URL
如果不想打开网页浏览器,dashboard 命令也可以只发出一个 URL:
andy@ThinkPad:~$ minikube dashboard --url