CKA 2025 MOCK Q-05 HPA
5 Mock Questions on Horizontal Pod Autoscaler (HPA)
🔶 Question 1: Scale Based
on Custom CPU Target and Scale-Up Cooldown
You have a Deployment named api-backend in the default
namespace.
Task:
- Create
an HPA targeting 70% CPU usage
- Min:
1, Max: 10 replicas
- Set scale-up
cooldown (delay before scaling up again) to 30 seconds
- File
name: hpa-backend.yaml
Bonus: Set the HPA to avoid scaling up rapidly even
if CPU spikes.
cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: api-backend
namespace: default
spec:
replicas: 2
selector:
matchLabels:
app: api-backend
template:
metadata:
labels:
app: api-backend
spec:
containers:
- name: backend
image: nginx
ports:
- containerPort:
80
resources:
requests:
cpu: "100m"
limits:
cpu: "200m"
EOF
Solution: Create HPA with
Scale-Up Cooldown (hpa-backend.yaml)
vi hpa-backend.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: api-backend-hpa
namespace: default
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-backend
minReplicas: 1
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
behavior:
scaleUp:
stabilizationWindowSeconds:
30 # Don't scale up again until 30 sec
cool down
📜 Commands:
kubectl apply -f deploy-backend.yaml
kubectl apply -f hpa-backend.yaml
kubectl get hpa api-backend-hpa -w
Comments
Post a Comment