# 节点池设计 nodePools: - name: system zones: ["us-east-1a", "us-east-1b", "us-east-1c"] instanceType: t3.large autoscaling: min: 3 max: 10 - name: workload zones: ["us-east-1a", "us-east-1b", "us-east-1c"] instanceType: m5.xlarge autoscaling: min: 5 max: 20
apiVersion: v1 kind: ResourceQuota metadata: name: compute-quota spec: hard: requests.cpu: "100" requests.memory: 200Gi limits.cpu: "200" limits.memory: 400Gi persistentvolumeclaims: "10"
apiVersion: v1 kind: LimitRange metadata: name: default-limits spec: limits: - default: cpu: 500m memory: 512Mi defaultRequest: cpu: 250m memory: 256Mi type: Container
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: web-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: web 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
apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: developer rules: - apiGroups: ["", "apps"] resources: ["pods", "deployments"] verbs: ["get", "list", "create", "update"]
apiVersion: v1 kind: Namespace metadata: name: production labels: pod-security.kubernetes.io/enforce: restricted pod-security.kubernetes.io/enforce-version: latest
apiVersion: networking.k8s.io/v1 kind: NetworkPolicy metadata: name: deny-all spec: podSelector: {} policyTypes: - Ingress - Egress
# Prometheus配置 apiVersion: v1 kind: ConfigMap metadata: name: prometheus-config data: prometheus.yml: | global: scrape_interval: 15s scrape_configs: - job_name: 'kubernetes-pods' kubernetes_sd_configs: - role: pod relabel_configs: - source_labels: [__meta_kubernetes_pod_annotation_prometheus_io_scrape] action: keep regex: true
groups: - name: critical-alerts rules: - alert: PodCrashLooping expr: rate(kube_pod_container_status_restarts_total[15m]) > 0 for: 5m labels: severity: critical annotations: summary: "Pod {{ $labels.pod }} crash looping"
apiVersion: v1 kind: ConfigMap metadata: name: loki-config data: loki.yaml: | server: http_listen_port: 3100 ingester: lifecycler: ring: kvstore: store: inmemory
# ArgoCD Application apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: production-app spec: destination: namespace: production server: https://kubernetes.default.svc source: repoURL: https://github.com/org/manifests targetRevision: main path: apps/production syncPolicy: automated: prune: true selfHeal: true
apiVersion: apps/v1 kind: Deployment spec: strategy: type: RollingUpdate rollingUpdate: maxSurge: 25% maxUnavailable: 0
Pod Pending
CrashLoopBackOff
Service无法访问
# 查看Pod事件 kubectl describe pod <pod-name> # 进入容器调试 kubectl exec -it <pod-name> -- /bin/bash # 查看日志 kubectl logs <pod-name> --tail=100 -f # 端口转发 kubectl port-forward svc/<service-name> 8080:80
apiVersion: v1 kind: Pod spec: nodeSelector: kubernetes.io/arch: amd64 tolerations: - key: cloud.google.com/gke-spot operator: Equal value: "true" effect: NoSchedule