본문 바로가기

Infra/쿠버네티스 입문

쿠버네티스 입문 (5) - 레플리카세트

728x90

- Pods는 언제든지 중지될 수 있기 때문에 레플리카 세트로 Pods 묶어서 집합체로 만든다.

- k8s 레플리카 세트로 인스턴스를 관리한다.

 

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: webapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: webapp
  template:
    metadata:
      labels:
        app: webapp
    spec:
      containers:
      - name: webapp
        image: richardchesterwood/k8s-fleetman-webapp-angular:release0-5
---
apiVersion: v1
kind: Pod
metadata:
  name: queue
  labels:
    app: queue
    release: "1"

spec:
  containers:
  - name: queue
    image: richardchesterwood/k8s-fleetman-queue:release1

- 레플리카 세트 수를 1개로 webapp을 처리했다.

 

apiVersion: v1
kind: Service
metadata:
  name: fleetman-webapp

spec:
  ports:
    - name: http
      port: 80
      nodePort: 30080

  selector:
    app: webapp

  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  name: fleetman-queue

spec:
  ports:
    - name: http
      port: 8161
      nodePort: 30010

  selector:
    app: queue

  type: NodePort

- 서비스도 알맞게 label을 수정해줬다.

- 이제 하나를 강제로 종료해도 1개가 계속 k8s에서 유지된다.

300x250