Complete the command to create a Horizontal Pod Autoscaler for deployment 'webapp' targeting CPU usage at 50%.
kubectl autoscale deployment webapp --cpu-percent=[1] --min=1 --max=5
The --cpu-percent flag sets the target average CPU utilization for the pods. 50% is a common target.
Complete the YAML snippet to specify the minimum number of replicas as 2 in the Horizontal Pod Autoscaler spec.
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: example-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: example
minReplicas: [1]
maxReplicas: 10
metrics:
- type: ResourceThe minReplicas field sets the minimum number of pod replicas the autoscaler maintains.
Fix the error in the metric type to correctly specify CPU resource metric in the HPA spec.
metrics: - type: [1] resource: name: cpu target: type: Utilization averageUtilization: 60
The metric type for CPU usage is Resource. Other types are for different metric sources.
Fill both blanks to complete the command that describes the Horizontal Pod Autoscaler named 'frontend-hpa' in namespace 'prod'.
kubectl [1] hpa frontend-hpa -n [2]
The describe command shows detailed info about the HPA. The namespace is specified with -n.
Fill all three blanks to complete the YAML snippet for HPA targeting deployment 'api-server' with min 2, max 6 replicas, and CPU utilization target 70%.
apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: [1] spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: [2] minReplicas: [3] maxReplicas: 6 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70
The metadata.name is the HPA name, scaleTargetRef.name is the deployment name, and minReplicas sets the minimum pods.