쿠버네티스에서 가장 기본적인 관리 단위가 Pod입니다. Pod는 하나 이상의 컨테이너 그룹을 포함하며, 컨테이너의 실행 상태를 단계별로 관리합니다. 주요 단계는 다음과 같습니다.
Phase | Description |
---|---|
Pending | Pod Lifecycle 의 첫 시작 단계 |
Pod 가 Node 에 할당되었지만 아직 Container 설정이 진행되고 있거나 실행 준비가 되지 않은 상태
쿠버네티스에서는 컨테이너의 상태를 주기적으로 점검(Health Check)하여 애플리케이션의 가용성을 높입니다. 이것을 Probe라고 합니다. Probe는 컨테이너가 정상 작동하는지를 주기적으로 확인하여 문제가 발생하면 재시작 등의 조치를 자동으로 수행합니다.
livenessProbe 생성
apiVersion: v1
kind: Pod
metadata:
labels:
test: liveness
name: liveness-http
spec:
containers:
- name: liveness
image: registry.k8s.io/e2e-test-images/agnhost:2.40
args:
- liveness
livenessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3 # 첫 번째 프로브를 수행하기 전 3초 대기
periodSeconds: 3 # kubelet이 3초마다 LivenessProbe를 실행
위 pod를 배포하면 아래와 같이 실패할 경우 재시작되는 것을 확인할 수 있다.
readliness Probe 생성
apiVersion: v1
kind: Pod
metadata:
labels:
test: readiness
name: readiness-http
spec:
containers:
- name: readiness
image: registry.k8s.io/e2e-test-images/agnhost:2.40
args:
- liveness
readinessProbe:
httpGet:
path: /healthz
port: 8080
httpHeaders:
- name: Custom-Header
value: Awesome
initialDelaySeconds: 3
periodSeconds: 3
위 pod를 배포하면 아래와 같이 확인할 수 있다. liveness probe와 달리 컨테이너를 재기동하지 않으며 트래픽을 차단한다.
쿠버네티스에서 리소스를 생성하거나 변경하기 위해 사용하는 YAML 파일을 Manifest라고 합니다. Manifest는 관리가 복잡할 수 있어서, 다양한 도구를 통해 효율적으로 관리합니다.
디렉토리 구조
Kustomize 실행
# kustomize 설치
brew install kustomize
resources:
- pod.yaml
images:
- name: nginx
newName: new-nginx
newTag: 1.23.1
apiVersion: v1
kind: Pod
metadata:
labels:
name: nginx
name: nginx
spec:
containers:
- image: nginx:latest
name: nginx
resources:
limits:
cpu: 100m
memory: 64Mi
kubectl kustomize <PATH>
위 명령어를 실행하면 기존의 pod를 수정하지 않고 필드만 재정의된 것을 확인할 수 있다.
쿠버네티스의 패키지 매니저 역할을 하며, Manifest 파일을 쉽게 관리하고 배포할 수 있도록 도와줍니다.
# helm 생성
helm create myChart
# helm install <RELEASE_NAME> <패키지 경로> [flags]
helm install myapp .
# Helm Release 확인
helm list
# Helm 삭제
helm delete myapp
GitOps는 Git 저장소를 이용해 인프라 및 애플리케이션 배포를 자동화하는 방식을 말합니다.
쿠버네티스를 위한 대표적인 GitOps 도구 중 하나로, 지속적 배포(Continuous Delivery)를 수행합니다. Git 저장소의 변경을 모니터링하고, 선언된 상태를 클러스터에 자동으로 적용합니다.
구성 요소 | 역할 |
---|---|
API Server | 웹 UI, CLI, API를 통해 사용자와 상호작용하는 인터페이스 제공 |
Repository Server | Git 저장소로부터 Manifest(YAML 파일 등)를 가져와 처리 |
Application Controller | 클러스터의 상태와 Git 저장소의 상태를 비교하여 배포를 수행 |
Redis | 캐싱과 세션 상태 관리를 위한 저장소 |
각 구성 요소는 다음과 같은 방식으로 상호작용합니다.
# ArgoCD Namespace 생성
kubectl create ns argocd
# Helm Repo 등록
helm repo add argo https://argoproj.github.io/argo-helm
helm repo update
helm install argocd argo/argo-cd --set server.service.type=NodePort --namespace argocd
# ArgoCD 서비스 접근을 위한 노드포트 변경
kubectl patch svc argocd-server -n argocd \
-p '{"spec": {"ports": [{"port": 443, "targetPort": 8080, "nodePort": 31001}]}}'
# 리소스 확인
kubectl get all -n argocd
# 초기 비밀번호 확인
kubectl patch svc argocd-server -n argocd \
-p '{"spec": {"ports": [{"port": 443, "targetPort": 8080, "nodePort": 31001}]}}'