kubectl version
minikube start or cloud cluster
Write production Kubernetes Deployment and Service manifests with rolling updates, HPA, and PodDisruptionBudgets.
1 apiVersion: apps/v1 2 kind: Deployment 3 metadata: 4 name: myapp 5 namespace: production 6 labels: 7 app: myapp 8 version: "1.0" 9 spec: 10 replicas: 3 11 selector: 12 matchLabels: 13 app: myapp 14 strategy: 15 type: RollingUpdate 16 rollingUpdate: 17 maxSurge: 1 18 maxUnavailable: 0 # Zero-downtime updates 19 template: 20 metadata: 21 labels: 22 app: myapp 23 version: "1.0" 24 spec: 25 topologySpreadConstraints: 26 - maxSkew: 1 27 topologyKey: kubernetes.io/hostname 28 whenUnsatisfiable: DoNotSchedule 29 labelSelector: 30 matchLabels: 31 app: myapp 32 33 terminationGracePeriodSeconds: 30 34 35 containers: 36 - name: myapp 37 image: ghcr.io/myorg/myapp:1.0.0 38 ports: 39 - containerPort: 8080 40 resources: 41 requests: 42 cpu: 100m 43 memory: 128Mi 44 limits: 45 cpu: 500m 46 memory: 512Mi 47 livenessProbe: 48 httpGet: 49 path: /healthz 50 port: 8080 51 initialDelaySeconds: 15 52 periodSeconds: 10 53 failureThreshold: 3 54 readinessProbe: 55 httpGet: 56 path: /ready 57 port: 8080 58 initialDelaySeconds: 5 59 periodSeconds: 5 60 failureThreshold: 3 61 env: 62 - name: APP_ENV 63 value: production 64 securityContext: 65 runAsNonRoot: true 66 runAsUser: 10001 67 allowPrivilegeEscalation: false 68 readOnlyRootFilesystem: true 69 --- 70 apiVersion: policy/v1 71 kind: PodDisruptionBudget 72 metadata: 73 name: myapp-pdb 74 namespace: production 75 spec: 76 minAvailable: 2 77 selector: 78 matchLabels: 79 app: myapp 80 --- 81 apiVersion: autoscaling/v2 82 kind: HorizontalPodAutoscaler 83 metadata: 84 name: myapp-hpa 85 namespace: production 86 spec: 87 scaleTargetRef: 88 apiVersion: apps/v1 89 kind: Deployment 90 name: myapp 91 minReplicas: 3 92 maxReplicas: 20 93 metrics: 94 - type: Resource 95 resource: 96 name: cpu 97 target: 98 type: Utilization 99 averageUtilization: 60 100 - type: Resource 101 resource: 102 name: memory 103 target: 104 type: Utilization 105 averageUtilization: 70 106
Sign in to share your feedback and join the discussion.