본문 바로가기

⭐ Kubernetes & EKS/디플로이먼트 (Deployment)

디플로이먼트 설명과 간단한 연습문제

# 디플로이먼트란?
디플로이먼트는 한마리도 관리자 라고 생각하면 쉽다.
systemd, runit, supervisord 와 비슷한 역할을 한다고 보면된다.
관리 프로그램은 컨테이너가 실행중인지 계속 확인하고, 정지될 경우 즉시 다시시작 해야한다.

- 쿠버네티스는 각 프로그램을 관리하기 위해 디플로이먼트 오브젝트를 생성한다. 디플로이먼트 오브젝트에는 해당 프로그램에 대한 정보(컨테이너 이미지 이름, 실행할 레플리카 수동 컨테이너를 실행하기 위해 알아야 하는 모든 정보)가 기록된다.

- 실행 명령어: kubectl describe deployment/deploy-jenkins

kubectl describe deployment/deploy-jenkins

kubectl describe deployment/<pod_name> #pod_name은 yaml을 생성할때 작성한 name을 적어주면 된다.
ec2-user:~/environment/yaml $ kubectl describe deployment/deploy-jenkins
Name:                   deploy-jenkins
Namespace:              default
CreationTimestamp:      Sat, 09 Oct 2021 04:29:20 +0000
Labels:                 app=jenkins-test
Annotations:            deployment.kubernetes.io/revision: 1
Selector:               app=jenkins-test
Replicas:               3 desired | 3 updated | 3 total | 0 available | 3 unavailable
StrategyType:           RollingUpdate
MinReadySeconds:        0
RollingUpdateStrategy:  25% max unavailable, 25% max surge
Pod Template:
  Labels:  app=jenkins-test
  Containers:
   jenkins:
    Image:        jenkins/jenkins:lts
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>
Conditions:
  Type           Status  Reason
  ----           ------  ------
  Available      False   MinimumReplicasUnavailable
  Progressing    False   ProgressDeadlineExceeded
OldReplicaSets:  <none>
NewReplicaSet:   deploy-jenkins-7dcdf75b94 (3/3 replicas created)
Events:
  Type    Reason             Age   From                   Message
  ----    ------             ----  ----                   -------
  Normal  ScalingReplicaSet  27m   deployment-controller  Scaled up replica set deploy-jenkins-7dcdf75b94 to 3
ec2-user:~/environment/yaml $

- 위에 정보에서 Pod Template 부분을 유심히 보면 pod 실행 정보를 담고 있는것을 볼 수 있다.

Pod Template:
  Labels:  app=jenkins-test
  Containers:
   jenkins:
    Image:        jenkins/jenkins:lts
    Port:         8080/TCP
    Host Port:    0/TCP
    Environment:  <none>
    Mounts:       <none>
  Volumes:        <none>

# 디플로이먼트 소개와 연습문제
- 디플로이먼트는 레플리카셋을 도와주는 역할
- 작성요령은 레플리카셋과 동일하다.

# jenkins를 디플로이먼트로 생성하는 연습문제
- 쿠버네티스 공식 사이트 > 검색 > deploy > deployment > kind: > 소스복사

# 실행파일 생성

vim jenkins-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: deploy-jenkins
  labels:
    app: jenkins-test
spec:
  replicas: 3
  selector:
    matchLabels:
      app: jenkins-test
  template:
    metadata:
      labels:
        app: jenkins-test
    spec:
      containers:
      - name: jenkins
        image: jenkins/jenkins:lts
        ports:
        - containerPort: 8080
kubectl create -f jenkins-deploy.yaml

kubectl get all

kubectl get pod

# pod을 일부러 삭제하기

kubectl delete pod [pod id] 

kubectl get pod

- 정상적으로 돌아온것을 확인 가능

kubectl get rs
kubectl describe rs [pod-id]

# 레이블 삭제

kubectl get pod

kubectl get pod --show-labels

# app과 관련된 레이블 삭제

kubectl label pod [pod-id] app-

kubectl get pod

# 스케일링하기

kubectl scale deploy deploy-jenkins --replicas=5

# app이 있는 pod만 조회하기

kubectl get pod -l app