3.1. 쿠버네티스


3.1.1 쿠버네티스 구성

쿠버네티스는 마스터 노드와 워커 노드라는 두 가지 종류의 노드로 구성되어 있다.

# 쿠버네티스 정보 확인
myserver01:~$ kubectl cluster-info 
Kubernetes control plane is running at <https://10.0.2.4:6443>
CoreDNS is running at <https://10.0.2.4:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy>

# 노드 정보 확인
myserver01:~$ kubectl get nodes # 단수형도 상관 x
NAME           STATUS     ROLES             AGE       VERSION
myserver01     READY      control-plane     19m       v1.26.5
myserver02     READY      <none>            5m58s     v1.26.5
myserver03     READY      <none>            72s       v1.26.5

# 파드 목록 확인
myserver01:~$ kubectl get pod
NAME            READY     STATUS        RESTARTS    AGE
hello-world     0/1       Completed     0           38s
# 더 자세한 정보 확인
myserver01:~$ kubectl get pod -o wide
NAME            READY     STATUS        RESTARTS    AGE    IP                NODE         ...
hello-world     0/1       Completed     0           38s    192.168.131.2     myserver02   ...

# 파드 삭제
myserver01:~$ kubectl delete pod hello-world
	pod "hello-world" deleted
myserver01:~$ kubectl get pod
	No resources found in default namespace.

3.1.2 파드 실행

# 파드 실행
myserver01:~$ kubectl run hello-world --image=hello-world --restart=Always
	pod/heelo-world created

# 파드 정보와 서비스 정보 확인(CrashLoopBackOff: 컨테이너가 재시작되기 전 대기하고 있는 상태)
myserver01:~$ kubectl get all
NAME            READY     STATUS               RESTARTS       AGE
hello-world     0/1       CrashLoopBackOff     1 (12s ago)    38s

NAME                  TYPE        CLUSTER-IP     EXTERNAL-IP    PORT(S)    AGE
services/kubernetes   ClusterIP   10.96.0.1      <none>         443/TCP    3d18H

# 파드 삭제
myserver01:~$ kubectl delete pod hello-world
pod "hello-world" deleted

3.1.3. 매니페스트를 활용한 파드 실행

매니페스트란 쿠버네티스 오브젝트를 생성하기 위한 메타 정보를 YAML 혹은 JSON 형식으로 작성한 파일을 의미한다.

# nignx-test01.yml
apiVersion: v1           # apiVersion을 v1이라고 지정
kind: Pod                # 오브젝트의 종류를 pod로 지정
metadata:                # 생성하고자 하는 오브젝트의 메타 정보를 작성
	name: nginx01          # 다른 오브젝트들과 구분할 수 있는 식별자
spec:                    # 앞으로 생성할 파드의 상태를 지정
	containers:            # 파드에 포함될 컨테이너들을 지정
	- name: nginx-test01   # 파드에 포함될 컨테이너 이름을 nginx-test01 이라고 지정
	  image: nginx:latest  # 해당 컨테이너는 nginx:latest 이미지를 통해 생성
# yml 파일로 파드 실행
myserver01:~$ kubectl apply -f nginx-test01.yml

# yml 파일로 파드 삭제
myserver01:~$ kubectl delete -f nginx-test01.yml

3.2. 디플로이먼트


3.2.1. 디플로이먼트 개념

쿠버네티스에서는 파드를 관리하기 위해 디플로이먼트라는 개념을 사용한다. 그 전에 레플리카셋에 대해 먼저 알아야 한다.

레플리카셋은 명시되어 있고 유지해야 하는 파드 개수에 대한 가용성을 보증하는 데 사용된다. 일반적으로 레플리카셋을 직접 다루기보다는 디플로이먼트를 통해 관리하는 것이 더 편리하다. 디플로이먼트는 레플리카셋을 생성하고 업데이트하며, 필요에 따라 파드를 자동으로 조정해 항상 원하는 상태를 유지한다.