Loading...
Loading...
Compare original and translation side by side
undefinedundefinedundefinedundefined| Strategy | Use Case | Configuration |
|---|---|---|
| RollingUpdate | Zero-downtime updates | |
| Recreate | Stateful apps, incompatible versions | |
| Blue-Green | Instant rollback | Two deployments, switch Service selector |
| Canary | Gradual rollout | Multiple deployments with weighted traffic |
| 策略 | 适用场景 | 配置 |
|---|---|---|
| RollingUpdate | 零停机更新 | |
| Recreate | 有状态应用、不兼容版本 | |
| Blue-Green | 即时回滚 | 两个Deployment,切换Service选择器 |
| Canary | 逐步发布 | 多个Deployment,流量加权分配 |
undefinedundefinedundefinedundefined| Type | Use Case | Access |
|---|---|---|
| ClusterIP | Internal services | |
| NodePort | Development, debugging | |
| LoadBalancer | External traffic (cloud) | Cloud provider LB IP |
| ExternalName | External service proxy | DNS CNAME |
| 类型 | 适用场景 | 访问方式 |
|---|---|---|
| ClusterIP | 内部服务 | |
| NodePort | 开发、调试 | |
| LoadBalancer | 外部流量(云环境) | 云服务商负载均衡IP |
| ExternalName | 外部服务代理 | DNS CNAME |
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-api-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- api.example.com
secretName: api-tls-secret
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-api
port:
number: 80apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-api-ingress
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/ssl-redirect: "true"
spec:
ingressClassName: nginx
tls:
- hosts:
- api.example.com
secretName: api-tls-secret
rules:
- host: api.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-api
port:
number: 80resources:
requests: # Guaranteed resources
cpu: 100m # 0.1 CPU core
memory: 256Mi
limits: # Maximum allowed
cpu: 500m # 0.5 CPU core
memory: 512Mi| Workload Type | CPU Request | Memory Request | CPU Limit | Memory Limit |
|---|---|---|---|---|
| Web API | 100m-500m | 256Mi-512Mi | 500m-1000m | 512Mi-1Gi |
| Worker | 250m-1000m | 512Mi-1Gi | 1000m-2000m | 1Gi-2Gi |
| Database | 500m-2000m | 1Gi-4Gi | 2000m-4000m | 4Gi-8Gi |
resources:
requests: # 预留资源
cpu: 100m # 0.1核CPU
memory: 256Mi
limits: # 最大允许资源
cpu: 500m # 0.5核CPU
memory: 512Mi| 工作负载类型 | CPU请求 | 内存请求 | CPU限制 | 内存限制 |
|---|---|---|---|---|
| Web API | 100m-500m | 256Mi-512Mi | 500m-1000m | 512Mi-1Gi |
| 工作节点 | 250m-1000m | 512Mi-1Gi | 1000m-2000m | 1Gi-2Gi |
| 数据库 | 500m-2000m | 1Gi-4Gi | 2000m-4000m | 4Gi-8Gi |
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30 # Wait for app startup
periodSeconds: 10 # Check every 10s
timeoutSeconds: 5 # Timeout per check
failureThreshold: 3 # Restart after 3 failureslivenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 30 # 等待应用启动
periodSeconds: 10 # 每10秒检查一次
timeoutSeconds: 5 # 单次检查超时时间
failureThreshold: 3 # 3次失败后重启容器readinessProbe:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 5 # Quick check after start
periodSeconds: 5 # Check every 5s
successThreshold: 1 # 1 success = ready
failureThreshold: 3 # Remove from LB after 3 failuresreadinessProbe:
httpGet:
path: /readyz
port: 8080
initialDelaySeconds: 5 # 启动后快速检查
periodSeconds: 5 # 每5秒检查一次
successThreshold: 1 # 1次成功即视为就绪
failureThreshold: 3 # 3次失败后从负载均衡中移除startupProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 0
periodSeconds: 10
failureThreshold: 30 # Allow 5 minutes to start (30 * 10s)startupProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 0
periodSeconds: 10
failureThreshold: 30 # 允许5分钟启动时间(30 * 10秒)apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleDown:
stabilizationWindowSeconds: 300 # Wait 5min before scale downapiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-api
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
behavior:
scaleDown:
stabilizationWindowSeconds: 300 # 缩容前等待5分钟apiVersion: v1
kind: ConfigMap
metadata:
name: my-api-config
data:
LOG_LEVEL: "info"
API_ENDPOINT: "https://api.example.com"
config.yaml: |
server:
port: 8080
features:
enabled: trueapiVersion: v1
kind: ConfigMap
metadata:
name: my-api-config
data:
LOG_LEVEL: "info"
API_ENDPOINT: "https://api.example.com"
config.yaml: |
server:
port: 8080
features:
enabled: trueapiVersion: v1
kind: Secret
metadata:
name: my-api-secrets
type: Opaque
data:
API_KEY: YXBpLWtleS1oZXJl # echo -n "api-key-here" | base64
DATABASE_URL: cG9zdGdyZXM6Ly8uLi4= # echo -n "postgres://..." | base64apiVersion: v1
kind: Secret
metadata:
name: my-api-secrets
type: Opaque
data:
API_KEY: YXBpLWtleS1oZXJl # echo -n "api-key-here" | base64
DATABASE_URL: cG9zdGdyZXM6Ly8uLi4= # echo -n "postgres://..." | base64spec:
containers:
- name: my-api
envFrom:
- configMapRef:
name: my-api-config
- secretRef:
name: my-api-secrets
volumeMounts:
- name: config-volume
mountPath: /app/config
volumes:
- name: config-volume
configMap:
name: my-api-configspec:
containers:
- name: my-api
envFrom:
- configMapRef:
name: my-api-config
- secretRef:
name: my-api-secrets
volumeMounts:
- name: config-volume
mountPath: /app/config
volumes:
- name: config-volume
configMap:
name: my-api-config# Validate manifests
kubectl apply -f manifests/ --dry-run=server
# Apply to cluster
kubectl apply -f manifests/
# Watch rollout
kubectl rollout status deployment/my-api# 验证清单
kubectl apply -f manifests/ --dry-run=server
# 应用到集群
kubectl apply -f manifests/
# 查看发布状态
kubectl rollout status deployment/my-api{baseDir}/references/errors.md| Error | Quick Fix |
|---|---|
| ImagePullBackOff | Check image name, tag, registry credentials |
| CrashLoopBackOff | Check logs: |
| OOMKilled | Increase memory limits |
| Pending | Check resources: |
{baseDir}/references/errors.md| 错误 | 快速修复 |
|---|---|
| ImagePullBackOff | 检查镜像名称、标签、仓库凭证 |
| CrashLoopBackOff | 查看日志: |
| OOMKilled | 增加内存限制 |
| Pending | 检查资源: |
{baseDir}/references/examples.md{baseDir}/references/examples.md{baseDir}/assets/{baseDir}/scripts/{baseDir}/assets/{baseDir}/scripts/