Bird
0
0

Which YAML snippet correctly defines this HPA?

hard📝 Best Practice Q15 of 15
Kubernetes - Resource Management
You want to create an HPA that scales a deployment named api-server based on both CPU usage (target 70%) and custom metric requests_per_second (target 100). The minimum pods should be 3 and maximum 10. Which YAML snippet correctly defines this HPA?
AapiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: api-server-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: api-server minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70 - type: Resource resource: name: requests_per_second target: type: AverageValue averageValue: "100"
BapiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: api-server-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: api-server minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: AverageValue averageValue: "70" - type: Pods pods: metric: name: requests_per_second target: type: AverageValue averageValue: "100"
CapiVersion: autoscaling/v1 kind: HorizontalPodAutoscaler metadata: name: api-server-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: api-server minReplicas: 3 maxReplicas: 10 targetCPUUtilizationPercentage: 70
DapiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: api-server-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: api-server minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70 - type: Pods pods: metric: name: requests_per_second target: type: AverageValue averageValue: "100"
Step-by-Step Solution
Solution:
  1. Step 1: Use autoscaling/v2 API for multiple metrics

    autoscaling/v2 supports multiple metrics including resource and custom metrics.
  2. Step 2: Check metric types and targets

    CPU uses type Utilization with averageUtilization; custom metric uses type Pods with metric name and AverageValue target.
  3. Step 3: Verify minReplicas and maxReplicas

    Minimum 3 and maximum 10 pods are correctly set in spec.
  4. Final Answer:

    YAML with cpu resource metric (Utilization) and pods metric for requests_per_second -> Option D
  5. Quick Check:

    Multiple metrics with correct types = apiVersion: autoscaling/v2 kind: HorizontalPodAutoscaler metadata: name: api-server-hpa spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment name: api-server minReplicas: 3 maxReplicas: 10 metrics: - type: Resource resource: name: cpu target: type: Utilization averageUtilization: 70 - type: Pods pods: metric: name: requests_per_second target: type: AverageValue averageValue: "100" [OK]
Quick Trick: Use autoscaling/v2 with resource and pods metrics for multiple targets [OK]
Common Mistakes:
  • Using autoscaling/v1 which does not support multiple metrics
  • Wrong metric types or target fields
  • Mixing resource and custom metric syntax incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kubernetes Quizzes