[쿠버네티스 어나더 클래스 (지상편) - Sprint 1] 04. Object를 그려보며 쿠버네티스 이해 (강의를 보고)Tech/Kubernetes(K8s)2025. 5. 30. 15:07
Table of Contents
* 본 게시물은 쿠버네티스 어나더 클래스 (지상편) - Sprint 1, 2 강의와 강의 자료를 바탕으로 작성되었습니다.

[1] Cluster Level Object
Namespace
- Object들을 Grouping해주는 역할
apiVersion: v1
kind: Namespace
metadata:
name: anotherclass-123
labels:
part-of: k8s-anotherclass
managed-by: dashboard
PV (PersistentVolume)
- 실제 Volume을 지정하는 역할
- local: path: (지정된 경로를 Volume으로 사용하겠다는 의미)
(지정한 path에는 디렉터리가 미리 생성되어 있어야 함) - nodeAffinity: (지정된 node의 disk를 Volume으로 이용)
- (nodeAffinity에 적힌 node내 disk의 path를 Volume으로 이용)
apiVersion: v1
kind: PersistentVolume
metadata:
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
version: 1.0.0
managed-by: dashboard
spec:
capacity:
storage: 2G
volumeMode: Filesystem
accessModes:
- ReadWriteMany
local:
path: "/root/k8s-local-volume/1231"
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- {key: kubernetes.io/hostname, operator: In, values: [k8s-master]}
Namespace Level Object
PVC (PersistentVolumeClaim)
- PV(Persistent Volume)을 지정할 때 사용
- storage: (저장공간을 얼마나 사용할 지 지정)
- accessModes: (저장 공간의 읽기/스기 옵션 지정)
(selector를 통해 PV를 지정하고 있는 것을 볼 수 있음)
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
namespace: anotherclass-123
name: api-tester-1231-files
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: kubectl
spec:
resources:
requests:
storage: 2G
accessModes:
- ReadWriteMany
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231-files
Deployment
- Pod를 만들고 업그레이드를 해주는 역할
- metadata
- namespace: (해당 namespace에 소속됨을 나타냄)
- name: (같은 Object 내에서 중복이 되면 안 됨)
- replicas: (Pod를 몇 개 만들지 지정)
- template: (아래에 담긴 내용대로 Pod가 만들어짐)
- nodeSelector: (pod를 띄울 Node를 선택)
- containers:
- image: 지정된 경로에서 이미지를 다운로드 (prefix에 레지스트리를 명시하지 않으면, DockerHub가 표준)
- envFrom: (환경 변수값 제공)
- startupProbe: (App이 잘 기동되었는지 확인하고 기동되지 않았다면 재기동 시킴)
(정상적으로 기동되었다면 나머지 2개의 Probe를 실행) - readinessProbe: (App이 외부 트래픽을 받을 준비가 되었는 지 판단하는 속성)
- livenessProbe: (App이 정상 동작 중인지 확인하는 속성. 만약, 정상이 아니라면 재시작시킴)
- resource:
- request: (Pod 하나에 CPU/Memory 자원을 할당)
- limits: (최대 자원을 설정. 설정하지 않으면 자원을 모두 사용함)
- volumeMounts:
- name: (해당 Volume 이름)
- mountPath: (Pod 내부에 만들어지는 디렉터리)
- volumes:
- - name: (volumeMounts의 name과 같으면 아래의 Object와 연결됨)
- persistentVolumeClaim:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
matchLabels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
replicas: 2
strategy:
type: RollingUpdate
template:
metadata:
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
spec:
nodeSelector:
kubernetes.io/hostname: k8s-master
containers:
- name: api-tester-1231
image: 1pro/api-tester:v1.0.0
ports:
- name: http
containerPort: 8080
envFrom:
- configMapRef:
name: api-tester-1231-properties
startupProbe:
httpGet:
path: "/startup"
port: 8080
periodSeconds: 5
failureThreshold: 36
readinessProbe:
httpGet:
path: "/readiness"
port: 8080
periodSeconds: 10
failureThreshold: 3
livenessProbe:
httpGet:
path: "/liveness"
port: 8080
periodSeconds: 10
failureThreshold: 3
resources:
requests:
memory: "100Mi"
cpu: "100m"
limits:
memory: "200Mi"
cpu: "200m"
volumeMounts:
- name: files
mountPath: /usr/src/myapp/files/dev
- name: secret-datasource
mountPath: /usr/src/myapp/datasource
volumes:
- name: files
persistentVolumeClaim:
claimName: api-tester-1231-files
- name: secret-datasource
secret:
secretName: api-tester-1231-postgresql
Service
- Pod에 외부 트래픽을 연결시켜주는 역할
apiVersion: v1
kind: Service
metadata:
namespace: anotherclass-123
name: api-tester-1231
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
selector:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
ports:
- port: 80
targetPort: http
nodePort: 31231
type: NodePort
ConfigMap, Secret
- ConfigMap은 Pod의 환경 변수 값을 제공하는 역할
- data: (환경 변수로 들어갈 내용)
- Secret은 ConfigMap과 비슷하지만, Pod에 조금 더 중요한 값을 제공하는 역할
- stringData: (중요한 값이 담긴 파일 생성)
(아래 yaml에서는 `postgresql-info.yaml`에 담김)
- stringData: (중요한 값이 담긴 파일 생성)
apiVersion: v1
kind: ConfigMap
metadata:
namespace: anotherclass-123
name: api-tester-1231-properties
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
data:
spring_profiles_active: "dev"
application_role: "ALL"
postgresql_filepath: "/usr/src/myapp/datasource/postgresql-info.yaml"
---
apiVersion: v1
kind: Secret
metadata:
namespace: anotherclass-123
name: api-tester-1231-postgresql
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
stringData:
postgresql-info.yaml: |
driver-class-name: "org.postgresql.Driver"
url: "jdbc:postgresql://postgresql:5431"
username: "dev"
password: "dev123"
HPA
- 부하에 따라 Pod를 늘려주고 줄여주는 스케일링 역할
- scaleTargetRef: (스케일 대상 지정)
- kind: Deployment
- minReplicas: (최소 Pod 개수 유지)
- maxReplicas: (부하 발생 시, 늘어날 최대 Pod 개수)
- metrics:
- resource:
- name: cpu
- target:
- type: Utilization
- averageUtilization: 40 (CPU 평균 사용률이 40%에 도달하면 scaleOut 하도록 설정)
- resource:
- behavior
- scaleUp:
- stabilizationWindowSeconds: (Pod 증가 후, 지정된 시간 동안은 Pod가 증가하지 않도록 함)
- scaleUp:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
namespace: anotherclass-123
name: api-tester-1231-default
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-tester-1231
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
behavior:
scaleUp:
stabilizationWindowSeconds: 120
생성된 Object의 제거
# Namespace 제거
kubectl delete ns anotherclass-123
# PV 제거
kubectl delete pv api-tester-1231-files- PV는 Namespace Level Object가 아니기 때문에, 따로 제거를 해줘야 함
각 Object에는 공통으로 labels 속성이 있음

labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard- labels는 Object에 걸려있는 App의 정보를 바로 파악하기 위해 사용하고 selector와 매칭이 돼, 두 Object를 연결할 때도 이용
- part-of: (App 전체 이름)
- component: (구성요소)
- name: (App 이름)
- instance: (인스턴스 식별 / name + instance 조합으로 사용됨)
- version: (App 버전, 변경 시 수정 필요)
- managed-by: (배포 도구 > Object 생성 주체 확인 용도)
- naming (정해진 관례는 없지만, 어느정도 구분하기 쉽게 작명하면 좋음)
- Namespace (namespace에 담을 App의 범위)
- StatefulSet (instance 명)
- ConfigMap (사용 목적에 따라 네이밍을 추가해줌/ 예. prometheus-k8s-rule)
- selector (Object간 연결에 이용되며, selector의 모든 속성이 labels 속성에 포함되어 있어야 함)
- 쿠버네티스에서 Object간 연결
- labels <-> selector
- Object 내에서 대상을 연결하는 속성 (scaleTargetRef 등)


- Deployment (Pod를 생성하고 Update를 관리)
- K8s에서 ReplicaSet을 만들고 ReplicaSet은 replicas 속성을 복사하여, 그 수만큼 Pod를 만들고 유지
'Tech > Kubernetes(K8s)' 카테고리의 다른 글
@ONE_ :: 정호원
잘못된 정보가 있다면 말씀해주세요!