kubernetes-flux
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseKubernetes Flux Skill
Kubernetes Flux 技能
Installation
安装
The skill invokes the Flux CLI. Install:
- macOS/Linux (Homebrew):
brew install fluxcd/tap/flux - macOS/Linux (script):
curl -s https://fluxcd.io/install.sh | sudo bash - Windows (winget):
winget install -e --id FluxCD.Flux - Windows (Chocolatey):
choco install flux - Custom dir:
curl -s https://fluxcd.io/install.sh | bash -s ~/.local/bin
Verify: . Then use to deploy controllers if needed.
flux --versionflux bootstrap本技能调用Flux CLI,安装方式如下:
- macOS/Linux(Homebrew):
brew install fluxcd/tap/flux - macOS/Linux(脚本):
curl -s https://fluxcd.io/install.sh | sudo bash - Windows(winget):
winget install -e --id FluxCD.Flux - Windows(Chocolatey):
choco install flux - 自定义目录:
curl -s https://fluxcd.io/install.sh | bash -s ~/.local/bin
验证安装:。若需要,可使用部署控制器。
flux --versionflux bootstrapCheat Sheet & Best Practices
速查表与最佳实践
Bootstrap: ; use , , or as needed.
flux bootstrap git --url=ssh://git@host/repo.git --path=clusters/my-cluster--branch--interval--private-key-file--token-authStatus: — controllers/CRDs; — all resources; ; — managed objects.
flux checkflux get all -Aflux get kustomizationsflux tree kustomization <name>Hacks: Use and to see sync state. Reconcile on demand: . Pin versions with on install script. Prefer Git over Helm for app manifests when using GitOps.
flux get sources gitflux get kustomizationsflux reconcile kustomization <name> --with-sourceFLUX_VERSION引导部署:;可根据需要添加、、或参数。
flux bootstrap git --url=ssh://git@host/repo.git --path=clusters/my-cluster--branch--interval--private-key-file--token-auth状态检查: — 检查控制器/CRD状态; — 查看所有资源;; — 查看托管对象。
flux checkflux get all -Aflux get kustomizationsflux tree kustomization <name>实用技巧:使用和查看同步状态。按需触发调和:。在安装脚本中通过固定版本。使用GitOps时,优先选择Git而非Helm来存储应用清单。
flux get sources gitflux get kustomizationsflux reconcile kustomization <name> --with-sourceFLUX_VERSIONCertifications & Training
认证与培训
Kubernetes: CKA / CKAD (Linux Foundation). Flux: GitOps with Flux (LFS269). Skill data: Bootstrap, reconcile, status (, ), tree; GitOps workflow.
flux checkflux get allKubernetes相关:CKA / CKAD(Linux基金会)。Flux相关:GitOps with Flux (LFS269)。技能核心内容:引导部署、调和、状态检查(、)、资源树;GitOps工作流。
flux checkflux get allHooks & Workflows
钩子与工作流
Suggested hooks: Pre-apply: . Post-push (to Git repo used by Flux): optional reconcile trigger. Use with devops (always) for GitOps clusters.
flux checkWorkflows: Use with devops (always). Flow: bootstrap or reconcile; debug with , . See skill and enterprise workflows.
flux get allflux tree kustomizationgitops-workflow推荐钩子:预应用钩子:。推送后钩子(推送到Flux使用的Git仓库):可选触发调和。始终与devops技能配合使用,以管理GitOps集群。
flux check工作流:始终与devops技能配合使用。流程:引导部署或调和;使用、进行调试。可参考技能及企业级工作流。
flux get allflux tree kustomizationgitops-workflowOverview
概述
This skill provides comprehensive Kubernetes cluster management through kubectl, enabling AI agents to inspect, troubleshoot, and manage Kubernetes resources.
本技能通过kubectl提供全面的Kubernetes集群管理能力,支持AI Agent检查、排查和管理Kubernetes资源。
When to Use
使用场景
- Debugging application pods and containers
- Monitoring deployment rollouts and status
- Analyzing service networking and endpoints
- Investigating cluster events and errors
- Troubleshooting performance issues
- Managing application scaling
- Port forwarding for local development
- 调试应用Pod与容器
- 监控Deployment发布状态
- 分析Service网络与端点
- 排查集群事件与错误
- 解决性能问题
- 管理应用扩缩容
- 端口转发用于本地开发
Requirements
前置要求
- kubectl installed and configured
- Valid KUBECONFIG file or default context
- Cluster access credentials
- Appropriate RBAC permissions
- 已安装并配置kubectl
- 有效的KUBECONFIG文件或默认上下文
- 集群访问凭证
- 合适的RBAC权限
Quick Reference
快速参考
bash
undefinedbash
undefinedGet pods in current namespace
获取当前命名空间下的Pod
kubectl get pods
kubectl get pods
Get pods in specific namespace
获取指定命名空间下的Pod
kubectl get pods -n production
kubectl get pods -n production
Get pods with labels
获取带指定标签的Pod
kubectl get pods -l app=web -n production
kubectl get pods -l app=web -n production
Describe a pod
查看Pod详情
kubectl describe pod my-app-123 -n default
kubectl describe pod my-app-123 -n default
Get pod logs
获取Pod日志
kubectl logs my-app-123 -n default
kubectl logs my-app-123 -n default
Get logs with tail
获取最新N条日志
kubectl logs my-app-123 -n default --tail=100
kubectl logs my-app-123 -n default --tail=100
Get logs since time
获取最近1小时的日志
kubectl logs my-app-123 -n default --since=1h
kubectl logs my-app-123 -n default --since=1h
List recent events
列出最近事件
kubectl get events -n default --sort-by='.lastTimestamp' | tail -20
kubectl get events -n default --sort-by='.lastTimestamp' | tail -20
Watch events in real-time
实时监控事件
kubectl get events -n default -w
undefinedkubectl get events -n default -w
undefinedResource Discovery
资源发现
Pods
Pod
bash
undefinedbash
undefinedList all pods
列出指定命名空间下的所有Pod
kubectl get pods -n <namespace>
kubectl get pods -n <namespace>
List pods with wide output
列出指定命名空间下的Pod(含详细信息)
kubectl get pods -n <namespace> -o wide
kubectl get pods -n <namespace> -o wide
List pods across all namespaces
列出所有命名空间下的Pod
kubectl get pods -A
kubectl get pods -A
Filter by label
按标签过滤Pod
kubectl get pods -l app=nginx -n <namespace>
undefinedkubectl get pods -l app=nginx -n <namespace>
undefinedDeployments
Deployment
bash
undefinedbash
undefinedList deployments
列出指定命名空间下的Deployment
kubectl get deployments -n <namespace>
kubectl get deployments -n <namespace>
Get deployment details
查看Deployment详情
kubectl describe deployment <name> -n <namespace>
kubectl describe deployment <name> -n <namespace>
Check rollout status
检查发布状态
kubectl rollout status deployment/<name> -n <namespace>
undefinedkubectl rollout status deployment/<name> -n <namespace>
undefinedServices
Service
bash
undefinedbash
undefinedList services
列出指定命名空间下的Service
kubectl get svc -n <namespace>
kubectl get svc -n <namespace>
Describe service
查看Service详情
kubectl describe svc <name> -n <namespace>
kubectl describe svc <name> -n <namespace>
Get endpoints
获取Service端点
kubectl get endpoints <name> -n <namespace>
undefinedkubectl get endpoints <name> -n <namespace>
undefinedConfigMaps and Secrets
ConfigMap与Secret
bash
undefinedbash
undefinedList ConfigMaps
列出指定命名空间下的ConfigMap
kubectl get configmaps -n <namespace>
kubectl get configmaps -n <namespace>
Describe ConfigMap
查看ConfigMap详情
kubectl describe configmap <name> -n <namespace>
kubectl describe configmap <name> -n <namespace>
Get ConfigMap data
获取ConfigMap数据
kubectl get configmap <name> -n <namespace> -o yaml
kubectl get configmap <name> -n <namespace> -o yaml
List Secrets (names only)
列出指定命名空间下的Secret(仅显示名称)
kubectl get secrets -n <namespace>
kubectl get secrets -n <namespace>
Describe Secret (values masked)
查看Secret详情(值会被掩码处理)
kubectl describe secret <name> -n <namespace>
undefinedkubectl describe secret <name> -n <namespace>
undefinedNamespaces
命名空间
bash
undefinedbash
undefinedList namespaces
列出所有命名空间
kubectl get namespaces
kubectl get namespaces
Get namespace details
查看命名空间详情
kubectl describe namespace <name>
undefinedkubectl describe namespace <name>
undefinedTroubleshooting
故障排查
Pod Debugging
Pod调试
bash
undefinedbash
undefinedDescribe pod for events and conditions
查看Pod事件与状态条件
kubectl describe pod <name> -n <namespace>
kubectl describe pod <name> -n <namespace>
Get pod logs
获取Pod日志
kubectl logs <pod-name> -n <namespace>
kubectl logs <pod-name> -n <namespace>
Get logs from specific container
获取Pod中指定容器的日志
kubectl logs <pod-name> -c <container-name> -n <namespace>
kubectl logs <pod-name> -c <container-name> -n <namespace>
Get previous container logs (after crash)
获取Pod中前一个容器的日志(崩溃后)
kubectl logs <pod-name> -n <namespace> --previous
kubectl logs <pod-name> -n <namespace> --previous
Exec into pod
进入Pod执行命令
kubectl exec -it <pod-name> -n <namespace> -- /bin/sh
kubectl exec -it <pod-name> -n <namespace> -- /bin/sh
Run command in pod
在Pod中执行指定命令
kubectl exec <pod-name> -n <namespace> -- ls -la /app
undefinedkubectl exec <pod-name> -n <namespace> -- ls -la /app
undefinedEvents
事件排查
bash
undefinedbash
undefinedList events sorted by time
按时间排序列出事件
kubectl get events -n <namespace> --sort-by='.lastTimestamp'
kubectl get events -n <namespace> --sort-by='.lastTimestamp'
Filter warning events
过滤警告事件
kubectl get events -n <namespace> --field-selector type=Warning
kubectl get events -n <namespace> --field-selector type=Warning
Watch events live
实时监控事件
kubectl get events -n <namespace> -w
undefinedkubectl get events -n <namespace> -w
undefinedManagement Operations
管理操作
Scaling
扩缩容
bash
undefinedbash
undefinedScale deployment
扩缩容Deployment
kubectl scale deployment <name> --replicas=5 -n <namespace>
kubectl scale deployment <name> --replicas=5 -n <namespace>
Autoscale deployment
为Deployment配置自动扩缩容
kubectl autoscale deployment <name> --min=2 --max=10 --cpu-percent=80 -n <namespace>
undefinedkubectl autoscale deployment <name> --min=2 --max=10 --cpu-percent=80 -n <namespace>
undefinedRollouts
发布版本管理
bash
undefinedbash
undefinedCheck rollout status
检查发布状态
kubectl rollout status deployment/<name> -n <namespace>
kubectl rollout status deployment/<name> -n <namespace>
View rollout history
查看发布历史
kubectl rollout history deployment/<name> -n <namespace>
kubectl rollout history deployment/<name> -n <namespace>
Rollback to previous version
回滚到上一个版本
kubectl rollout undo deployment/<name> -n <namespace>
kubectl rollout undo deployment/<name> -n <namespace>
Rollback to specific revision
回滚到指定版本
kubectl rollout undo deployment/<name> --to-revision=2 -n <namespace>
undefinedkubectl rollout undo deployment/<name> --to-revision=2 -n <namespace>
undefinedPort Forwarding
端口转发
bash
undefinedbash
undefinedForward local port to pod
将本地端口转发到Pod
kubectl port-forward <pod-name> 8080:80 -n <namespace>
kubectl port-forward <pod-name> 8080:80 -n <namespace>
Forward to service
将本地端口转发到Service
kubectl port-forward svc/<service-name> 8080:80 -n <namespace>
undefinedkubectl port-forward svc/<service-name> 8080:80 -n <namespace>
undefinedContext Management
上下文管理
bash
undefinedbash
undefinedGet current context
获取当前上下文
kubectl config current-context
kubectl config current-context
List all contexts
列出所有上下文
kubectl config get-contexts
kubectl config get-contexts
Switch context
切换上下文
kubectl config use-context <context-name>
kubectl config use-context <context-name>
Set default namespace
设置默认命名空间
kubectl config set-context --current --namespace=<namespace>
undefinedkubectl config set-context --current --namespace=<namespace>
undefinedCommon Workflows
常见工作流
Troubleshoot a Failing Pod
排查故障Pod
bash
undefinedbash
undefined1. Find the problematic pod
1. 定位问题Pod
kubectl get pods -n production
kubectl get pods -n production
2. Describe for events
2. 查看Pod事件
kubectl describe pod <pod-name> -n production
kubectl describe pod <pod-name> -n production
3. Check events
3. 检查集群事件
kubectl get events -n production --sort-by='.lastTimestamp' | tail -20
kubectl get events -n production --sort-by='.lastTimestamp' | tail -20
4. Get logs
4. 获取Pod日志
kubectl logs <pod-name> -n production --tail=200
undefinedkubectl logs <pod-name> -n production --tail=200
undefinedMonitor Deployment Rollout
监控Deployment发布
bash
undefinedbash
undefined1. Check deployment status
1. 检查Deployment状态
kubectl get deployments -n production
kubectl get deployments -n production
2. Watch rollout
2. 监控发布过程
kubectl rollout status deployment/<name> -n production
kubectl rollout status deployment/<name> -n production
3. Watch pods
3. 监控Pod状态
kubectl get pods -l app=<app-name> -n production -w
undefinedkubectl get pods -l app=<app-name> -n production -w
undefinedDebug Service Connectivity
调试Service连通性
bash
undefinedbash
undefined1. Check service
1. 检查Service详情
kubectl describe svc <name> -n <namespace>
kubectl describe svc <name> -n <namespace>
2. Check endpoints
2. 检查Service端点
kubectl get endpoints <name> -n <namespace>
kubectl get endpoints <name> -n <namespace>
3. Check backing pods
3. 检查后端Pod
kubectl get pods -l <service-selector> -n <namespace>
kubectl get pods -l <service-selector> -n <namespace>
4. Port forward for testing
4. 端口转发用于测试
kubectl port-forward svc/<name> 8080:80 -n <namespace>
undefinedkubectl port-forward svc/<name> 8080:80 -n <namespace>
undefinedSafety Features
安全特性
Blocked Operations
受限操作
The following are dangerous and require confirmation:
- commands
kubectl delete - Destructive exec commands (rm, dd, mkfs)
- Scale to 0 replicas in production
以下操作存在风险,需要确认后执行:
- 命令
kubectl delete - 破坏性exec命令(如rm、dd、mkfs)
- 在生产环境中将副本数缩容至0
Masked Output
输出掩码
Secret values are always masked. Only metadata shown.
Secret的值始终会被掩码处理,仅显示元数据。
Error Handling
错误处理
| Error | Cause | Fix |
|---|---|---|
| Not installed | Install kubectl |
| Cluster unreachable | Check network/VPN |
| RBAC permissions | Request permissions |
| Resource missing | Verify name/namespace |
| Timeout | Check cluster health |
| 错误信息 | 原因 | 解决方法 |
|---|---|---|
| 未安装kubectl | 安装kubectl |
| 集群无法访问 | 检查网络/VPN连接 |
| RBAC权限不足 | 申请对应权限 |
| 资源不存在 | 验证资源名称与命名空间 |
| 请求超时 | 检查集群健康状态 |
Related
相关资源
- kubectl docs: https://kubernetes.io/docs/reference/kubectl/
- Kubernetes API: https://kubernetes.io/docs/reference/kubernetes-api/
- kubectl文档:https://kubernetes.io/docs/reference/kubectl/
- Kubernetes API:https://kubernetes.io/docs/reference/kubernetes-api/
Memory Protocol (MANDATORY)
记忆协议(必填)
Before starting:
bash
cat .claude/context/memory/learnings.mdAfter completing: Record any new patterns or exceptions discovered.
ASSUME INTERRUPTION: Your context may reset. If it's not in memory, it didn't happen.
开始前:
bash
cat .claude/context/memory/learnings.md完成后:记录发现的任何新模式或异常情况。
假设会被中断:你的上下文可能会重置。如果内容未被记录到记忆中,则视为未发生。