apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-deployment
namespace: wsi-skills-namespace-2
labels:
app: backend-deployment
spec:
replicas: 2
selector:
matchLabels:
app: backend-deployment
template:
metadata:
labels:
app: backend-deployment
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: worker2 #Node Key
operator: In
values:
- backend #Node Value
containers:
- name: wsi-skills-container
image: [Dockerimage]
ports:
- containerPort: 8080
resources:
requests:
cpu: "250m"
memory: "256Mi" #이 부분을 설정해야합니다.
limits:
cpu: "512m"
memory: "512Mi" #이 부분을 설정해야합니다.
---
apiVersion: v1
kind: Service
metadata:
name: wsi-stress-service
labels:
app: backend-deployment
namespace: wsi-skills-namespace-2
annotations:
alb.ingress.kubernetes.io/healthcheck-path: "/상태검사 경로"
spec:
selector:
app: backend-deployment
type: NodePort
ports:
- port: [Service Port]
targetPort: [TargetGroup Port]
protocol: TCP
cat << EOF > memoryhpa.yaml
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: memory-hpa
namespace: wsi-skills-namespace-2
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: backend-deployment
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageValue: 10Mi
EOF
kubectl apply -f memoryhpa.yaml
kubectl get hpa -n wsi-skills-namespace-2 -w #실시간 확인
왼쪽이 Pod에 memory 사용률이고 오른쪽이 HPA 조건입니다. Pod에 memory는 bytes 으로 표시되는 겁니다. 즉, 3813376을 Mi(메비 바이트)로 변환하면 3.6 정도 크기가 됩니다