본문 바로가기
Compute/kubernetis

31. 새로 추가된 시험 유형 - 3 / HPA 생성

by 조청유곽 2025. 11. 6.
반응형

[Question]

Create a new HorizontalPodAutoscaler (HPA) named apache-server in the autoscale namespace. 
This HPA must target the existing Deployment called apache-server in the autoscale namespace.

Set the HPA to target for 50% CPU usage per pod.

• Configure hpa to have at min 1 Pod and no more than 4 Pods[max]. Also, 
we have to set the downscale stabilization window to 30 seconds.

 


 

[Precondition]

(1) Namespace 및 deployment 준비

controlplane ~ ➜  kubectl create namespace autoscale
namespace/autoscale created

controlplane ~ ➜  kubectl create deployment apache-server -n auto-scale --dry-run=client --image=nginx -o yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: apache-server
  name: apache-server
  namespace: auto-scale
spec:
  replicas: 1
  selector:
    matchLabels:
      app: apache-server
  strategy: {}
  template:
    metadata:
      labels:
        app: apache-server
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

controlplane ~ ➜

 

 


[Solve]

- HPA 생성 

- spec의 behavior 섹션 추가 

controlplane ~ ➜  kubectl autoscale deployment apache-server -n autoscale --min=1 --max=4 --cpu=50% --dry-run=client -o yaml > 31.hpa.yaml

controlplane ~ ➜  nano 31.hpa.yaml 

## 아래의 behavior 섹션 추가
behavior:
  scaleDown:
    stabilizationWindowSeconds: 30

controlplane ~ ➜  cat 31.hpa.yaml 
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: apache-server
spec:
  maxReplicas: 4
  metrics:
  - resource:
      name: cpu
      target:
        averageUtilization: 50
        type: Utilization
    type: Resource
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: apache-server
  behavior:
    scaleDown:
      stabilizationWindowSeconds: 30
status:
  currentMetrics: null
  desiredReplicas: 0

controlplane ~ ➜  kubectl apply -f 31.hpa.yaml 
horizontalpodautoscaler.autoscaling/apache-server created

controlplane ~ ➜
반응형