Creating the manifests
Course: Kubernetes Part 3 (Scaling) - chapter 4
Hardcoded replicas
Section titled “Hardcoded replicas”Lets try to create a deployment with hardcoded set of replicas
apiVersion: apps/v1kind: Deploymentmetadata: name: cpu-deploymentspec: replicas: 2 selector: matchLabels: app: cpu-app template: metadata: labels: app: cpu-app spec: containers: - name: cpu-app image: 100xdevs/week-28:latest ports: - containerPort: 3000- Create a serice
apiVersion: v1kind: Servicemetadata: name: cpu-servicespec: selector: app: cpu-app ports: - protocol: TCP port: 80 targetPort: 3000 type: LoadBalancerWith a horizontal pod accelerator
Section titled “With a horizontal pod accelerator”- Add HPA manifest
apiVersion: autoscaling/v2kind: HorizontalPodAutoscalermetadata: name: cpu-hpaspec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: cpu-deployment minReplicas: 2 maxReplicas: 5 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 50- Apply all three manifests
kubectl apply -f service.ymlkubectl apply -f deployment.ymlkubectl apply -f hpa.yml💡 You can scale up/down based on multiple metrics. If either of the metrics goes above the threshold, we scale up If all the metrics go below the threshold, we scale down