Horizontal Pod Autoscaling (HPA) automatically adjusts the number of Go service replicas based on CPU or memory usage. Create an HPA resource that targets your deployment and defines the scaling thresholds.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: go-service-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: go-service
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
Apply the configuration with kubectl apply -f hpa.yaml.