반응형
[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 ~ ➜반응형
'Compute > kubernetis' 카테고리의 다른 글
| 31. 새로 추가된 시험 유형 - 5 / helm Argo cd설치 (0) | 2025.11.07 |
|---|---|
| 31. 새로 추가된 시험 유형 - 4 / CNI 플러그인 설치 Flannel, Calico (0) | 2025.11.06 |
| 31. 새로 추가된 시험 유형 - 2 / Gateway API Migration (0) | 2025.11.06 |
| 31. 새로 추가된 시험 유형 - 1 / configmap 수정 (0) | 2025.11.06 |
| 쿠버네티스 kubernetis 환경에서의 인터페이스 구성 ovs / veth / bridge (0) | 2025.04.07 |