用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill kubernetes-devops命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | kubernetes-devops |
| description | Kubernetes deployments with security and best practices Use when this capability is needed. |
| metadata | {"author":"Alteriom"} |
Purpose: Deploy, manage, and scale applications on Kubernetes clusters with security and reliability.
Works with: Kubernetes 1.28+, kubectl, Helm, Kustomize
License: MIT (original work, inspired by Kubernetes docs v1.31, CNCF best practices, 12-Factor App)
Use this skill when you need to:
Don't use this for:
# Install 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
# Verify
kubectl version --client
# Configure kubeconfig
export KUBECONFIG=~/.kube/config
# Test connection
kubectl get nodes
# Check current context
kubectl config current-context
Think Before Coding (Karpathy Principle #1):
Step 1: Create Deployment
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp
namespace: default
labels:
app: myapp
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: myregistry/myapp:v1.0.0
ports:
- containerPort: 8080
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: myapp-secrets
key: database-url
resources:
requests:
memory: "128Mi"
cpu: "100m"
limits:
memory: "256Mi"
Step 2: Create Service
# service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp
namespace: default
spec:
selector:
app: myapp
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIP
Step 3: Deploy
# Create namespace (if needed)
kubectl create namespace myapp
# Apply resources
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
# Verify
kubectl get deployments -n myapp
kubectl get pods -n myapp
kubectl get services -n myapp
Verification:
# Check pod status
kubectl get pods -n myapp
# All pods should be Running
# Check logs
kubectl logs -n myapp deployment/myapp --tail=50
# Test service
kubectl port-forward -n myapp service/myapp 8080:80
curl http://localhost:8080/health
Step 1: Create Secret
# From literal values
kubectl create secret generic myapp-secrets \
--from-literal=database-url="postgresql://user:pass@host:5432/db" \
--from-literal=api-key="secret123"
# From file
kubectl create secret generic myapp-tls \
--from-file=tls.crt=./cert.crt \
--from-file=tls.key=./cert.key
# Verify (base64 encoded)
kubectl get secret myapp-secrets -o yaml
Step 2: Use in Deployment
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: myapp-secrets
key: database-url
- name: API_KEY
valueFrom:
secretKeyRef:
name: myapp-secrets
key: api-key
Security Best Practices:
Manual Scaling:
# Scale to 5 replicas
kubectl scale deployment myapp --replicas=5 -n myapp
# Verify
kubectl get pods -n myapp
Horizontal Pod Autoscaler (HPA):
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: myapp-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: myapp
minReplicas: 3
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Apply:
kubectl apply -f hpa.yaml
kubectl get hpa -n myapp
Simplicity First (Karpathy Principle #2):
Update image version:
# Update deployment
kubectl set image deployment/myapp myapp=myregistry/myapp:v1.1.0 -n myapp
# Watch rollout
kubectl rollout status deployment/myapp -n myapp
# Check history
kubectl rollout history deployment/myapp -n myapp
Rollback if needed:
# Undo last rollout
kubectl rollout undo deployment/myapp -n myapp
# Rollback to specific revision
kubectl rollout undo deployment/myapp --to-revision=2 -n myapp
Verification:
# Check pods are running new version
kubectl get pods -n myapp -o jsonpath='{.items[*].spec.containers[0].image}'
# Check rollout status
kubectl rollout status deployment/myapp -n myapp
Pod not starting:
# Check pod status
kubectl get pods -n myapp
# Describe pod
kubectl describe pod <pod-name> -n myapp
# Common issues:
# - ImagePullBackOff: Wrong image name or auth
# - CrashLoopBackOff: App crashing on startup
# - Pending: Insufficient resources
# Check logs
kubectl logs <pod-name> -n myapp --previous # Logs from crashed container
kubectl logs <pod-name> -n myapp --tail=100
# Get shell in pod
kubectl exec -it <pod-name> -n myapp -- /bin/sh
Service not accessible:
# Check service
kubectl get service myapp -n myapp
# Check endpoints
kubectl get endpoints myapp -n myapp
# Should show pod IPs
# Test from another pod
kubectl run -it --rm debug --image=busybox --restart=Never -- wget -O- http://myapp.myapp.svc.cluster.local
Karpathy Principle: Understand the System - K8s failures cascade through layers (pod → deployment → service → ingress). Debug from the bottom up: start with pod logs, then service endpoints, then ingress rules.
# Deploy blue (current)
kubectl apply -f deployment-blue.yaml
# Deploy green (new version)
kubectl apply -f deployment-green.yaml
# Switch traffic to green
kubectl patch service myapp -p '{"spec":{"selector":{"version":"green"}}}'
# Verify green is healthy
# Delete blue
kubectl delete deployment myapp-blue
apiVersion: v1
kind: ConfigMap
metadata:
name: myapp-config
data:
app.conf: |
server {
listen 80;
server_name example.com;
}
DATABASE_POOL_SIZE: "10"
LOG_LEVEL: "info"
---
# Use in deployment
spec:
containers:
- name: myapp
envFrom:
- configMapRef:
name: myapp-config
volumeMounts:
- name: config
mountPath: /etc/app
volumes:
- name: config
configMap:
name: myapp-config
Use StatefulSets for databases, message queues, anything needing persistent identity:
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: postgres
spec:
serviceName: postgres
replicas: 3
selector:
matchLabels:
app: postgres
template:
metadata:
labels:
app: postgres
spec:
containers:
- name: postgres
image: postgres:15
ports:
- containerPort: 5432
volumeMounts:
- name: data
mountPath: /var/lib/postgresql/data
env:
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-secret
key: password
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: []
Headless Service (for StatefulSet DNS):
apiVersion: v1
kind: Service
metadata:
name: postgres
spec:
clusterIP: None # Headless
selector:
app: postgres
ports:
- port: 5432
DNS names:
postgres-0.postgres.default.svc.cluster.local
postgres-1.postgres.default.svc.cluster.local
postgres-2.postgres.default.svc.cluster.local
One-time job:
apiVersion: batch/v1
kind: Job
metadata:
name: db-migration
spec:
template:
spec:
containers:
- name: migrate
image: myapp:v1.0.0
command: ["npm", "run", "migrate"]
restartPolicy: Never
backoffLimit: 3
Scheduled job (CronJob):
apiVersion: batch/v1
kind: CronJob
metadata:
name: backup
spec:
schedule: "0 2 * * *" # 2 AM daily
jobTemplate:
spec:
template:
spec:
containers:
- name: backup
image: myapp-backup:latest
command: ["./backup.sh"]
restartPolicy: OnFailure
Karpathy Principle: Surgical Changes - Use Jobs for migrations, CronJobs for backups. Don't run these in your main deployment—they have different lifecycle needs.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: myapp-ingress
annotations:
cert-manager.io/cluster-issuer: "letsencrypt-prod"
spec:
ingressClassName: nginx
tls:
- hosts:
- api.example.com
secretName: myapp-tls
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: myapp
port:
number: 80
Install Ingress Controller (NGINX):
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.9.0/deploy/static/provider/cloud/deploy.yaml
Ensure minimum availability during node maintenance:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: myapp-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: myapp
This prevents voluntary disruptions (node drains, kubectl delete) from taking down too many pods at once.
Limit resource usage per namespace:
apiVersion: v1
kind: ResourceQuota
metadata:
name: myapp-quota
namespace: myapp
spec:
hard:
requests.cpu: "10"
requests.memory: 20Gi
limits.cpu: "20"
limits.memory: 40Gi
pods: "50"
Why it happens: Forgetting to set CPU/memory limits
Consequences:
✅ How to avoid:
resources:
requests: # Scheduler uses this
memory: "128Mi"
cpu: "100m"
limits: # Hard limit
memory: "256Mi"
cpu: "200m"
Why it happens: Deploying without liveness/readiness probes
Consequences:
✅ How to avoid:
livenessProbe: # Restart if failing
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
readinessProbe: # Remove from service if failing
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
latest TagWhy it happens: Not pinning image versions
Consequences:
✅ How to avoid:
# Bad
image: myapp:latest
# Good
image: myapp:v1.2.3
image: myapp:sha256:abc123...
Why it happens: All replicas on same node
Consequences:
✅ How to avoid:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- myapp
topologyKey: kubernetes.io/hostname
Why it happens: /metrics endpoint public
Consequences:
✅ How to avoid:
# Network Policy to restrict metrics access
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-prometheus
spec:
podSelector:
matchLabels:
app: myapp
ingress:
- from:
- namespaceSelector:
matchLabels:
name: monitoring
ports:
- port: 9090
protocol: TCP
Before considering deployment complete:
Deployment:
latest)Service:
Security:
Observability:
Combine with:
ssh-essentials - Access cluster nodestask-development-workflow - CI/CD pipelinemonitoring - Set up Prometheus, GrafanaExample CI/CD:
# .github/workflows/deploy.yml
name: Deploy to K8s
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build image
run: docker build -t myapp:${{ github.sha }} .
- name: Push image
run: docker push myapp:${{ github.sha }}
- name: Deploy to K8s
run: |
kubectl set image deployment/myapp myapp=myapp:${{ github.sha }}
kubectl rollout status deployment/myapp
Official Documentation:
Production Guides:
Related Skills:
ssh-essentials - Server accesstask-development-workflow - CI/CDmonitoring - ObservabilityIncorporates Karpathy Principles:
Tested With:
Completeness: 9/10 - Covers deployments, StatefulSets, Jobs, CronJobs, scaling, security, troubleshooting. Missing: Operators, custom controllers, service meshes.
Last Updated: April 13, 2026
Maintainer: Alteriom
License: MIT
Karpathy Principle: Understand the Dependencies - Kubernetes failures cascade through dependencies (pod → deployment → service → ingress). Always debug from the bottom up, not top down.
Source: Alteriom/ai-dev-skills — distributed by TomeVault.