Dev./Kubernetes & Helm

Kubernetes: ReplicaSet 적용하기

Ivan'show 2023. 9. 26.
728x90
반응형

레플리카 셋으로 pod 띄우기

레플리카 셋으로 3개의 파드를 만들어서 하나의 db 에 모든 파드들이 연결되어 있는지 확인해보자

# lion-rs.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: lion-app
  labels:
    app: lion-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: lion-app
  template:
    metadata:
      labels:
        app: lion-app
    spec:
      imagePullSecrets:
      - name: regcred
      containers:
      - name: lion-app
        image: likelion-cr-mh.kr.ncr.ntruss.com/lion-app:latest
        imagePullPolicy: Always # 기존의 이미지를 쓰지않고 항상 가져오게 끔
        envFrom:
        - secretRef:
            name: db-secret
        - configMapRef:
            name: django-config
        - secretRef:
            name: django-secret
        ports:
          - containerPort: 8000
        livenessProbe:
          httpGet:
            path: health/
            port: 8000
# db-pod.yaml
apiVersion: v1
kind: Pod
metadata:
  name: lion-db
  labels:
    app: lion-db
spec:
  imagePullSecrets:
  - name: regcred
  containers:
    - name: lion-db
      resources: # k8s extension 설치 후 resource 제약조건
        limits:
          memory: "128Mi"
          cpu: "500m"
      image: postgres:13
      imagePullPolicy: Always # 기존의 이미지를 쓰지않고 항상 가져오게 끔
      envFrom:
      - secretRef:
          name: db-secret
      ports: 
        - containerPort: 5432
      volumeMounts:
      - name: postgres-data
        mountPath: "var/lib/postgresql/data"
  volumes:
  - name: postgres-data
    emptyDir: {}

k get rs
kimminhyeok@Ivans-Mac lion-k8s % k get rs 
NAME       DESIRED   CURRENT   READY   AGE
lion-app   3         3         3       138m
k get po
kimminhyeok@Ivans-Mac lion-k8s % k get po
NAME             READY   STATUS    RESTARTS  
lion-app-2ss26   1/1     Running   0          
lion-app-hgs2h   1/1     Running   0          
lion-app-kp4lm   1/1     Running   0          
lion-db          0/1     Pending   0          
k exec -it lion-app-2ss26 -- /bin/sh
# inside of the container
python manage.py createsuperuser

각 컨테이너에 접속해서 쉘로 새로 생성된 유저정보를 확인 !

728x90
반응형

댓글