Minikube Setup Skill
Minikube 搭建指南
- Install Minikube - Follow platform-specific instructions
- Start Minikube - With adequate resources for 3 pods
- Enable Addons - Ingress for external access
- Load Images - Push local images to Minikube registry
- Deploy Application - Apply Kubernetes manifests or Helm chart
- 安装Minikube - 遵循对应平台的安装说明
- 启动Minikube - 分配足够资源以支持3个Pod
- 启用插件 - 启用Ingress以支持外部访问
- 加载镜像 - 将本地镜像推送至Minikube镜像仓库
- 部署应用 - 应用Kubernetes清单文件或Helm Chart
What is Minikube?
什么是Minikube?
Minikube runs a single-node Kubernetes cluster locally for development:
- Local testing - Test K8s manifests without cloud costs
- Fast iteration - Build, deploy, test cycles locally
- Full K8s API - Supports most Kubernetes features
- Cross-platform - Linux, macOS, Windows
Minikube 在本地运行单节点 Kubernetes 集群,用于开发工作:
- 本地测试 - 无需云服务成本即可测试K8s清单文件
- 快速迭代 - 在本地完成构建、部署、测试的循环
- 完整K8s API - 支持大部分Kubernetes功能
- 跨平台 - 支持Linux、macOS、Windows
| Resource | Minimum | Recommended |
|---|
| CPUs | 2 | 4+ |
| Memory | 2GB | 8GB+ |
| Disk | 20GB | 50GB+ |
| Container Runtime | Docker or Podman | Docker |
| 资源 | 最低要求 | 推荐配置 |
|---|
| CPU | 2核 | 4核及以上 |
| 内存 | 2GB | 8GB及以上 |
| 磁盘 | 20GB | 50GB及以上 |
| 容器运行时 | Docker或Podman | Docker |
Using Homebrew
使用Homebrew安装
Or download binary
或下载二进制文件
Using Chocolatey
使用Chocolatey安装
Or download installer from
或从以下链接下载安装程序
Starting Minikube
启动Minikube
Start with defaults (2 CPU, 2GB RAM)
使用默认配置启动(2核CPU,2GB内存)
Start with more resources (recommended for this project)
使用推荐配置启动(适用于本项目)
minikube start --cpus=4 --memory=8192 --disk-size=50gb
minikube start --cpus=4 --memory=8192 --disk-size=50gb
Docker driver (default on most systems)
Docker驱动(多数系统默认)
minikube start --driver=docker
minikube start --driver=docker
minikube start --driver=podman
minikube start --driver=podman
VirtualBox driver
VirtualBox驱动
minikube start --driver=virtualbox
minikube start --driver=virtualbox
With all recommended options
使用所有推荐选项启动
minikube start
--cpus=4
--memory=8192
--disk-size=50gb
--driver=docker
--container-runtime=docker
minikube start
--cpus=4
--memory=8192
--disk-size=50gb
--driver=docker
--container-runtime=docker
Minikube Addons
Minikube 插件
Enable ingress controller
启用Ingress控制器
minikube addons enable ingress
minikube addons enable ingress
kubectl get pods -n ingress-nginx
kubectl get pods -n ingress-nginx
Enable Metrics Server
启用Metrics Server
Enable metrics for HPA
启用指标服务以支持HPA
minikube addons enable metrics-server
minikube addons enable metrics-server
List Available Addons
查看可用插件
See all available addons
查看所有可用插件
minikube addons enable ingress metrics-server registry
minikube addons enable ingress metrics-server registry
Managing Minikube
Minikube 管理
Check cluster status
检查集群状态
type: Control Plane
type: Control Plane
host: Running
host: Running
kubelet: Running
kubelet: Running
apiserver: Running
apiserver: Running
kubeconfig: Configured
kubeconfig: Configured
Start again (preserves state)
重新启动(保留集群状态)
Delete and start fresh
删除集群并重新创建
minikube delete
minikube start
minikube delete
minikube start
Tunnel for External Access
隧道实现外部访问
If NodePort doesn't work
如果NodePort无法正常工作
This runs in foreground - keep separate terminal
此命令在前台运行 - 请使用单独的终端窗口
Loading Images to Minikube
向Minikube加载镜像
Why Load Images?
为什么需要加载镜像?
Minikube cannot access local Docker images by default. You must:
- Build image locally
- Load image into Minikube
- Deploy
Minikube 默认无法访问本地Docker镜像。您需要:
- 在本地构建镜像
- 将镜像加载至Minikube
- 部署应用
minikube image load todo-frontend:latest
minikube image load todo-frontend:latest
Load multiple images
加载多个镜像
minikube image load todo-frontend:latest todo-backend:latest todo-mcp-server:latest
minikube image load todo-frontend:latest todo-backend:latest todo-mcp-server:latest
docker images --format "{{.Repository}}:{{.Tag}}" | grep todo | xargs minikube image load
docker images --format "{{.Repository}}:{{.Tag}}" | grep todo | xargs minikube image load
Image Load Workflow
镜像加载流程
Step 1: Build images
步骤1:构建镜像
docker build -t todo-frontend:latest ./frontend
docker build -t todo-backend:latest ./backend
docker build -t todo-mcp-server:latest -f backend/Dockerfile.mcp ./backend
docker build -t todo-frontend:latest ./frontend
docker build -t todo-backend:latest ./backend
docker build -t todo-mcp-server:latest -f backend/Dockerfile.mcp ./backend
Step 2: Start Minikube
步骤2:启动Minikube
Step 3: Load images
步骤3:加载镜像
minikube image load todo-frontend:latest todo-backend:latest todo-mcp-server:latest
minikube image load todo-frontend:latest todo-backend:latest todo-mcp-server:latest
Applying Kubernetes Manifests
应用Kubernetes清单文件
Apply all manifests
应用所有清单文件
kubectl apply -f k8s/ -n todo-app
kubectl apply -f k8s/ -n todo-app
kubectl apply -f k8s/00-namespace.yaml
kubectl apply -f k8s/01-configmap.yaml
kubectl apply -f k8s/02-secret.yaml
kubectl apply -f k8s/00-namespace.yaml
kubectl apply -f k8s/01-configmap.yaml
kubectl apply -f k8s/02-secret.yaml
Install with values
使用自定义配置安装
helm install todo-app ./helm/todo-app
--namespace todo-app
--create-namespace
-f helm/todo-app/values-dev.yaml
helm install todo-app ./helm/todo-app
--namespace todo-app
--create-namespace
-f helm/todo-app/values-dev.yaml
Or use default values
或使用默认配置安装
helm install todo-app ./helm/todo-app --namespace todo-app
helm install todo-app ./helm/todo-app --namespace todo-app
Forward service to local port
将服务端口转发至本地端口
kubectl port-forward svc/frontend 8080:80 -n todo-app
kubectl port-forward svc/frontend 8080:80 -n todo-app
Minikube Service Command
Minikube Service命令
Open service in browser
在浏览器中打开服务
minikube service frontend -n todo-app
minikube service frontend -n todo-app
Get URL without opening
获取服务URL但不打开浏览器
minikube service frontend -n todo-app --url
minikube service frontend -n todo-app --url
Get Minikube IP
获取Minikube的IP地址
Access NodePort services
访问NodePort类型服务
http://$(minikube ip):<nodeport>
http://$(minikube ip):<nodeport>
Open in browser with URL
获取仪表盘URL并在浏览器中打开
Troubleshooting Minikube
Minikube 故障排查
Issue: Minikube won't start
问题:Minikube无法启动
Check prerequisites
检查前置条件
1. Update minikube
1. 更新Minikube
2. Restart Docker Desktop
2. 重启Docker Desktop
3. Delete .minikube directory: rm -rf ~/.minikube
3. 删除.minikube目录:rm -rf ~/.minikube
4. Try different driver
4. 尝试使用其他驱动
Issue: Images not found
问题:镜像未找到
Verify image is loaded
验证镜像是否已加载
If not loaded, re-run load command
如果未加载,重新运行加载命令
minikube image load todo-frontend:latest
minikube image load todo-frontend:latest
Issue: Pods in Pending state
问题:Pod处于Pending状态
kubectl describe pod <pod-name> -n todo-app
kubectl describe pod <pod-name> -n todo-app
May need to increase Minikube resources
可能需要增加Minikube资源
minikube stop
minikube start --cpus=4 --memory=8192
minikube stop
minikube start --cpus=4 --memory=8192
Issue: CrashLoopBackOff
问题:CrashLoopBackOff状态
kubectl logs <pod-name> -n todo-app
kubectl logs <pod-name> -n todo-app
View previous logs
查看之前的日志
kubectl logs <pod-name> -n todo-app --previous
kubectl logs <pod-name> -n todo-app --previous
Describe pod for events
查看Pod详情及事件
kubectl describe pod <pod-name> -n todo-app
kubectl describe pod <pod-name> -n todo-app
Issue: Ingress not working
问题:Ingress无法工作
Verify ingress addon
验证Ingress插件状态
minikube addons list | grep ingress
minikube addons list | grep ingress
Enable if missing
如果未启用,启用插件
minikube addons enable ingress
minikube addons enable ingress
Add host entry (for todo.local)
添加主机映射(以todo.local为例)
echo "$(minikube ip) todo.local" | sudo tee -a /etc/hosts
echo "$(minikube ip) todo.local" | sudo tee -a /etc/hosts
Integration with Project
与项目集成
Todo Project Minikube Workflow
Todo项目Minikube工作流
1. Start Minikube with adequate resources
1. 使用足够资源启动Minikube
minikube start --cpus=4 --memory=8192 --disk-size=50gb
minikube start --cpus=4 --memory=8192 --disk-size=50gb
2. Enable required addons
2. 启用所需插件
minikube addons enable ingress metrics-server
minikube addons enable ingress metrics-server
3. Build Docker images
3. 构建Docker镜像
docker build -t todo-frontend:latest ./frontend
docker build -t todo-backend:latest ./backend
docker build -t todo-mcp-server:latest -f backend/Dockerfile.mcp ./backend
docker build -t todo-frontend:latest ./frontend
docker build -t todo-backend:latest ./backend
docker build -t todo-mcp-server:latest -f backend/Dockerfile.mcp ./backend
4. Load images into Minikube
4. 将镜像加载至Minikube
minikube image load todo-frontend:latest todo-backend:latest todo-mcp-server:latest
minikube image load todo-frontend:latest todo-backend:latest todo-mcp-server:latest
5. Create namespace
5. 创建命名空间
kubectl create namespace todo-app
kubectl create namespace todo-app
kubectl create secret generic backend-secrets
--from-literal=GEMINI_API_KEY=${GEMINI_API_KEY}
--from-literal=BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}
-n todo-app
kubectl create secret generic backend-secrets
--from-literal=GEMINI_API_KEY=${GEMINI_API_KEY}
--from-literal=BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}
-n todo-app
7. Apply manifests
7. 应用清单文件
kubectl apply -f k8s/ -n todo-app
kubectl apply -f k8s/ -n todo-app
8. Verify deployment
8. 验证部署
kubectl get pods -n todo-app
kubectl get svc -n todo-app
kubectl get pods -n todo-app
kubectl get svc -n todo-app
9. Access application
9. 访问应用
minikube service frontend -n todo-app
minikube service frontend -n todo-app
kubectl delete namespace todo-app
kubectl delete namespace todo-app
Verification Checklist
验证清单
Common Commands Reference
常用命令参考
minikube start # Start cluster
kubectl get pods -n todo-app # Check status
minikube dashboard # Open dashboard
minikube service frontend -n todo-app # Access app
minikube start # 启动集群
kubectl get pods -n todo-app # 检查状态
minikube dashboard # 打开仪表盘
minikube service frontend -n todo-app # 访问应用
kubectl logs -f deployment/backend -n todo-app # View logs
kubectl describe pod <pod-name> -n todo-app # Debug pod
kubectl exec -it <pod-name> -n todo-app -- sh # Shell in pod
kubectl logs -f deployment/backend -n todo-app # 查看日志
kubectl describe pod <pod-name> -n todo-app # 调试Pod
kubectl exec -it <pod-name> -n todo-app -- sh # 进入Pod终端
minikube stop # Stop cluster
minikube delete # Delete cluster
minikube stop # 停止集群
minikube delete # 删除集群
After successful Minikube deployment:
- Test all application features
- Verify AI chatbot works end-to-end
- Prepare for cloud deployment (Phase 5)
- Review Helm charts for production use
成功部署Minikube后:
- 测试应用的所有功能
- 验证AI聊天机器人端到端运行正常
- 准备云环境部署(第5阶段)
- 为生产环境优化Helm Chart