Minikube 常用 CLI 命令详解(CentOS 8)
Minikube v1.39.0 常用 CLI 命令详解(CentOS 8):给出 start/stop/delete/status/node/addons/tunnel 等子命令帮助回显、参数与示例,附 FAQ,实测验证通过。
Minikube 常用 CLI 命令详解(CentOS 8)
目标:详解 minikube v1.39.0 在 CentOS 8 上的常用命令与参数,覆盖
start/stop/delete/status/ssh/kubectl/service/dashboard/addons/node/profile/config/image/logs/ip/version/update-context各子命令的--help回显、真实默认值与独立可执行的示例命令,并附配套kubectl运维命令速查。文中命令与回显在 CentOS 8.4 + minikube v1.39.0 + Kubernetes v1.37.0 实测通过。
一、环境信息
- 操作系统:CentOS Linux release 8.4.2105 / x86_64(内核 6.8.0-138-generic)
- minikube:v1.39.0(commit 7a9f6a841470a207de8cf4bafcccee0969d8ba10,二进制位于 /usr/local/bin/minikube)
- kubectl:v1.37.0(Kustomize v5.8.1);Kubernetes:v1.37.0
- 驱动:docker;节点承载基础镜像 kicbase v0.0.51;节点内运行时 containerd 2.3.4
- 集群:单节点 control-plane,节点名 minikube,节点 IP 192.168.49.2
- kubeconfig context:minikube;示例账号:root(示例密码 q1w2e3r4)
二、minikube 主命令与全局参数
minikube 是单二进制 CLI,通过子命令完成集群的创建、查询、删除与节点操作。本环境实测可用的常用子命令:
| 子命令 | 用途 |
|---|---|
start | 启动本地 Kubernetes 集群 |
stop | 停止集群(保留数据) |
delete | 删除集群与本地数据 |
status | 查看集群与节点状态 |
ssh | 登录节点或在其上执行命令 |
kubectl | 调用与集群版本匹配的 kubectl |
service | 获取并访问 Service 的 URL |
dashboard | 访问集群内的 Kubernetes Dashboard |
addons | 管理 addons(启用/禁用/列表) |
node | 节点增删启停与列表 |
profile | 管理多个 minikube 集群 profile |
config | 读写 minikube 配置 |
image | 镜像构建/导入/拉取/加载 |
cache | 镜像本地缓存管理 |
logs | 查看节点日志 |
ip | 获取节点 IP |
version | 打印 minikube 版本 |
update-context | 校验并修正 kubeconfig 中的 IP |
所有子命令共用的全局参数(从 --help 回显确认):
| 参数 | 说明 | 默认值 |
|---|---|---|
--alsologtostderr | 同时把日志输出到 stderr | false |
--log_file | 日志文件路径 | 无(输出到 stderr) |
--v int | 日志详细级别,值越大输出越多 | 0 |
-p, --profile string | 指定操作的 profile(集群)名 | minikube |
三、minikube start:启动集群
3.1 帮助回显(节选)
minikube start --help
实测回显(节选常用参数):
Starts a local Kubernetes cluster
Options:
-c, --container-runtime='':
The container runtime to be used. Valid options: docker, cri-o, containerd (default: auto)
--cpus='2':
Number of CPUs allocated to Kubernetes. Use "max" to use the maximum number of CPUs. Use "no-limit" to not specify a limit (Docker/Podman only)
--disk-size='20000mb':
Disk size allocated to the minikube VM (format: <number>[<unit>], where unit = b, k, m or g).
-d, --driver='':
Driver is one of: virtualbox, kvm2, qemu2, qemu, vmware, none, docker, podman, ssh (defaults to auto-detect)
--image-mirror-country='':
Country code of the image mirror to be used. Leave empty to use the global one. For Chinese mainland users, set it to cn.
--kubernetes-version='':
The Kubernetes version that the minikube VM will use (ex: v1.2.3, 'stable' for v1.37.0, 'latest' for v1.37.0). Defaults to 'stable'.
-m, --memory='':
Amount of RAM to allocate to Kubernetes (format: <number>[<unit>], where unit = b, k, m or g). Use "max" to use the maximum amount of memory. Use "no-limit" to not specify a limit (Docker/Podman only)
-n, --nodes=1:
The total number of nodes to spin up. Defaults to 1.
--service-cluster-ip-range='10.96.0.0/12':
The CIDR to be used for service cluster IPs.
--wait-timeout=6m0s:
max time to wait per Kubernetes or host to be healthy.
--binary-mirror='':
Location to fetch kubectl, kubelet, & kubeadm binaries from.
Usage:
minikube start [flags] [options]
3.2 常用参数表
| 参数 | 说明 | 真实默认值 |
|---|---|---|
-c, --container-runtime | 节点内运行时,取值 docker / cri-o / containerd | auto |
--driver / -d | 承载节点的驱动 | auto-detect |
--cpus | 分配给集群的 CPU 数 | 2 |
-m, --memory | 分配给集群的内存 | 空(按驱动默认,本环境节点分配 2200MB) |
--disk-size | 分配给集群的磁盘 | 20000mb |
-n, --nodes | 启动节点总数 | 1 |
--kubernetes-version | 引导的 Kubernetes 版本 | stable(本环境 v1.37.0) |
--image-mirror-country | 组件镜像镜像站国家码(中国大陆填 cn) | 空 |
--image-repository | 组件镜像仓库地址 | 空(cn 时自动为 registry.cn-hangzhou.aliyuncs.com/google_containers) |
--binary-mirror | kubectl/kubelet/kubeadm 引导二进制下载源 | 空(本环境实测 https://dl.k8s.io/release) |
--service-cluster-ip-range | Service 网段 | 10.96.0.0/12 |
--wait-timeout | 等待集群就绪的最长时间 | 6m0s |
--force | 强制执行有风险的操作(如 root 下用 docker 驱动) | false |
3.3 实测启动示例
minikube start --driver=docker --container-runtime=containerd \
--image-mirror-country=cn \
--binary-mirror=https://dl.k8s.io/release
实测回显:
* minikube v1.39.0 on Centos 8.4.2105 (docker/amd64)
* Using the docker driver based on user configuration
* Using image repository registry.cn-hangzhou.aliyuncs.com/google_containers
* Starting "minikube" primary control-plane node in "minikube" cluster
* Pulling base image v0.0.51 ...
* Preparing Kubernetes v1.37.0 on containerd 2.3.4 ...
* Verifying Kubernetes components...
- Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v5
* Enabled addons: default-storageclass, storage-provisioner
* Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
💡 重复启动同一集群时,minikube 复用已有 profile,回显首行由
based on user configuration变为based on existing profile;未指定--kubernetes-version时使用 profile 内已记录的版本(本环境 v1.37.0)。
3.4 指定 Kubernetes 版本与资源
minikube start --kubernetes-version=v1.37.0 --cpus=2 --memory=2200mb --disk-size=20000mb
💡 该命令可在支持足够资源的服务器上引导指定版本;
--kubernetes-version亦可填stable/latest。运行时(containerd/docker/cri-o)不可通过该参数切换,须minikube delete后以新--container-runtime重建。
四、minikube stop / delete / status
4.1 minikube stop
minikube stop --help
实测回显:
Stops a local Kubernetes cluster. This command stops the underlying VM or container, but keeps user data intact. The cluster can be started again with the "start" command.
Options:
--all=false:
Set flag to stop all profiles (clusters)
--keep-context-active=false:
keep the kube-context active after cluster is stopped. Defaults to false.
--schedule=0s:
Set flag to stop cluster after a set amount of time (e.g. --schedule=5m)
实测执行:
minikube stop
* Stopping node "minikube" ...
* Powering off "minikube" via SSH ...
* 1 node stopped.
💡
minikube stop只关闭节点、保留数据;--all一次停止所有 profile;--schedule=5m可定时自动停止。
4.2 minikube delete
minikube delete --help
实测回显:
Deletes a local Kubernetes cluster. This command deletes the VM, and removes all
associated files.
Options:
--all=false:
Set flag to delete all profiles
--purge=false:
Set this flag to delete the '.minikube' folder from your user directory.
示例(删除默认集群并清理配置目录):
minikube delete
minikube delete --all --purge
💡
minikube delete删除当前集群及其节点文件;--all删除全部 profile;--purge连带删除~/.minikube目录。删除后可用minikube profile list确认列表为空。
4.3 minikube status
minikube status --help
实测回显(节选):
Gets the status of a local Kubernetes cluster.
Options:
-n, --node='':
The node to check status for. Defaults to control plane. Leave blank with default format for status on all nodes.
-o, --output='text':
minikube status --output OUTPUT. json, text
-w, --watch=1s:
Continuously listing/getting the status with optional interval duration.
实测执行:
minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
停止后再次执行(实测回显):
minikube
type: Control Plane
host: Stopped
kubelet: Stopped
apiserver: Stopped
kubeconfig: Stopped
💡
host/kubelet/apiserver全Running且kubeconfig: Configured为健康;-o json输出结构化状态,-w 1s持续轮询。
五、minikube ssh 与 minikube kubectl
5.1 minikube ssh
minikube ssh --help
实测回显:
Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'.
Options:
--native-ssh=true:
Use native Golang SSH client (default true).
-n, --node='':
The node to ssh into. Defaults to the primary control plane.
实测执行(查看节点内核与系统标识):
minikube ssh -- uname -r
minikube ssh -- cat /etc/os-release | head -1
6.8.0-138-generic
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
💡 进入交互式节点用
minikube ssh;在节点上执行单条命令用minikube ssh -- <命令>;多节点集群用-n <节点名>指定目标节点。
5.2 minikube kubectl
minikube kubectl --help
实测回显:
Run the Kubernetes client, download it if necessary. Remember -- after kubectl!
This will run the Kubernetes client (kubectl) with the same version as the cluster
Examples:
minikube kubectl -- --help
minikube kubectl -- get pods --namespace kube-system
Options:
--ssh=false:
Use SSH for running kubernetes client on the node
实测执行:
minikube kubectl -- get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready <none> 15m v1.37.0
💡 本机已装 kubectl 时可直接用
kubectl;minikube kubectl --用于本机无 kubectl 时代自动下载并使用与集群版本一致的客户端(注意--分隔)。
六、minikube service 与 minikube dashboard
6.1 minikube service
minikube service --help
实测回显:
Returns the Kubernetes URL(s) for service(s) in your local cluster. In the case of multiple URLs they will be printed one at a time.
Available Commands:
list Lists the URLs for the services in your local cluster
Options:
--all=false:
Forwards all services in a namespace (defaults to "false")
--https=false:
Open the service URL with https instead of http (defaults to "false")
-n, --namespace='default':
The service namespace
--url=false:
Display the Kubernetes service URL in the CLI instead of opening it in the default browser
实测执行(仅打印 URL 便于后续访问):
minikube service nginx-demo --url
http://192.168.49.2:32250
💡
--url只打印访问地址不打开浏览器;不加--url会为 Service 建立隧道并尝试打开浏览器;minikube service list列出命名空间内全部 Service URL。
6.2 minikube dashboard
minikube dashboard --help
实测回显:
Access the Kubernetes dashboard running within the minikube cluster
Options:
--port=0:
Exposed port of the proxyfied dashboard. Set to 0 to pick a random port.
--url=false:
Display dashboard URL instead of opening a browser
示例(仅取 URL):
minikube dashboard --url
💡 首次执行会启用 dashboard addon 并建立代理,
--url打印访问地址而不打开浏览器;--port可固定代理端口。
七、minikube addons
7.1 帮助回显
minikube addons --help
实测回显:
addons modifies minikube addons files using subcommands like "minikube addons enable dashboard"
Available Commands:
configure Configures the addon w/ADDON_NAME within minikube
disable Disables the addon w/ADDON_NAME within minikube
enable Enables the addon w/ADDON_NAME within minikube
images List image names the addon w/ADDON_NAME used
list Lists all available minikube addons as well as their current statuses (enabled/disabled)
open Opens the addon w/ADDON_NAME within minikube
7.2 实测执行(查看启用状态)
minikube addons list
实测回显(仅列出 enabled 项):
│ default-storageclass │ minikube │ enabled ✅ │ Kubernetes │
│ storage-provisioner │ minikube │ enabled ✅ │ minikube │
启用 / 禁用示例:
minikube addons enable ingress
minikube addons disable ingress
💡
default-storageclass与storage-provisioner为 minikube 默认启用项;启用 ingress / dashboard 等 addon 后按其说明访问。addon 的启停不影响已有业务负载。
八、minikube node
8.1 帮助回显
minikube node --help
实测回显:
Operations on nodes
Available Commands:
add Adds a node to the given cluster.
delete Deletes a node from a cluster.
list List nodes.
start Starts a node.
stop Stops a node in a cluster.
8.2 实测执行
minikube node list
minikube 192.168.49.2
💡
minikube node list输出每行「节点名 + IP」;单节点集群仅一行。minikube node add可追加 worker 节点,minikube node delete <节点名>删除节点。
九、minikube profile 与 minikube config
9.1 minikube profile
minikube profile --help
实测回显:
profile sets the current minikube profile, or gets the current profile if no arguments are provided. This is used to run and manage multiple minikube instance. You can return to the default minikube profile by running `minikube profile default`
Available Commands:
list Lists all minikube profiles.
实测执行:
minikube profile list
┌──────────┬────────┬────────────┬──────────────┬─────────┬────────┬───────┬────────────────┬────────────────────┐
│ PROFILE │ DRIVER │ RUNTIME │ IP │ VERSION │ STATUS │ NODES │ ACTIVE PROFILE │ ACTIVE KUBECONTEXT │
├──────────┼────────┼────────────┼──────────────┼─────────┼────────┼───────┼────────────────┼────────────────────┤
│ minikube │ docker │ containerd │ 192.168.49.2 │ v1.37.0 │ OK │ 1 │ * │ * │
└──────────┴────────┴────────────┴──────────────┴─────────┴────────┴───────┴────────────────┴────────────────────┘
💡
minikube profile list汇总所有 profile 的驱动、运行时、IP、版本与状态;minikube profile <名>切换当前 profile。多集群并存时用-p <名>指定操作对象。
9.2 minikube config
minikube config --help
实测回显(节选可配置字段与子命令):
config modifies minikube config files using subcommands like "minikube config set driver kvm2"
* driver
* container-runtime
* cpus
* memory
* kubernetes-version
* insecure-registry
Available Commands:
defaults Lists all valid default values for PROPERTY_NAME
get Gets the value of PROPERTY_NAME from the minikube config file
set Sets an individual value in a minikube config file
unset unsets an individual value in a minikube config file
view Display values currently set in the minikube config file
示例(设置并查看默认驱动):
minikube config set driver docker
minikube config get driver
minikube config view
💡
minikube config持久化到~/.minikube/config/config.json(全局默认值),对之后新建的 profile 生效;已存在 profile 的取值记录在~/.minikube/profiles/<profile>/config.json。详见《Minikube 集群配置文件详解(CentOS 8)》。
十、minikube image 与 minikube cache
10.1 minikube image
minikube image --help
实测回显:
Manage images
Available Commands:
build Build a container image in minikube
load Load an image into minikube
ls List images
pull Pull images
push Push images
rm Remove one or more images
save Save a image from minikube
tag Tag images
实测执行(本环境导入并查看 nginx 镜像):
minikube image load nginx:alpine
minikube image ls | grep nginx
docker.io/library/nginx:alpine
💡
minikube image load把本机 Docker 引擎中的镜像导入节点内 containerd(离线或镜像拉取受限时的有效手段);minikube image pull直接从仓库拉取;minikube image ls列出节点内镜像。
10.2 minikube cache
minikube cache --help
实测回显:
Add an image into minikube as a local cache, or delete, reload the cached images
Available Commands:
add Add an image to local cache.
delete Delete an image from the local cache.
list List all available images from the local cache.
reload reload cached images.
示例:
minikube cache add nginx:alpine
minikube cache list
💡
minikube cache把镜像缓存到~/.minikube/cache/images,供后续集群启动时按--cache-images复用。
十一、minikube logs / ip / version / update-context
11.1 minikube logs
minikube logs --help
实测回显(节选):
Gets the logs of the running instance, used for debugging minikube, not user code.
Options:
--file='':
If present, writes to the provided file instead of stdout.
-f, --follow=false:
Show only the most recent journal entries, and continuously print new entries as they are appended to the journal.
-n, --length=60:
Number of lines back to go within the log
--node='':
The node to get logs from. Defaults to the primary control plane.
--problems=false:
Show only log entries which point to known problems
示例:
minikube logs --length 100
minikube logs --problems
💡
--problems只展示已知问题相关日志,排障首选;--file输出到文件,--node指定多节点环境中的目标节点。
11.2 minikube ip
minikube ip --help
实测回显:
Retrieves the IP address of the specified node, and writes it to STDOUT.
Options:
-n, --node='':
The node to get IP. Defaults to the primary control plane.
实测执行:
minikube ip
192.168.49.2
11.3 minikube version
minikube version --help
实测回显:
Print the version of minikube.
Options:
--components=false:
list versions of all components included with minikube. (the cluster must be running)
-o, --output='':
One of 'yaml' or 'json'.
--short=false:
Print just the version number.
实测执行:
minikube version
minikube version: v1.39.0
commit: 7a9f6a841470a207de8cf4bafcccee0969d8ba10
minikube version --short
v1.39.0
11.4 minikube update-context
minikube update-context --help
实测回显:
Retrieves the IP address of the running cluster, checks it
with IP in kubeconfig, and corrects kubeconfig if incorrect.
💡 集群 IP 变化(如重启后)导致 kubectl 连不上时,执行
minikube update-context自动校正 kubeconfig 中的 IP。
十二、kubectl 配套运维命令速查
minikube 创建集群后通过 kubectl 管理集群(本机 kubectl v1.37.0)。以下命令与回显均为 CentOS 8 实测。
12.1 版本核对
kubectl version
Client Version: v1.37.0
Kustomize Version: v5.8.1
Server Version: v1.37.0
12.2 节点查看
kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
minikube Ready <none> 15m v1.37.0 192.168.49.2 <none> Debian GNU/Linux 12 (bookworm) 6.8.0-138-generic (amd64) containerd://2.3.4
12.3 系统组件 Pod 查看
kubectl get pods -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-6cf5fbd489-lgwkg 1/1 Running 0 8m1s
kube-system coredns-6cf5fbd489-p9s9c 1/1 Running 0 8m1s
kube-system etcd-minikube 1/1 Running 0 14m
kube-system kube-apiserver-minikube 1/1 Running 0 15m
kube-system kube-controller-manager-minikube 1/1 Running 1 (15m ago) 15m
kube-system kube-proxy-hncj6 1/1 Running 0 8m1s
kube-system kube-scheduler-minikube 1/1 Running 0 15m
kube-system storage-provisioner 1/1 Running 1 (7m29s ago) 8m3s
12.4 业务部署与访问验证
kubectl create deployment nginx-demo --image=nginx:alpine
kubectl expose deployment nginx-demo --port=80 --type=NodePort
实测回显:
deployment.apps/nginx-demo created
service/nginx-demo exposed
查看部署状态(实测回显):
kubectl get deployment,svc,pods -o wide
NAME READY UP-TO-DATE AVAILABLE AGE CONTAINERS IMAGES SELECTOR
deployment.apps/nginx-demo 1/1 1 1 20s nginx nginx:alpine app=nginx-demo
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 45m <none>
service/nginx-demo NodePort 10.103.148.183 <none> 80:32250/TCP 20s app=nginx-demo
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
pod/nginx-demo-74b4649967-qfzjd 1/1 Running 0 20s 10.244.0.6 minikube <none> <none>
通过 NodePort 访问验证(实测回显):
curl -s -o /dev/null -w "HTTP:%{http_code}\n" http://192.168.49.2:32250/
HTTP:200
12.5 常用命令速查
kubectl cluster-info # 查看集群信息
kubectl get csr # 查看证书签名请求(应 Approved,Issued)
kubectl describe node minikube # 查看节点详情与资源使用
kubectl logs <pod-name> -n <namespace> # 查看 Pod 日志
kubectl delete deployment nginx-demo # 删除示例部署
kubectl delete svc nginx-demo # 删除示例 Service
十三、注意事项
-p/--profile默认 minikube:多集群并存时,操作前用-p <名>指定目标 profile,避免误操作。minikube start幂等:对已存在集群执行 start 会复用 profile 并校正 kubeconfig,不重建数据。stop与delete的区别:stop保留数据可再 start;delete彻底删除集群与节点文件,不可恢复。- 运行时不可热切换:
--container-runtime仅在集群创建时生效,切换须delete后重建。 - NodePort 端口随机:
kubectl expose --type=NodePort分配的端口(本环境 32250)在服务重建后会变化。 minikube ssh面向节点:节点内系统为 kicbase 基础镜像(Debian 12),与服务器宿主系统(CentOS 8)不同,属正常现象。
十四、常见问题(FAQ)
Q1:minikube kubectl -- get pods 报错提示缺少 --?
定位:minikube kubectl 需用 -- 分隔 minikube 参数与 kubectl 参数。
解决:写成 minikube kubectl -- get pods -A;本机已装 kubectl 时可直接用 kubectl get pods -A。
Q2:minikube start 报 The "docker" driver should not be used with root privileges?
定位:以 root 身份运行 docker 驱动时的安全提示。
解决:改用普通用户(加入 docker 组)执行;确需 root 时追加 --force,或改用 --driver=none。
Q3:镜像拉取失败(Pod 处于 ImagePullBackOff / ErrImagePull)?
定位:docker.io 直连慢或不稳。
解决:用 minikube image load <镜像> 从本机 Docker 引擎导入镜像(实测有效),或在节点内配置 docker.io 镜像加速端点后重启 containerd。
Q4:minikube ip 与 kubectl 连接的地址不一致,kubectl 连不上集群?
定位:集群 IP 变化后 kubeconfig 未同步。
解决:执行 minikube update-context 自动校正 kubeconfig 中的 IP,再执行 kubectl get nodes 复核。
Q5:minikube service 打开浏览器失败(无图形界面服务器)?
定位:默认行为是打开本机浏览器。
解决:加 --url 只打印访问地址,或 minikube service <svc> --url 取得 URL 后用 curl 访问。
十五、参考链接
- minikube 命令参考:https://minikube.sigs.k8s.io/docs/commands/
- minikube 官方文档:https://minikube.sigs.k8s.io/docs/
- minikube 快速开始:https://minikube.sigs.k8s.io/docs/start/
- minikube GitHub Releases:https://github.com/kubernetes/minikube/releases
- kubectl 命令参考:https://kubernetes.io/docs/reference/kubectl/