vi my-nginx.yml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: my-nginx
name: my-nginx
spec:
replicas: 1
selector:
matchLabels:
run: my-nginx
template:
metadata:
labels:
run: my-nginx
spec:
containers:
- image: nginx
name: my-nginx
resources:
# requests ⇒ pod를 만들때 최소 리소스 설정
requests:
# 250m ⇒ 0.25 CPU
cpu: 250m
memory: 64Mi
# 최대 리소스 설정
limits:
cpu: 500m
memory: 128Mi
vi hpa.yml
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: my-nginx-hpa
namespace: default
spec:
scaleTargetRef:
kind: Deployment
apiVersion: apps/v1
name: my-nginx
# 최대 replicas 수
maxReplicas: 4
minReplicas: 1
metrics:
- type: Resource
resource:
# 대상 cpu 가 20%를 초과하면 확장한다.
name: cpu
targetAverageUtilization: 20
kubectl apply -f my-nginx.yml -f hpa.yml
#해당 pod shell 접근
apt update
apt install vim
vi shell.sh
#!/bin/bash
START=0
END=1000000000000000000
while [ $START -le $END ]
do
START=`expr $START + 1`
done
chmod 777 shell.sh
./shell.sh
#다른 콘솔창에서 확인한다.
kubectl get pods
kubectl top pod
kubectl get hpa