Master Node의 구성 요소
Worker Node의 구성 요소 ( 물론 Master Node에도 설치되는 요소들 )
Kube API Server 중심으로 처리되는 Pod 생성 과정
Kubernetes Resource - Pod
# 1. API 버전: 파드를 생성할 것이므로 'v1'을 사용합니다.
apiVersion: v1
# 2. Kind: 생성할 리소스의 종류는 'Pod'입니다.
kind: Pod
# 3. Metadata: 파드에 대한 부가 정보입니다.
metadata:
# 파드의 고유한 이름
name: my-app-pod
# 파드를 식별하고 그룹화하기 위한 라벨 (key-value 쌍)
labels:
app: my-app
tier: frontend
# 4. Spec: 파드의 상세 명세입니다.
spec:
# 이 파드에서 실행될 컨테이너들의 목록 (리스트/배열 형태)
containers:
# 리스트의 첫 번째 아이템을 의미하는 '-'
- name: nginx-container
image: nginx
Kubernetes Resource - ReplicaSet
# 1. API 버전: ReplicaSet은 'apps/v1'을 사용합니다. (ReplicationController는 'v1')
apiVersion: apps/v1
# 2. Kind: 생성할 리소스는 'ReplicaSet' 입니다.
kind: ReplicaSet
# 3. Metadata: ReplicaSet 자체의 이름과 라벨을 정의합니다.
metadata:
name: my-app-replicaset
labels:
app: my-app
tier: frontend
# 4. Spec: ReplicaSet의 상세 명세입니다.
spec:
# 생성하고 유지할 파드의 개수
replicas: 3
# ★★★ ReplicaSet이 관리할 파드를 찾는 기준 (필수 항목)
selector:
matchLabels:
tier: frontend
# ★★★ 생성할 파드의 설계도 (Pod Template)
template:
metadata:
# 위 selector의 matchLabels와 일치해야 합니다.
labels:
tier: frontend
spec:
containers:
- name: nginx
image: nginx
Kubernetes Resource - Deployment
# API 버전: ReplicaSet과 동일하게 'apps/v1'을 사용합니다.
apiVersion: apps/v1
# ★★★ Kind: 생성할 리소스가 'Deployment'임을 명시합니다.
kind: Deployment
# Deployment 자체의 이름과 라벨을 정의합니다.
metadata:
name: my-app-deployment
# Deployment의 상세 명세입니다. (ReplicaSet과 구조가 동일)
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: nginx
image: nginx
Kubernetes Resource - Service
ClusterIP Service
# 1. API 버전
apiVersion: v1
# 2. Kind: 생성할 리소스는 'Service' 입니다.
kind: Service
# 3. Metadata: 서비스의 이름을 정의합니다. 이 이름이 내부 DNS 이름이 됩니다.
metadata:
name: backend-service
# 4. Spec: 서비스의 상세 명세입니다.
spec:
# ★★★ 서비스 타입을 'ClusterIP'로 지정
# 참고: type을 생략하면 기본값이 ClusterIP이므로, 이 줄은 생략 가능합니다.
type: ClusterIP
# 서비스를 연결할 파드를 찾는 셀렉터
selector:
app: backend
tier: api
# 포트 매핑 정보
ports:
- protocol: TCP
port: 80 # 서비스 자체가 사용할 포트
targetPort: 8080 # 파드가 실제로 사용하는 포트
NodePort Service
# 1. API 버전
apiVersion: v1
# 2. Kind: 생성할 리소스는 'Service' 입니다.
kind: Service
# 3. Metadata: 서비스의 이름을 정의합니다.
metadata:
name: my-app-service
# 4. Spec: 서비스의 상세 명세입니다.
spec:
# 서비스의 타입을 'NodePort'로 지정
type: NodePort
# ★★★ 서비스를 연결할 파드를 찾는 방법 (필수 항목)
selector:
app: my-app
# 포트 매핑 정보를 정의 (리스트 형태)
ports:
- protocol: TCP
port: 80 # 서비스 자체의 포트
targetPort: 80 # 파드의 포트
nodePort: 30008 # 노드에 외부에 개방될 포트
Kubernetes Resource - Namespace
apiVersion: v1
kind: Namespace
metadata:
name: dev
apiVersion: v1
kind: ResourceQuota
metadata:
name: compute-quota
namespace: dev
spec:
hard:
pods: "10"
requests.cpu: "4"
requests.memory: 5Gi
limits.cpu: "10"
limits.memory: 10Gi
Kubernetes Resource 관리 방식 : 명령형 vs 선언형