728x90
반응형
# 자동 스케일링 기능 구현
- 이전 사용한 리소스 삭제
kubectl delete all --all -n wordpress
kubectl delete pvc -n wordpress wp-pv-claim
kubectl delete pvc -n wordpress mysql-pv-claim
# resource limits 설정하기
쿠버네티스 공식사이트 > resource limits > 리소스 제한 코드 확인
vim wordpress-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress
namespace: wordpress
labels:
app: wordpress
spec:
ports:
- port: 80
selector:
app: wordpress
tier: frontend
type: LoadBalancer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: wp-pv-claim
namespace: wordpress
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: wordpress
namespace: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: frontend
template:
metadata:
labels:
app: wordpress
tier: frontend
spec:
nodeSelector:
app: wordpress
containers:
- resources:
requests:
memory: "500Mi"
cpu: "100m"
limits:
memory: "1024Mi"
cpu: "300m"
image: wordpress:4.8-apache
name: wordpress
env:
- name: WORDPRESS_DB_HOST
value: wordpress-mysql
- name: WORDPRESS_DB_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 80
name: wordpress
volumeMounts:
- name: wordpress-persistent-storage
mountPath: /var/www/html
volumes:
- name: wordpress-persistent-storage
persistentVolumeClaim:
claimName: wp-pv-claim
vim mysql-deployment.yaml
apiVersion: v1
kind: Service
metadata:
name: wordpress-mysql
namespace: wordpress
labels:
app: wordpress
spec:
ports:
- port: 3306
selector:
app: wordpress
tier: mysql
clusterIP: None
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-pv-claim
namespace: wordpress
labels:
app: wordpress
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 20Gi
---
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
name: wordpress-mysql
namespace: wordpress
labels:
app: wordpress
spec:
selector:
matchLabels:
app: wordpress
tier: mysql
template:
metadata:
labels:
app: wordpress
tier: mysql
spec:
nodeSelector:
app: mysql
containers:
- resources:
requests:
memory: "256Mi"
cpu: "50m"
limits:
memory: "512Mi"
cpu: "100m"
image: mysql:5.6
name: mysql
env:
- name: MYSQL_ROOT_PASSWORD
valueFrom:
secretKeyRef:
name: mysql-pass
key: password
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
# 폴더의 모든 yaml 파일을 실행하기
kubectl apply -k ./
# 확인하기
kubectl get pod -w -n wordpress
# hpa 적용하기
쿠버네티스 공식 사이트 > hpa 검색 > 워크스루
kubectl get pod -w -n wordpress
# 워드 프레스를 감시하는 hpa를 생성
kubectl autoscale deployment wordpress --cpu-percent=50 --min=1 --max=10 -n wordpress
kubectl autoscale deployment wordpress-mysql --cpu-percent=50 --min=1 --max=10 -n wordpress
# 워드 프레스를 감시하는 hpa를 조회
kubectl get hpa -w -n wordpress
- 부하가 증가하거나 트래픽이 많아진다면 replicas를 증가시켜 부하를 분산시킨다.
728x90
반응형
'⭐ Kubernetes & EKS > Kubernetes 예제' 카테고리의 다른 글
ClusterIP 에서 Nodeport 로 변경하는 방법 (0) | 2021.11.07 |
---|---|
쿠버네티스 예제를 활용한 애플리케이션 개발 (1) (0) | 2021.09.20 |