728x90
Deployment with HPA
# DEPOLOYMENT
apiVersion: apps/v1
kind: Deployment
metadata: # Deployment object 자신의 고유 정보
name: ${APP_NAME} # Deployment object에 대한 Unique-key
spec:
replicas: ${REPLICA_QUANTITY} # 초기 Pod의 개수를 설정
minReadySeconds: 10 # Pod이 Ready 단계가 된 후, Available 단계가 될 때 까지의 시간 차이
revisionHistoryLimit: 2 # replicaset 이전버전 보관수
strategy:
type: RollingUpdate # RollingUpdate에 대한 상세 설정. “Recreate” or “RollingUpdate”를 설정 가능 합니다. 기본값은 “RollingUpdate” 입니다. Recreate의 경우 Pod가 삭제된 후 재생성.
rollingUpdate:
maxUnavailable: 25%
selector: # Deployment object가 관리해야할 Pod이 어떤 것인지 찾기 위해 selector 정보로 Pod의 label 정보를 비교하고 관리
matchLabels:
app: ${APP_NAME}
template: # Deployment object가 생성할 Pod 관련 설정
metadata:
labels:
app: ${APP_NAME}
spec:
imagePullSecrets:
- name: myregistrykey
hostAliases:
containers:
- name: ${APP_NAME}
image: ${IMAGE}
imagePullPolicy: Always # Always download images, **IfNotPresent : Use cached images first
ports:
- name: http
containerPort: 8080 # ==============> targetPort와 맞춰주세요 <=====================
resources:
requests: # 컨테이너가 요청할 최소한의 리소스에 대한 설정입니다. Spring Boot 애플리케이션의 경우는 메모리 값을 256M 이상으로 설정
memory: ${REQUESTS_MEMORY}
cpu: ${REQUESTS_CPU}
limits: # 컨테이너가 최대한으로 사용할 리소스에 대한 설정입니다. 애플리케이션에 따라 적절한 CPU와 메모리 값으로 설정
memory: ${LIMITS_MEMORY}
cpu: ${LIMITS_CPU}
livenessProbe:
httpGet:
path: /service/healthy
port: 8080
initialDelaySeconds: 60
failureThreshold: 10
periodSeconds: 30
readinessProbe:
httpGet:
path: /service/healthy
port: 8080
initialDelaySeconds: 60 # 컨테이너가 시작된 후 프로브를 보내기 전에 기다리는 시간
failureThreshold: 5
periodSeconds: 15 # 검사를 보내는 빈도. 보통 10~20초 사이로 세팅
lifecycle: # 20 초의 동기식 유예 기간을 선택. 포드 종료 프로세스는이 대기 시간 후에 만 계속됨
preStop:
exec:
command: ["sh", "-c", "sleep 20"]
env:
- name: DRIVER_URL
valueFrom:
configMapKeyRef:
key: DRIVER_URL
name: application-cm
- name: EMAIL_RECEIVER_URL
valueFrom:
configMapKeyRef:
key: EMAIL_RECEIVER_URL
name: application-cm
- name: DB_USERNAME
valueFrom:
secretKeyRef:
key: DB_USERNAME
name: db-secret
optional: false
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
key: DB_PASSWORD
name: db-secret
optional: false
---
# HPA(Horizonal Pod AutoScaler) # Horizonal Pod AutoScaler 적용
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: ${APP_NAME}-hpa # HorizontalPodAutoscaler object 자신의 고유 정보를 입력
spec: # HorizontalPodAutoscaler object가 수행하는 내용에 대한 설정
maxReplicas: ${MAX_QUANTITY} # 업스케일 시 생성할 수 있는 Pod의 최대수
minReplicas: ${MIN_QUANTITY} # 다운스케일 시 생성할 수 있는 Pod의 최소수
scaleTargetRef: # HorizontalPodAutoscaler object가 동작할 대상에 대한 설정
apiVersion: apps/v1
kind: Deployment
name: ${APP_NAME}
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 60
ConfigMap, Secret for Application
# ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: application-cm
data:
DRIVER_URL: ${DRIVER_URL}
EMAIL_RECEIVER_URL: ${EMAIL_RECEIVER_URL}
---
# Secret
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
DB_USERNAME: XXXXXXX
DB_PASSWORD: XXXXXXX
---
apiVersion: v1
kind: Secret
metadata:
name: email-receiver
type: Opaque
data:
APPMAIL_USERNAME: XXXXXXXXXXX
APPMAIL_PASSWORD: XXXXXXXXXXX
Service
apiVersion: v1
kind: Service
metadata:
name: ${APP_NAME}-service
spec: # Service object를 노출하기 위한 방식을 설정
type: ClusterIP
selector: # Service object가 요청을 전달할 Pod을 찾기위한 검색어
app: ${APP_NAME} # app이름으로 Pod의 label이 같은 pod를 찾아 요청을 전달, 찾은 Pod이 여러개인 경우 load balancing 정책에 따라 하나의 Pod을 선택함.
ports:
- name: http
protocol: TCP
port: 80 # 외부에서 접속 port ====> application 접속포트 확인하세요
targetPort: 8080 # Service object로 들어온 요청을 전달할 target이되는 Pod이 노출하고 있는 포트.(pod 내의 container 연결포트)
Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ${APP_NAME}-alb-ingress
annotations:
kubernetes.io/ingress.class: alb
alb.ingress.kubernetes.io/healthcheck-path: /service/healthy
alb.ingress.kubernetes.io/target-type: ip
alb.ingress.kubernetes.io/subnets: subnet-0b2436d34db03228d, subnet-01d461f0bd67ca737 ## Update the subnet name
alb.ingress.kubernetes.io/load-balancer-attributes: idle_timeout.timeout_seconds=1800
alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}]'
spec:
rules:
- host: test1.armyost.com ## Update the host url
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: test1-service ## Update the service name
port:
number: 80
- host: test2.armyost.com ## Update the host url
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: test2-service ## Update the service name
port:
number: 80
- host: test3.armyost.com ## Update the host url
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: test3-service ## Update the service name
port:
number: 80
'PaaS > Kubernetes' 카테고리의 다른 글
Kubernetes Dashboard를 외부로 노출시키기 위한 Ingress 작업 (1) | 2023.11.13 |
---|---|
Ingress에서 Rewrite Target 사용하기 (0) | 2023.11.09 |
OIDC 인증으로 특정 Service Account에 대해 Kubelet API 호출하기 (1) | 2023.11.08 |
k8s 보안, 최소권한으로 특정 NameSpace에 대한 권한만 부여하기 (0) | 2023.11.08 |
GCP가 말하는 Kubernetes를 GCP에서 운영해야 하는 이유 (0) | 2023.11.03 |