[쿠버네티스] 리소스쿼터 + 3계층 배포

최동혁·2023년 4월 28일
0

쿠버네티스

목록 보기
6/7

네임스페이스 생성

cdh-dev 2Gi 3Gi min:0.1 max:0.5
cdh-prod 4Gi 5Gi min:1 max:2

cdh-dev

apiVersion: v1
kind: Namespace
metadata:
  name: cdh-dev

리소스 쿼터

apiVersion: v1
kind: ResourceQuota
metadata:
  name: rq-1
  namespace: cdh-dev
spec:
  hard:
    requests.memory: 2Gi
    limits.memory: 3Gi

LimitRange

apiVersion: v1
kind: LimitRange
metadata:
  name: lr-1
  namespace: nm-3
spec:
  limits:
  - type: Container
    min:
      memory: 0.1Gi
    max:
      memory: 0.5Gi
    maxLimitRequestRatio:
      memory: 3
    defaultRequest:
      memory: 0.1Gi
    default:
      memory: 0.2Gi

DB

MySQL 서비스

apiVersion: v1
kind: Service
metadata:
  name: db-svc
spec:
  selector:
    type: db
  ports:
  - port: 3306
    targetPort: 3306

MySQL configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: db-cm
data:
  MYSQL_ROOT_PASSWORD: "qwer1234"

MySQL 파드

apiVersion: v1
kind: Pod
metadata:
  name: db-pod
  labels:
    type: db
spec:
  containers:
  - name: container
    image: mysql:8.0.32-debian
    resources:
      limits:
        memory: "0.5Gi"
      requests:
        memory: "0.4Gi"
    envFrom:
    - configMapRef:
        name: db-cm
  • 최소 메모리 요청(request): 0.1Gi
  • 최대 메모리 요청(request): 0.5Gi
  • 최대 메모리 제한(limit): 3Gi
  • 최소 메모리 요청(request)은 LimitRange 설정인 0.1Gi보다 크므로, 이 조건은 만족합니다.
  • 최대 메모리 요청(request)은 LimitRange 설정인 0.5Gi보다 작으므로, 이 조건은 만족합니다.
  • 최대 메모리 제한(limit)은 LimitRange 설정인 0.5Gi보다 작으므로, 이 조건은 만족합니다.
  • 네임스페이스 내 모든 파드의 메모리 요청(request) 합계가 resource quota인 2Gi를 초과하지 않으므로, 이 조건도 만족합니다.

WAS

gunicorn 서비스

apiVersion: v1
kind: Service
metadata:
  name: backend-svc
spec:
  selector:
    type: backend
  ports:
  - port: 8000
    targetPort: 8000

gunicorn configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: backend-cm
data:
  DBNAME: "web"
  DBUSER: "root"
  DBPASS: "qwer1234"
  DBHOST: "db-svc"
  DBPORT: "3306"

gunicorn 파드

apiVersion: v1
kind: Pod
metadata:
  name: backend-pod
  labels:
    type: backend
spec:
  containers:
  - name: container
    image: ddarahakit2023/back:1.0
    command: ["/bin/sh", "-ec", "python manage.py migrate && gunicorn config.wsgi --bind 0.0.0.0:8000"]
    resources:
      limits:
        memory: "0.5Gi"
      requests:
        memory: "0.4Gi"
    envFrom:
    - configMapRef:
        name: backend-cm

WS

nginx 서비스

apiVersion: v1
kind: Service
metadata:
  name: frontend-svc
spec:
  selector:
    type: frontend
  ports:
  - port: 80
    targetPort: 80
  type: LoadBalancer

nginx configmap

apiVersion: v1
kind: ConfigMap
metadata:
  name: frontend-cm
data:
  BACKEND_SVC_NAME: "backend-svc"

nginx 파드

apiVersion: v1
kind: Pod
metadata:
  name: frontend-pod
  labels:
    type: frontend
spec:
  containers:
  - name: container
    image: cis07385/front:1.1
    command: ["/bin/sh", "-ec", "envsubst '$BACKEND_SVC_NAME' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"]
    resources:
      limits:
        memory: "0.5Gi"
      requests:
        memory: "0.4Gi"
    envFrom:
    - configMapRef:
        name: frontend-cm

cdh-prod

apiVersion: v1
kind: Namespace
metadata:
  name: cdh-prod

리소스 쿼터

apiVersion: v1
kind: ResourceQuota
metadata:
  name: rq-1
  namespace: cdh-prod
spec:
  hard:
    requests.memory: 4Gi
    limits.memory: 5Gi
profile
항상 성장하는 개발자 최동혁입니다.

0개의 댓글