본문 바로가기
인프라

쿠버네티스(Kubernetes) Deployment란?

by 유일리 2024. 1. 12.
쿠버네티스 Deployment란?

 

DeploymentPod와 Relicaset에 대한 관리를 제공하는 단위이다. Deployment는 Pod를 감싼 개념이라 생각할 수 있다.


Deployment 실습해보자.

1. YAML 파일 생성

vi deploy.yaml

 

deploy.yaml (파드 3개 생성)

apiVersion: apps/v1 # kubernetes resource 의 API Version
kind: Deployment # kubernetes resource name
metadata: # 메타데이터 : name, namespace, labels, annotations 등을 포함
  name: nginx-deployment
  labels:
    app: nginx
spec: # 메인 파트 : resource 의 desired state 를 명시
  replicas: 3 # 동일한 template 의 pod 을 3 개 복제본으로 생성합니다.
  selector:
    matchLabels:
      app: nginx
  template: # Pod 의 template 을 의미합니다.
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx # container 의 이름
        image: nginx:1.14.2 # container 의 image
        ports:
        - containerPort: 80 # container 의 내부 Port

 

2. 적용 및 조회, Auto-healing과 Scaling

kubectl apply -f deploy.yaml

 

파드 3개짜리 ReplicaSet을 만든 셈이다.

파드 하나를 지워도 ReplicaSet이 자동으로 하나를 다시 생성하는 것을 확인할 수 있다. (NAME, AGE 가 바뀜)

 

relica 개수를 5개로 바꿔보자.

kubectl scale deployment/nginx-deployment --replicas=5

개수를 3으로 다시 scale하면 terminate하는 것을 확인할 수 있다.

 

4. 삭제

kubectl delete deploy nginx-deployment

 

Pod IP는 클러스터 내에서만 사용 가능하다. minikube 내에 들어가서 확인해보자.

minikube ssh
curl -X GET <POD-IP> -vvv
ping <POD-IP>

 

댓글