โ ์ฟ ๋ฒ๋คํฐ์ค ์ด๋๋ ํด๋์ค (์ง์ํธ) - Spring 1, 2 ์ ๋ฃ๊ณ ์์ฑํ๋ ๋ณต์ต ๋ธ๋ก๊ทธ ์ ๋๋ค.
1. Object ๊ทธ๋ ค๋ณด๋ฉฐ ์ดํดํ๊ธฐ
๊ฐ Object ๋ณ ๊ธฐ๋ฅ ๊ฐ๋จ ์ ๋ฆฌ โฌ๏ธ
Object ๋ช | ๊ธฐ๋ฅ |
Deployment | Pod ๋ฅผ ๋ง๋ค๊ณ ์ ๊ทธ๋ ์ด๋ ํด์ฃผ๋ ์ญํ |
Service | Pod ํํ ํธ๋ํฝ์ ์ฐ๊ฒฐ์์ผ์ฃผ๋ ์ญํ |
ConfirMap | pod ์ ํ๊ฒฝ๋ณ์ ๊ฐ์ ์ ๊ณตํ๋ ์ญํ |
Secret | pod ์ ์ข ๋ ์ค์ํ ํ๊ฒฝ๋ณ์ ๊ฐ์ ์ ๊ณตํ๋ ์ญํ |
PVC (PersistentVolumeClaim) | pod ์์ pv ๋ฅผ ์ง์ ํ ๋ ์ฌ์ฉ |
PV (PersistentVolume) | ์ค์ Volume ์ ์ง์ ํ๋ ์ญํ |
HPA | ๋ถํ์ ๋ฐ๋ผ pod ๋ฅผ ๋๋ ค์ฃผ๊ณ , ์ค์ฌ์ฃผ๋ ์ค์ผ์ผ๋ง ์ญํ |
1. master node ์ ์ ์ํด์ ๋๋ ํ ๋ฆฌ ์์ฑ
mkdir -p /root/k8s-local-volume/1231
2. Namespace : Object๋ค์ ๊ทธ๋ฃนํํด์ฃผ๋ ์ญํ
apiVersion: v1
kind: Namespace
metadata:
name: anotherclass-123
labels:
part-of: k8s-anotherclass
managed-by: dashboard
3. Deployment : Pod ๋ฅผ ๋ง๋ค๊ณ ์ ๊ทธ๋ ์ด๋ ํด์ฃผ๋ ์ญํ
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
- namespace: anotherclass-123 : ์์ ๋ง๋ Namespace ์์์ด ๋๋ค.
- name: api-tester-1231 : ํ Namespace ์์์ ์ค๋ณต๋๋ฉด ์๋จ
- replicas: 2 : pod ๋ฅผ 2๊ฐ๋ก ๋ง๋ ๋ค
- type: RollingUpdate : deployment ๊ธฐ๋ฅ์ ํต์ฌ (→ ๋ค์ ๊ฐ์์์ ์ค๋ช ์์ )
- template: : ์ฌ๊ธฐ ๋ด์ฉ๋๋ก pod ๊ฐ ๋ง๋ค์ด์ง๋ค.
- nodeSelector: : pod๋ฅผ ๋์ธ ๋ ธ๋๋ฅผ ์ ํ
- container: image : DockerHub ์์ ์ด๋ฏธ์ง ๋ค์ด
- envFrom: configMapRef: : Application ์ ํ๊ฒฝ๋ณ์์ ๊ด๋ จ๋ ๋ถ๋ถ
- startupProbe: : App ์ด ์ ๊ธฐ๋๋๋์ง ์ฒดํฌ, ๊ธฐ๋์ด ์๋๋ฉด App ์ ์ฌ๊ธฐ๋
- readinessProbe: : App ์ ํธ๋ํฝ์ ์ฐ๊ฒฐํ ๊ฑด์ง๋ฅผ ๊ฒฐ์ ํ๋ ์์ฑ
- livenessProbe: : App ์ด ์ ์์ด ์๋๋ฉด ์ฌ์์์ ์ํฌ๊ฑด์ง ํ๋จํ๋ ์์ฑ (์ค์)
- resources: : pod ํ๋์ CPU๋ memory ๋ฅผ ์ผ๋ง๋ ํ ๋นํ ์ง
- volumeMounts: mountPath: : pod ๋ด๋ถ์ ๋ง๋ค์ด์ง๋ ๋๋ ํ ๋ฆฌ
- volumeMounts ์ name ๊ณผ volumes ์ name์ด ๋งคํ๋๋ค.
4. 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
๊ฐ์ ์ข ๋ฅ์ object ๋ผ๋ฆฌ ์ด๋ฆ์ด ์ค๋ณต๋๋ฉด ์๋๋ค
Service ์ Deployment ๋ ์๋ก ๋ค๋ฅธ object ๋ผ ์ด๋ฆ์ด ๊ฐ์๋ ๋๋ค
5. ConfirMap : pod ์ ํ๊ฒฝ๋ณ์ ๊ฐ์ ์ ๊ณตํ๋ ์ญํ
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"
6. Secret : pod ์ ์ข ๋ ์ค์ํ ํ๊ฒฝ๋ณ์ ๊ฐ์ ์ ๊ณตํ๋ ์ญํ
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"
- stringData : stringData ์์ ์๋ ํ์ผ์ด pod ์์ ๋ง๋ค์ด์ง๋ค.
7. PVC (PersistentVolumeClaim) : pod ์์ 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
8. PV (PersistentVolume) : ์ค์ 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]}
Cluster Level ์ Obejct
- local : ์์ ์๋ path ๋ฅผ volume ์ผ๋ก ์ฌ์ฉ
- nodeAffinity : nodeSelector ์ ๊ฐ์ด Master Node ๋ฅผ ์ง์ ํ๋ค.
9. HPA : ๋ถํ์ ๋ฐ๋ผ pod ๋ฅผ ๋๋ ค์ฃผ๊ณ , ์ค์ฌ์ฃผ๋ ์ค์ผ์ผ๋ง ์ญํ
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
- kind: Deployment : ์ค์ผ๋ง ๋์์ผ๋ก Deployment ๋ฅผ ์ง์
- minReplicas: 2 : ์ต์ ๋ ๊ฐ์ pod ๋ฅผ ์ ์งํ๊ณ ์๋ค๊ฐ
- maxReplicas: 4 : ๋ถํ๊ฐ ์๊ธฐ๋ฉด ์ต๋ 4๊ฐ๊น์ง ๋์ด๋๋๋ก ์ค์
- metrics: : resource ์ ๋ฐ๋ผ ๊ทธ ๊ธฐ์ค์ ๋์ผ๋ฉด ์ค์ผ์ผ ์์์ ํ๋ผ๊ณ ์ค์
- behavior: pod ๊ฐ ํ ๋ฒ ์ฆ๊ฐ๋ฅผ ํ ํ pod ๊ฐ ์ถ๊ฐ์ ์ผ๋ก ๋์ด๋์ง ์๊ฒ ํ๋ ์ค์
- namespace ๋ฅผ ์ญ์ ํ๋ฉด ์ด ์์ ์๋ ๋ชจ๋ Object ๊ฐ ๊ฐ์ด ์ญ์ ๊ฐ ๋๋ค
kubectl delete ns anotherclass-123
kubectl delete pv api-tester-1231-files
- ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ์ด ๋ช ๋ น์ด๋ง ์คํํด์ฃผ๋ฉด ๋๋ค
- pv ๋ namespace ์ ์ํ์ง ์๊ธฐ ๋๋ฌธ์ ๋ณ๋๋ก ํ ๋ฒ ๋ ์ญ์
2. Labels, Selector, Naming
- ์ ๊ฐ์์์ ์ค์นํ๋ Promethueus ๋ฅผ ์๋ก ์ค๋ช
prometheus ๋ฅผ ์ค์นํ๊ณ ์์ฑ๋ pod์ labels
- ๋ผ๋ฒจ๋ง : ๋์์ ๊ฐ๋จํ ์ ๋ณด๋ฅผ ๋ถ์ฌ๋์ ๋
- object ๊ฐ ๋ง์์ง๋ฉด์ ์ ๋ณด๋ฅผ ์๊ธฐ๊ฐ ์ด๋ ค์์ง๋ค.
- ์ค๋ธ์ ํธ์ ๋ผ๋ฒจ๋ง์ด ์ ๋์ด ์์ผ๋ฉด → object ์ ๊ฑธ๋ ค ์๋ App ์ ์ ๋ณด๋ฅผ ๋ฐ๋ก ํ์ ํ ์ ์๋ค.
- part-of : ์ดํ๋ฆฌ์ผ์ด์ ์ ์ฒด ์ด๋ฆ
- component (๊ตฌ์ฑ์์) : ์๋น์ค๋ฅผ ๊ตฌ์ฑํ๊ณ ์๋ ๊ฐ๊ฐ์ ๋ถ๋ฆฌ๋ ๊ธฐ๋ฅ๋ค
- name : ์ดํ๋ฆฌ์ผ์ด์
์ ์ค์ ์ด๋ฆ
๊ตฌ์ฑ ์์ ๋ฐ์ ์ฌ๋ฌ ์ข ๋ฅ์ name๋ค์ด ์์ ์ ์๋ค. - instance : ๋ชฉ์ ์ ๋ฐ๋ผ ์ฌ๋ฌ๊ฐ์ ์ดํ๋ฆฌ์ผ์ด์ ์ ์ค์นํ ๋ ๊ฐ์ ๋ค๋ฅด๊ฒ ์ค์ ์ฌ์ฉ
- version : App ๋ฒ์ ์ด ๋ณ๊ฒฝ๋๋ฉด ์์ ํ์
- name : ์ดํ๋ฆฌ์ผ์ด์
์ ์ค์ ์ด๋ฆ
- ์ฟ ๋ฒ๋คํฐ์ค์ object ์ ๋ํ Naming
- ์ด๋ฆ์ด ์ค๋ณต๋๋ฉด ์๋๋ค
- ์ผํ๋ก๋์ด ๊ถ๊ณ ์ฃผ์๋ Naming !!
- Namespace : ์ฌ๊ธฐ์ ๋ค์ด๊ฐ๋ App ๋ค์ ๋ฒ์๋ฅผ ๋ํ๋ด๋ ์ด๋ฆ์ด ์ข๋ค
- Object : ์ดํ๋ฆฌ์ผ์ด์
name + instance
k8s ๊ณต์ ๋ฌธ์์ ๋ฐ๋ฅด๋ฉด instance ์ด๋ฆ์ ์ดํ๋ฆฌ์ผ์ด์ ์ด๋ฆ์ ์๋ณ์๋ฅผ ์ถ๊ฐํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์์ Object์ ์ด๋ฆ์ label ์ instance ์ด๋ฆ
๊ฐ์์์ ๊ตฌ์ฑ๋ ์ค๋ธ์ ํธ Labels
Deployment ๋์
Object | ๋์ |
์ฟ ๋ฒ๋คํฐ์ค |
|
ReplicaSet : Pod ๋ณต์ ๋ณธ ๊ด๋ฆฌ |
|
Pod |
|
label ์ ๊ธฐ๋ฅ
- App ์ ๋ณด๋ฅผ ํ์ ํ๊ธฐ ์ํ ์ฉ๋
- selector ์ ๋งค์นญ์ด ๋ผ์ ๋ Object ๋ฅผ ์ฐ๊ฒฐ
- select ์ ๋ด์ฉ์ด ๋ชจ๋ label ์ ํฌํจ
- instance ์ด๋ฆ์ด ๊ณ ์ ํ๊ธฐ ๋๋ฌธ์ selector ์ instance ๋ง ๋ฃ์ด๋ ๋งค์นญ์ด ๋๋ค
⇒ selector & label : object ๋ค์ ๋งค์นญํด ์ฃผ๋ ์ญํ
์ฟ ๋ฒ๋คํฐ์ค ๊ฐ object ์ฐ๊ฒฐ
- label ↔ selector
- object ๋ด์์ ๋์์ ์ฐ๊ฒฐํ๋ ์์ฑ
labels ์ ์ญํ
- ์ ๋ณด์ฑ ๋ผ๋ฒจ๋ง
- ์ ๋ณด์ฑ ๋ผ๋ฒจ๋ง + ๊ธฐ๋ฅ์ฑ ๋ผ๋ฒจ๋ง
- labels ์์ prefix ๋ฅผ ๋ถ์ผ ์๋ ์๋๋ฐ ์ด๋ ๋๋ฉ์ธ์ ๊ฐ๋ฆฌํจ๋ค. (์ต์ ์ฌํญ)
selector
- ์ฌ๋ฌ ์ข ๋ฅ์ selector ๋ค์ด ์๊ณ , ๊ฐ๊ฐ์ ์ฌ์ฉ ๋ฐฉ๋ฒ์ด ์กฐ๊ธ์ฉ ๋ค๋ฅด๋ค
Service
selector:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
PVC
selector:
matchLabels:
instance: api-tester-1231-files
→ ์ ๋์ด ์๋ ํ ํ๋ฆฟ ํ๋๋ง ๋๊ณ , ๋ณต์ฌํด์ ๋ณ๊ฒฝํด์ผ ํ๋ ์ฃผ์ ๊ฐ๋ค๋ง ๋ณ๊ฒฝํด์ ์จ๋ ๋๋ค
'๐ฑ ์ธํ๋ฐ > โ ์ฟ ๋ฒ๋คํฐ์ค ์ด๋๋ ํด๋์ค (์ง์ํธ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
(6) Configmap, Secret ์ดํดํ๊ธฐ (2) | 2025.06.08 |
---|---|
(5) Probe ์ดํดํ๊ธฐ (1) | 2025.06.02 |
(3) ์ค๋ฌด์์ ๋๊ปด ๋ณธ ์ฟ ๋ฒ๋คํฐ์ค๊ฐ ์ ๋ง ํธํ ์ด์ (0) | 2025.05.29 |
(2) ์ฟ ๋ฒ๋คํฐ์ค ๋ฌด๊ฒ๊ฐ ์๊ฒ ์ค์นํ๊ธฐ (0) | 2025.05.28 |
[๋ฏธ์ 1] ์ฟ ๋ฒ๋คํฐ์ค ์ค์น ๊ตฌ๊ฐ๋ณ ์ํ ํ์ธ (1) | 2025.05.28 |