0
0
Kubernetesdevops~20 mins

Horizontal Pod Autoscaler in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Horizontal Pod Autoscaler Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of HPA status command
What is the output of the following command after deploying an HPA targeting a deployment named webapp with min replicas 2 and max replicas 5, currently scaling to 3 replicas based on CPU usage?
Kubernetes
kubectl get hpa webapp
A
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
webapp  Deployment/webapp   60%/50%   2         5         3          10m
B
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
webapp  Deployment/webapp   70%/50%   2         5         4          10m
C
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
webapp  Deployment/webapp   60%/60%   2         5         2          10m
D
NAME    REFERENCE          TARGETS   MINPODS   MAXPODS   REPLICAS   AGE
webapp  Deployment/webapp   50%/60%   2         5         3          10m
Attempts:
2 left
💡 Hint
Look carefully at the TARGETS column showing current CPU usage versus target CPU utilization.
🧠 Conceptual
intermediate
2:00remaining
Understanding HPA scaling behavior
If a Horizontal Pod Autoscaler is configured with minReplicas=1, maxReplicas=4, and target CPU utilization of 50%, what happens when the CPU usage stays at 30% for a long time?
AThe HPA will keep the pods at the current number, ignoring CPU usage below target.
BThe HPA will scale down the pods to 1, the minimum number of replicas.
CThe HPA will scale up the pods to 4, the maximum number of replicas.
DThe HPA will delete all pods because CPU usage is low.
Attempts:
2 left
💡 Hint
Think about what the minimum replicas setting means for scaling down.
Configuration
advanced
3:00remaining
Correct HPA YAML for CPU autoscaling
Which YAML snippet correctly defines a Horizontal Pod Autoscaler for a deployment named api-server with min 3 replicas, max 10 replicas, targeting 75% CPU utilization?
A
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: api-server
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api-server
  minReplicas: 3
  maxReplicas: 10
  targetMemoryUtilizationPercentage: 75
B
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
  name: api-server
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api-server
  minReplicas: 3
  maxReplicas: 10
  targetCPUUtilizationPercentage: 75
C
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-server
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api-server
  minReplicas: 3
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 75
D
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-server
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api-server
  minReplicas: 3
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 75
Attempts:
2 left
💡 Hint
The autoscaling/v2 API uses a metrics array with resource type and target details.
Troubleshoot
advanced
2:00remaining
Troubleshooting HPA not scaling up
You created an HPA for a deployment, but the pods never scale beyond 1 even when CPU usage is high. Which is the most likely cause?
AThe maxReplicas is set to 1, limiting scaling to a single pod.
BThe HPA minReplicas is set to 1, so it cannot scale beyond that.
CThe deployment's resource requests for CPU are not set, so HPA cannot calculate usage properly.
DThe deployment has too many replicas already running.
Attempts:
2 left
💡 Hint
Check the maxReplicas setting to see if it limits scaling.
Best Practice
expert
3:00remaining
Best practice for HPA metrics configuration
Which approach is best practice when configuring Horizontal Pod Autoscaler metrics for a web application that experiences variable CPU and memory usage?
AAvoid using metrics and set fixed replica counts to prevent unpredictable scaling.
BConfigure only memory usage metric because CPU usage fluctuates too much to be reliable.
CConfigure multiple metrics including CPU utilization and memory usage with appropriate targets to allow balanced scaling.
DConfigure only CPU utilization metric because memory usage is less important for scaling decisions.
Attempts:
2 left
💡 Hint
Consider how multiple metrics can improve scaling decisions.