pod
๋ช
๋ น์ด
1. Create
# ํ์ผ์ด ์์ ๊ฒฝ์ฐ
kubectl create -f ./pod.yaml
# ๋ด์ฉ๊ณผ ํจ๊ป ๋ฐ๋ก ์์ฑ
kubectl create -f - <<END
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
containers:
- name: container
image: kubetm/init
END
๊ธฐ์กด์ ๊ฐ์ ์ด๋ฆ์ Pod๊ฐ ์กด์ฌํ๋ฉด ์์ฑ์ด ์๋๋ค.
2. Apply
kubectl apply -f ./pod.yaml
๊ธฐ์กด์ ๊ฐ์ ์ด๋ฆ์ Pod๊ฐ ์กด์ฌํ๋ฉด ๋ด์ฉ์ด override๋๋ค.
3. Get
# ๊ธฐ๋ณธ Pod ๋ฆฌ์คํธ ์กฐํ (Namepsace ํฌํจ)
kubectl get pods -n defalut
# ์ข๋ ๋ง์ ๋ด์ฉ ์ถ๋ ฅ
kubectl get pods -o wide
# Pod ์ด๋ฆ ์ง์
kubectl get pod pod1
# Json ํํ๋ก ์ถ๋ ฅ
kubectl get pod pod1 -o json
4. Describe
# ์์ธ ์ถ๋ ฅ
kubectl describe pod pod1
5. Delete
# ํ์ผ์ด ์์ ๊ฒฝ์ฐ ์์ฑํ ๋ฐฉ๋ฒ ๊ทธ๋๋ก ์ญ์
kubectl delete -f ./pod.yaml
# ๋ด์ฉ๊ณผ ํจ๊ป ๋ฐ๋ก ์์ฑํ ๊ฒฝ์ฐ ์์ฑํ ๋ฐฉ๋ฒ ๊ทธ๋๋ก ์ญ์
kubectl delete -f - <<END
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
containers:
- name: container
image: kubetm/init
END
# Pod ์ด๋ฆ ์ง์
kubectl delete pod pod1
6. Exec
# Pod์ด๋ฆ์ด pod1์ธ Container๋ก ๋ค์ด๊ฐ๊ธฐ (๋์ฌ๋ exit)
kubectl exec pod1 -it /bin/bash
# Container๊ฐ ๋๊ฐ ์ด์ ์์๋ Container์ด๋ฆ์ด con1์ธ Container๋ก ๋ค์ด๊ฐ๊ธฐ
kubectl exec pod1 -c con1 -it /bin/bash
๋ด๋ถ ์ค์
1. ์ปจํ
์ด๋
ํ๋ ๋ด์ ์ฌ๋ฌ๊ฐ์ ์ปจํ ์ด๋๊ฐ ์กด์ฌํ ์ ์์ผ๋ฉฐ ํ ํ๋๋ ๋ก์ปฌ๊ณผ ๊ฐ์ ๊ฐ๋ ์ผ๋ก ์๋ก๋ค๋ฅธ ์ปจํ ์ด๋๋ผ๋ฆฌ ํฌํธ๊ฐ ์ค๋ณต๋ ์ ์์ผ๋ฉฐ ํ๋๊ฐ ์์ฑ๋ ๋ ๊ณ ์ ์ ip์ฃผ์๊ฐ ํ ๋น๋๋ค. ํด๋น ip์ฃผ์๋ ํด๋ฌ์คํฐ๋ด์์๋ง ์ด์ฉํ์ฌ ํ๋์ ์ ๊ทผํ ์ ์์ผ๋ฉฐ ์ธ๋ถ์์๋ ์ ๊ทผ ํ ์ ์๋ค. ๊ทธ๋ฆฌ๊ณ ํ๋์ ๋ฌธ์ ๊ฐ ์๊ธด๋ค๋ฉด ์์คํ ์ด ํ๋๋ฅผ ์ญ์ ํ๊ณ ์ฌ์์ฑํ๊ฒ ๋๋๋ฐ ์ด ip๋ ์ฌํ ๋น๋๋ฏ๋ก ํ๋ฐ์ฑ์ ์ฃผ์์ด๋ค.
apiVersion: v1
kind: Pod
metadata:
name: pod-1
spec:
conatiners:
- name: container1
image: tmkube/p8000
ports:
- containerPort: 8000
-name: container2
image: tmkube/p8080
ports:
- cotainerPort: 8080
2. ๋ผ๋ฒจ
๊ฐ๊ฐ์ ํ๋๋ณ๋ก ๋ผ๋ฒจ์ ์ฌ๋ฌ๊ฐ ๋ฌ ์ ์์ด ์ฌ์ฉ๋ชฉ์ ์ ๋ฐ๋ผ ํ๋๋ฅผ ๋ถ๋ฅํ ์ ์์ด ์๋น์ค๋ฅผ ์ด์ฉํด์ ์ํ๋ ํ๋๋ฅผ ์ ํํด์ ์ฌ์ฉํ ์ ์๋ค.
apiVersion: v1
kind: Service
metadata:
name: svc-1
spec:
selector:
type: web
ports:
- port: 8080
apiVersion: v1
kind: Pod
metadata:
name: pod-2
lavels:
type: web
lo: dev
spec:
containers:
- name: container
image: tmkube/init
3. ๋
ธ๋ ์ค์ผ์ค
ํ๋๋ ์ฌ๋ฌ๋ ธ๋๋ค ์ค์ ํ ๋ ธ๋์ ์ฌ๋ผ๊ฐ์ผ๋๊ธฐ ๋๋ฌธ์ ์ค์ผ์คํ๋ ๋ฐฉ๋ฒ์ด ๋๊ฐ์ง ์กด์ฌํ๋ค.
์ง์ ์ ํ
ํ๋์ ๋ผ๋ฒจ์ ๋จ ๊ฒ์ฒ๋ผ ๋ ธ๋์ ๋ผ๋ฒจ์ ๋ง๋ค์ด ์ง์ ์ ํํ ์ ์๋ค.
apiVersion: v1
kind: Pod
metadata:
name: pod-3
spec:
nodeSelector:
hostname: node1
containers:
- name: container
image: tmkube/init
์ฟ ๋ฒ๋คํฐ์ค๊ฐ ํ๋จํ์ฌ ์ค์ผ์ค๋ฌ๊ฐ ์ ํ
ํ๋์ ์ฌ์ฉ๋ฉ๋ชจ๋ฆฌ๋์ ๋ช ์ํด์ฃผ๊ฒ ๋๋๋ฐ ์ค์ผ์ค๋ฌ๊ฐ ํ๋จํ์ฌ ์ ์ ํ ๋ ธ๋๋ฅผ ์ ํํ๋ค.
apiVersion: v1
kind: Pod
metadata:
name: pod-4
spec:
containers:
- name: container
image: tmkube/init
resources:
request:
memory: 2Gi
limits:
memory: 3Gi
request๋ ํด๋น ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์๊ตฌํ๋ค๋ ์๋ฏธ์ด๊ณ limits๋ ์ต๋ ์ฌ์ฉ๋์ด๋ฉฐ, ๋ฉ๋ชจ๋ฆฌ์ limit์ ์ด๊ณผ์์๋ ํ๋๋ฅผ ๋ฐ๋ก ์ข ๋ฃ์ํค๊ฒ ๋๊ณ cpu์ limit์ ์ด๊ณผํ๊ฒ ๋๋ฉด request๋ก ๋ฎ์ถ๊ณ ์ข ๋ฃ๋์ง ์๋๋ค.
๋ฉ๋ชจ๋ฆฌ๋ ์ ํ๋์ ์ด๊ณผํ๊ฒ ๋๋ฉด ๋ค๋ฅธ ํ๋ก์ธ์ค๋ค์ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์นจ๋ฒํ๊ฒ ๋์ด ๋ค๋ฅธ ํ๋ก๊ทธ๋จ์๋ ์
์ํฅ์ ๋ฏธ์น ์ ์๊ธฐ ๋๋ฌธ์ ์ข
๋ฃ์ํค๊ฒ ๋๋ค.
Node Schedule ๋ฐฉ๋ฒ

kubectl label nodes k8s-node1 kr=az-1 #๋
ธ๋ ๋ผ๋ฒจ ์ถ๊ฐ
kubectl label nodes k8s-node2 us=az-1 #๋
ธ๋ ๋ผ๋ฒจ ์ถ๊ฐ
# Node์ ๋ผ๋ฒจ ์ญ์
kubectl label nodes k8s-node1 kr- #๋
ธ๋์ ๋ผ๋ฒจ ์ญ์ (key๊ฐ๋ง ํ์)
1. ๋
ธ๋ ์ ํ
NodeName
๋ด๊ฐ ์ํ๋ ๋ ธ๋๋ฅผ ์ ํํ๊ณ ์ถ์๋ ์ค์ผ์ค๋ฌ์ ์๊ด์์ด ๋ช ์์ ์ผ๋ก ๋ ธ๋๋ฅผ ์ ํํ ์ ์๋ค๋ ํน์ง์ด ์์ง๋ง ์ค์ ์์ฉํ๊ฒฝ์์๋ ๋ ธ๋์ ์ถ๊ฐ/์ญ์ ๊ณผ์ ์ค์์ ๋ ธ๋์ ์ด๋ฆ์ด ๋ณ๊ฒฝ๋ ์ ์์ด ์ ์ฌ์ฉ๋์ง๋ ์๋๋ค.
apiVersion: v1
kind: Pod
metadata:
name: node-name
spec:
nodeName: k8s-node1
containers:
- name: container
image: kubetm/app
NodeSelector
ํ๋์ key/value๋ก ๋ผ๋ฒจ์ ๋ฌ๋ฉด ํด๋น ๋ผ๋ฒจ๊ณผ ๋งค์นญ๋๋ ๋ ธ๋์ค์์ ์ค์ผ์ค๋ฌ์ ์ํด ์์์ด ๋ง์ ๋ ธ๋๋ก ํ๋๊ฐ ํ ๋น๋๋ค. ๋ผ๋ฒจ์ด ๋ฑ ๋งค์นญ๋๋ ๋ ธ๋์๋ง ํ ๋น์ด ๋๊ธฐ ๋๋ฌธ์ ๋งค์นญ๋๋ ๊ฒฝ์ฐ๊ฐ ์๋ค๋ฉด ํ ๋น์ด ์ด๋ฃจ์ด์ง์ง ์๋๋ค.
apiVersion: v1
kind: Pod
metadata:
name: node-selector
spec:
nodeSelector: key1:value1
containers:
- name: container
image: kubetm/app
NodeAffinity

ํ๋์ key๋ง์ ๊ฐ์ง๊ณ ๋ ๋งค์นญ๋๋ ๋ ธ๋์ ์ฐ๊ฒฐ์ด ๋๋ฉฐ ๋งค์นญ๋๋ ๋ ธ๋๊ฐ ์กด์ฌํ์ง ์๋๋ผ๋ ์ค์ผ์ค๋ฌ๊ฐ ํ๋จํด์ ์์์ด ๋ง์ ๋ ธ๋์ ํ ๋น์ด๋๋๋ก ์ต์ ์ ์ค ์ ์๋ค.
matchExpressions๋ฅผ ์ด์ฉํ์ฌ ์ค์ผ์ค๋ฌ๊ฐ ๋
ธ๋์ ํ๋๋ฅผ ์ฐ๊ฒฐํด์ฃผ๊ฒ ๋๋ค. operator๋ก Gt์ Lt๊ฐ ์ถ๊ฐ๋๊ณ required/preferred
์ต์
์ ํตํด์ ๋
ธ๋์ ์๋ ํค๋ฅผ ๊ฐ์ง๊ณ ์์ด๋ ํ ๋น๋๋๋ก ํด์ค ์ ์๋ค.
required : key๊ฐ ๋งค์นญ๋์ด์ผ๋ง ํจ
apiVersion: v1 kind: Pod metadata: name: pod-required spec: affinity: nodeAffinity: requiredDuringSchedulingIgnoredDuringExecution: nodeSelectorTerms: - matchExpressions: - {key: ch, operator: Exists} containers: - name: container image: kubetm/app terminationGracePeriodSeconds: 0
preferred : key๊ฐ ๋งค์นญ๋์ง ์์๋ ์ค์ผ์ค๋ฌ์ ์ํด ํ ๋น์ด ๊ฐ๋ฅ
weight : ํน์ ๋ผ๋ฒจ์ ๋ํ ๊ฐ์ค์น๋ฅผ ์ค์ผ๋ก์จ ๋จ์ํ ์์์ ๋ณด๊ณ ๋ง ํ ๋น๋๋ ๊ฒ์ด ์๋ ๊ฐ์ค์น๋ฅผ ํฉ์ฐํด์ ํ ๋นํ๊ธฐ ์ํ ์์ฑ๊ฐ
apiVersion: v1 kind: Pod metadata: name: pod-preferred spec: affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - weight: 1 preference: matchExpressions: - {key: ch, operator: Exists} containers: - name: container image: kubetm/app terminationGracePeriodSeconds: 0
2. Pod๊ฐ ์ง์ค / ๋ถ์ฐ
Pod Affinity

์ฌ๋ฌ ํ๋๋ค์ ํ ๋ ธ๋์ ์ง์คํ์ฌ ํ ๋น
Webํ๋์ Serverํ๋๋ฅผ ๊ฐ์ PV(HostPath)๋ฅผ ์ฌ์ฉํด์ผ ํ๋ ๊ฒฝ์ฐ์ ๊ฐ์ ๋ ธ๋์ ํ ๋น๋๋๋ก ํ๋ ค๊ณ ํ ๋ ํ๋์ ํ์ ์ ๋์ผํ๊ฒ ํจ์ผ๋ก์จ ๊ฐ์ ๋ ธ๋์ ํ ๋นํด์ฃผ๋๋ก ํด์ฃผ๋ ๊ธฐ๋ฅ
pod Affinity๋ผ๋ ์ต์ ์ matchExpressions๋ก ๋ ธ๋๋ด์ ํ๋๋ผ๋ฒจ์ ํ์ธํ๊ณ topologyKey ์ต์ ์ ํตํด์ ๋ ธ๋์ ๋ผ๋ฒจ์ ์กฐ๊ฑด์ ์ค ์ ์๋ค. ๋ํ, Node Affinity์ ๋ง์ฐฌ๊ฐ์ง๋ก required/preferred์ต์ ์ ์ค ์๋ ์๋ค.
# master pod
apiVersion: v1
kind: Pod
metadata:
name: web1
labels:
type: web1
spec:
nodeSelector:
a-team: '1'
containers:
- name: container
image: kubetm/app
terminationGracePeriodSeconds: 0
# affinity pod
apiVersion: v1
kind: Pod
metadata:
name: server1
spec:
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: a-team
labelSelector:
matchExpressions:
- {key: type, operator: In, values: [web1]}
containers:
- name: container
image: kubetm/app
terminationGracePeriodSeconds: 0
Anti-Affinity

์ฌ๋ฌ ํ๋๋ค์ ์ง์ค๋๋ ์ผ ์์ด ๋ถ์ฐ๋์ด ํ ๋น
๋ง์คํฐํ๋์ ์ฌ๋ ์ด๋ธ ํ๋๋ฅผ ๋ง๋ค๋ ๋ถ์ฐ๋์ด์ผ ํ๋๋ฐ ํ๋์ Type์ ๊ฐ์ ํ๋๋ก ์ค์ ํด๋์ผ๋ฉด ์๋ก ๋ค๋ฅธ ๋ ธ๋์ ํ ๋นํด์ฃผ๋๋ก ํ๋ ๊ธฐ๋ฅ
podAntiAffinity๋ผ๋ ์ต์ ์ matchExpressions๋ก ๋ ธ๋๋ด์ ํ๋๋ผ๋ฒจ์ ํ์ธํ๊ณ topologyKey ์ต์ ์ ํตํด์ ๋ ธ๋์ ๋ผ๋ฒจ์ ์กฐ๊ฑด์ ์ค ์ ์๋ค. ๋ํ, Node Affinity์ ๋ง์ฐฌ๊ฐ์ง๋ก required/preferred์ต์ ์ ์ค ์๋ ์๋ค.
# master
apiVersion: v1
kind: Pod
metadata:
name: master
labels:
type: master
spec:
nodeSelector:
a-team: '1'
containers:
- name: container
image: kubetm/app
terminationGracePeriodSeconds: 0
# master-anti
apiVersion: v1
kind: Pod
metadata:
name: slave
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- topologyKey: a-team
labelSelector:
matchExpressions:
- {key: type, operator: In, values: [master]}
containers:
- name: container
image: kubetm/app
terminationGracePeriodSeconds: 0
3. Node์ ํ ๋น ์ ํ
Toleration / Taint

ํน์ ๋ ธ๋์ ์๋ฌด ํ๋๋ ํ ๋น๋์ง ์๋๋ก ์ ํ์ ํ๊ธฐ ์ํด ์ฌ์ฉ
๋ ธ๋์ Taint๋ฅผ ์ง์ ํด๋์ผ๋ฉด ์ค์ผ์ค๋ฌ์ ์ํด ํ ๋น๋์ง๋ ์์ผ๋ฉฐ ์๋์ผ๋ก ์ง์ ์ ํ๋ คํด๋ ํ ๋น๋์ง ์๋๋ค. ํ๋์ Toleration์ ์ค์ ํด์ฃผ์ด์ผ ํด๋น ๋ ธ๋์ ํ ๋น์ด ๊ฐ๋ฅํ๋ค.
Taint
๋ ธ๋์ Taint์์ labels์ effect์ต์ ์ ์ด์ฉํ์ฌ ์ค์ ํ ์ ์๋ค.
Taint์์ฑ์ ์๋ก์ด ํ๋๊ฐ ํ ๋น๋ ๋ ํ์ธํ๋ ์กฐ๊ฑด์ผ๋ก์จ ์ด๋ฏธ ๋ ธ๋์ ํ๋๊ฐ ๋์๊ฐ๊ณ ์๋ ์ํ๋ก ์ต์ ์ ์ถ๊ฐํด์ฃผ๊ฒ ๋๋ฉด ๊ธฐ์กด์ ๋ ธ๋๋ ๊ณ์ํด์ ์์ ์ ์ํํ ์ ์๋ค.
effect
NoSchedule : ํ ํ๋๋ค์ด ์ด ๋ ธ๋์ ํ ๋น ๋์ง ์๋๋ค.
PreferNoSchedule : ๊ฐ๊ธ์ ์ค์ผ์ค๋ง์ด ๋์ง ์๋๋ก ํ๋ ์ต์ ์ผ๋ก ํน์ ์ํฉ์๋ ํ ๋น์ด ๋ ์๋ ์๋ค.
NoExecute : ๊ธฐ์กด์ ์๋ํ๊ณ ์๋ ํ๋๋ ์ญ์ ๋๋ ์ต์
kubectl taint nodes k8s-node1 hw=gpu:NoSchedule #๋
ธ๋์ Taint ์ค์
kubectl taint nodes k8s-node1 hw=gpu:NoSchedule- #๋
ธ๋์ Taint ์ญ์
Toleration
ํ๋์ ํด๋น ๋ ธ๋๋ก ์ค์ผ์ค๋ง ๋๋๋ก Toleration์ ์ค์ ํด์ฃผ์ด์ผ ํ๋ฉฐ key/operator/value/effect ์์ฑ์ผ๋ก ์ค์ ํด์ค ์ ์๋ค.
operator
Euqal
Exists
์ด ์ต์
์ ํ๋์ ์ฃผ๋๋ผ๊ณ ํด๋น ํ๋๋ ๋ค๋ฅธ ๋งค์นญ๋๋ ๋
ธ๋์ ๋ํด ์ค์ผ์ค๋ง์ด ๋ ์ ์๊ธฐ ๋๋ฌธ์ nodeSelector
์ต์
์ ์ถ๊ฐ๋ก ์ฃผ์ด ํน์ ๋
ธ๋์ ํ ๋น๋ ์ ์๋๋ก ํด์ฃผ์ด์ผ ํ๋ค.
NoExcute๋
ธ๋์ NoExcute์ต์
์ ๋จ ํ๋๋ผ๋ฉด ์ญ์ ๊ฐ ๋์ง ์๊ฒ ์ง๋ง tolerationSeconds
์ต์
์ ์ด์ฉํด์ ์๊ฐ์ ์ ์ํด์ฃผ๋ฉด ํด๋น ์๊ฐ ํ์๋ ์ญ์ ํ๋๋ก ํ ์ ์๋ค.
# NoScheduled pod
apiVersion: v1
kind: Pod
metadata:
name: pod-with-toleration
spec:
nodeSelector:
gpu: no1
tolerations:
- effect: NoSchedule
key: hw
operator: Equal
value: gpu
containers:
- name: container
image: kubetm/app
terminationGracePeriodSeconds: 0
# NoExcute pod
apiVersion: v1
kind: Pod
metadata:
name: pod1-with-no-execute
spec:
tolerations:
- effect: NoExecute
key: out-of-disk
operator: Exists
tolerationSeconds: 30
containers:
- name: container
image: kubetm/app
terminationGracePeriodSeconds: 0
+) ์ถ๊ฐ
terminationGracePeriodSeconds: 0
: ๊ธฐ๋ณธ pod์ ์ญ์ ์์ฒญํ ์ญ์ ๋๋ ์๊ฐ์ 30s์ธ๋ฐ 0s๋ก ์
ํ
ํ๋ ๊ตฌ์กฐ
Status:
phase: Pending
conditions:
- type: Initialized
status: 'True'
lastProbeTme: null
lastTransitonTime: '2019-09-26T22:07:56Z'
- type: PodScheduled
status: 'True'
lastProbTime: null
lastTransitonTime: '2019-09-26T22:07:56Z'
containerStatuses:
- name: container
state:
waiting:
reason: ContainerCreating
lastState: {}
ready: false
restartCount: 0
image: tmkube/init
imageID: ''
started: false
- type: ContainersReady
status: 'False'
lastProbTime: null
lastTransitonTime: '2019-09-26T22:07:56Z'
reason: ContainersNotReady
- type: Ready
status: 'False'
lastProbTime: null
lastTransitonTime: '2019-09-26T22:07:56Z'
reason: ContainersNotReady
Phase : Pod์ ์ ์ฒด ์ํ
Pending
Running
Succeeded
Failed
Unknown
Conditions : Pod๊ฐ ์คํํ๋ ๋จ๊ณ์ ์ํ
Initialized
ContainerReady
PodScheduled
Ready
Reason : ์ปจ๋์ ์ ์ํ๊ฐ False์ธ๊ฒฝ์ฐ ์ด์ ๋ฅผ ์๋ ค์ฃผ๊ธฐ ์ํ ์์ฑ
ContainersNotReady
PodCompleted
State : ๊ฐ๊ฐ์ ์ปจํ ์ด๋๋ค์ ๋ํํ๋ ์ํ
Wating
Running
Terminated
Reason : ํ์ฌ ์ํ์ ์ด์
ConainerCreating
CrashLoopBackOff
Error
Completed
์ปจํ ์ด๋์ ์ํ์ค imageID๊ฐ ์๋ ๊ฒฝ์ฐ ์์ง image๊ฐ ๋ค์ด์ด ๋์ง ์์ ์ํ์ด๋ค.
LifeCycle
1. Pending
Pod์ ์ต์ด์ํ๋ก ์ปจํ ์ด๋๋ค์ด ์์ฑ๋๊ธฐ ์ ์ ์ด๊ธฐํ์์ผ์ค ๋ด์ฉ์ด ์์ ๊ฒฝ์ฐ
initContainer
๋ฅผ ํตํด์ ๋ณธ ์ปจํ ์ด๋๋ณด๋ค ๋จผ์ ์์ฑ์ด ๋์ด ๋ณผ๋ฅจ/๋ณด์๊ณผ ๊ฐ์ ์ ํ ์ ์ํํ ์ ์๊ณ ์ฑ๊ณต์ ์ผ๋ก ์ํํ๊ฑฐ๋ ํ์ง ์์๋ค๋ฉดInitialized
์์ฑ์ด true, ์คํจํ๋ค๋ฉด false๊ฐ ๋๋ค.Pod๊ฐ ์ฌ๋ผ๊ฐ๊ฒ ๋ ๋ ธ๋๋ฅผ ์ค์ ํ๋๋ฐ ์ง์ ์ค์ ํ๊ฑฐ๋ k8s๊ฐ ์๋์ผ๋ก ์ก์์ฃผ๊ฒ ๋๋๋ฐ ์๋ฃ๊ฐ ๋๋ค๋ฉด
PodScheduled
์์ฑ์ด True๊ฐ ๋๋ค.Container์ image๋ฅผ ๋ค์ด๋ก๋๊ฐ ์งํ๋๊ณ ์ปจํ ์ด๋์ ์ํ๋ waiting(reason : ContainerCreating)์ด ๋๋ค.
+) Pending ๋์ค์ Failed๋ก ๋น ์ง๋ ๊ฒฝ์ฐ๋ ์กด์ฌํ๊ณ ํต์ ์ฅ์ ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ Unknown์ํ๋ก ๋ฐ๋๊ณ Unknown์ํ๊ฐ ์ง์๋๋ฉด Failed๋ก ๋ณ๊ฒฝ๋๋ค.
2. running
์ปจํ ์ด๋๊ฐ ๊ธฐ๋์ด๋๋ฉด์ Pod์ ์ํ๊ฐ
Running
์ด ๋๋ค.๋ง์ผ ์ปจํ ์ด๋๊ฐ ๊ธฐ๋์ด ๋๋ ์ค ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ค๋ฉด ์ปจํ ์ด๋์ ์ํ๋ waiting(reason : CrashLoopBackOff)์ด ๋์ด ์ปจํ ์ด๋๋ฅผ ์ฌ๊ธฐ๋ํ๋ค. ์ด์ํฉ์๋ Pod์ ์ํ๋ Running์ํ์ด๋ฉฐ ๋ด๋ถ
ContainerReady
/Ready
์์ฑ์ด false๋ก ๋ฐ๋๊ฒ ๋๋ค.๋ชจ๋ ์ปจํ ์ด๋๊ฐ ์ ์์ ์ผ๋ก running์ด ๋์๋ค๋ฉด
ContainerReady
/Ready
์ด true๊ฐ ๋๋ค. ์ด๋ ๊ฒ ์ปจํ ์ด๋์ ๋ฌธ์ ๊ฐ๋ฐ์ํด๋Running
์ํ์ด๊ธฐ ๋๋ฌธ์ Pod์ ์ํ๋ฟ๋ง์ด ์๋๋ผ ์ปจํ ์ด๋์ ์ํ๋ ๋ชจ๋ํฐ๋ง์ ์ํํด์ผ ํ๋ค.
+) ํต์ ์ฅ์ ๊ฐ ๋ฐ์ํ๋ ๊ฒฝ์ฐ Unknown์ํ๋ก ๋ฐ๋๊ณ Unknown์ํ๊ฐ ์ง์๋๋ฉด Failed๋ก ๋ณ๊ฒฝ๋๋ค.
3. Failed / Succeeded
Job / CronJob์ผ๋ก ์์ฑ๋ Pod์ ๊ฒฝ์ฐ ์์
์ด ๋๋ฌ์๋ ์ ์ํ์ค ํ๊ฐ๋ก ๋ณ๊ฒฝ๋๊ฒ ๋๋๋ฐ ๋ง์ฝ ์์
์ ํ๊ณ ์๋ ์ปจํ
์ด๋์ค ํ๊ฐ๋ผ๋ ๋ฌธ์ ๊ฐ ๋ฐ์ํด์ Error
๊ฐ ๋ฐ์ํ๋ค๋ฉด Failed, ๋ชจ๋ Completed๊ฐ ๋์๋ค๋ฉด Succeeded์ํ๊ฐ ๋๋ค.
์ด ๋ ์ํ ๋ชจ๋ ์ปจํ
์ด๋๋ค์ ์ข
๋ฃ๋ ์ํ์ด๊ธฐ ๋๋ฌธ์ ContainerReady
/ Ready
๋ ๋ชจ๋ False๊ฐ ๋๋ค.
ReadinessProbe / LivenessProbe
์ปจํ ์ด๋์์ ์ฌ๋ผ๊ฐ๋ App์ ์ํ๋ฅผ ๊ฐ์งํ๊ณ ๋์ํ๊ธฐ ์ํ ์ค์ ์ผ๋ก ์๋ก ๊ธฐ๋ฅ์ ๋ชฉ์ ๋ง ๋ค๋ฅผ๋ฟ ์ค์ ๋ฐฉ๋ฒ์ ๋์ผํ๋ค.
์์ฑ
httpGet
: Port, Host, Path, HttpHeader, Scheme๋ฑ์ ์ค์ ์ผ๋ก ์ฒดํฌExec
: Command๋ฅผ ํตํด ๊ฒฐ๊ณผ๋ฅผ ์ฒดํฌํ ์ ์๋ค.tcpSocket
: port, host๋ฅผ ์ด์ฉํด์ ์ฑ๊ณต ์ฌ๋ถ๋ฅผ ํ์ธํ ์ ์๋ค.
๋ฐ๋์ ์ 3๊ฐ์ ์ต์ ์ค 1๊ฐ๋ ๊ผญ ์ ์ํด์ผํ๋ ์์ฑ์ด๋ค.
์ต์
initialDelaySeconds : ์ต์ด Probe๋ฅผ ํ๊ธฐ์ ์ ๋๋ ์ด ์๊ฐ
periodSeconds : Probe๋ฅผ ์ฒดํฌํ๋ ๊ฐ๊ฒฉ
timeoutSeconds : timeout ์๊ฐ
successThreshold : ๋ช๋ฒ ์ฑ๊ณตํด์ผ ์ฑ๊ณต์ผ๋ก ์ธ์ ํ ๊ฒ์ธ์ง์ ๋ํ ๊ฐ
failureThreshold : ๋ช๋ฒ ์คํจํด์ผ ์คํจ๋ก ์ธ์ ํ ๊ฒ์ธ์ง์ ๋ํ ๊ฐ
์ ์ค์ ์ ํตํด App์ ์ฑ๊ณต์ฌ๋ถ๋ฅผ ํ์ ํ๊ณ ์ฑ๊ณต์ด ๋๊ธฐ ์ ๊ฐ์ง๋ Pod์ ์ํ๊ฐ Running์ด ๋์ด๋ ์ปจํ ์ด๋์ ์ํ๋ false๋ก Service๋ NotReadyAddr ์ํ๋ก Pod์ ์ฐ๊ฒฐ์ด ๋์ง ์๋๋ค.
kubectl get events -w | grep pod-readiness-exec1 #pod-readiness-exec1์ด๋ผ๋ ์ด๋ฆ์ event๋ค ์กฐํ
watch "kubectl describe pod pod-readiness-exec1 | grep -A5 Conditions" #pod-readiness-exec1๋ผ๋ pod์ Conditions์ ๋งค์นญ๋๋ ๋จ์ด์์ 5๋ฒ์งธ ์ค๊น์ง ์ง์์ ์ผ๋ก ์ถ๋ ฅ
kubectl describe endpoints svc-readiness #Service์ endpoint์ํ ํ์ธ(pod์ ์ฐ๊ฒฐ์ํ ํ์ธ)
1. ReadinessProbe
ํ ์๋น์ค๊ฐ 2๊ฐ์ Pod๊ฐ ์๋ก ๋ค๋ฅธ ๋ ธ๋์์์ ์คํ๋๊ณ ์์๋ ํ๊ฐ์ ๋ ธ๋๊ฐ ๋ฌธ์ ๊ฐ๋ฐ์ํด์ ํ ํ๋๊ฐ ์ฃฝ์๋ค๋ฉด auto healing ๊ธฐ๋ฅ์ ์ํด ์๋ก์ด ํ๋๊ฐ ์์ฑ์ด ๋๊ฒ ๋๋๋ฐ ์ด๋ ํ๋์ ์ปจํ ์ด๋์ ์ํ๊ฐ running์ด ๋๋ฉด ํธ๋ํฝ์ ๋๋์ด ์์ฒญ์ ์ฒ๋ฆฌํ๊ฒ ๋๋ค. ๊ทธ๋ฐ๋ฐ ์ปจํ ์ด๋๋ Running์ด์ง๋ง App์ด ์์ง ๋ถํ ์ค์ด๋ผ๋ฉด 50%์ ์ฌ์ฉ์๋ ์๋ฌ๋ฅผ ์๋ต๋ฐ๊ฒ ๋ ๊ฒ์ด๋ค.
์ด๋ฐ๊ฒฝ์ฐ์ ๊ฐ์ด App ๊ตฌ๋๊น์ง ํธ๋ํฝ์ ๋๋์ง ์์ ํธ๋ํฝ ์คํจ๋ฅผ ์์ ๋ ๊ธฐ๋ฅ
์๋ฅผ๋ค์ด ํฐ์บฃ๊ณผ ๊ฐ์ด ์น์๋ฒ๋ ๊ตฌ๋์ด ๋์ด Running์ํ๊ฐ ๋์๋๋ฐ ๊ทธ ์์ ์ฌ๋ผ๊ฐ๋ App์ด ๊ตฌ๋์ด ์์ง ๋์ง ์์ ๊ฒฝ์ฐ
apiVersion: v1
kind: Pod
metadata:
name: pod-readiness-exec1
labels:
app: readiness
spec:
containers:
- name: readiness
image: kubetm/app
ports:
- containerPort: 8080
readinessProbe:
exec:
command: ['cat', '/readiness/ready.txt']
initialDelaySeconds: 5
periodSeconds: 10
successThreshold: 3
volumeMounts:
- name: host-path
mountPath: /readiness
volumes:
- name: host-path
hostPath:
path: /tmp/readiness
type: DirectoryOrCreate
terminationGracePeriodSeconds: 0
2. LivenessProbe
Pod์ Container๋ Running์ํ์ธ๋ฐ Memory Overflow์ ๊ฐ์ ๋ฌธ์ ๋ก App๋ง ์ฃฝ์ ๊ฒฝ์ฐ์๋ Auto Healing๊ธฐ๋ฅ์ด ์ํ๋์ง ์์ ์ง์์ ์ธ ์คํจ๋ฅผ ๋ฐ์์ํค๊ฒ ๋๋๋ฐ App์ฅ์ ๋ฅผ ๊ฐ์งํ๊ณ Pod๋ฅผ ์ฌ์คํ์์ผ ํธ๋ํฝ์ ์ง์์ ์ธ ์คํจ๋ฅผ ์์ ๋ ๊ธฐ๋ฅ
apiVersion: v1
kind: Pod
metadata:
name: pod-liveness-httpget1
labels:
app: liveness
spec:
containers:
- name: liveness
image: kubetm/app
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
failureThreshold: 3
terminationGracePeriodSeconds: 0
QoS classes
Quality of Service์ ์ฝ์๋ก k8s์์๋ ์ฑ์ ์ค์๋์ ๋ฐ๋ผ์ ์์์ ๊ด๋ฆฌํ ์ ์๋๋ก ์ง์ํด์ฃผ๋ ๊ธฐ๋ฅ์ผ๋ก ํ ํ๋์์ ์ถ๊ฐ ์์์ด ํ์ํ ๊ฒฝ์ฐ ํด๋น ํ๋๊ฐ ์๋ฌ๋ฅผ ๋ฐ์ํ๋ ๊ฒ์ด ์๋ ๋ค๋ฅธ ํ๋์ ์์์ ๋ค์ด์ํค๊ณ ํ์ํ ํ๋์๊ฒ ์์์ ํ ๋นํด์ค์ผ๋ก์จ ๊ด๋ฆฌ๋ฅผ ํด์ฃผ๋ ๊ธฐ๋ฅ์ด๋ค.
QoS classes๋ ๋ณ๋์ ์ค์ ์ผ๋ก ํ ๋น์ ํ๋ ๊ฒ์ด ์๋๋ผ spec์ resources๋ฅผ ์ ์ํด ์ค๋ requests
, limits
์ ์ค์ ๊ฐ์ผ๋ก ๋จ๊ณ๊ฐ ์ค์ ์ด ๋๋ค.
1. Guaranteed
๊ฐ์ฅ ๋์ ๋ฑ๊ธ์ ๋จ๊ณ๋ก ํ ํ๋๋ด ๋ชจ๋ request์ limit๊ฐ ์ค์ ๋์ด ์๊ณ reqeust์ limit์ memory์ cpu๊ฐ ๋ชจ๋ ์ค์ ๋์ด memory์ cpu์ request์ limit์ ๊ฐ์ด ๋ชจ๋ ๊ฐ์ ๊ฒฝ์ฐ ํด๋น ๋ฑ๊ธ์ด ์ค์ ๋๋ค.
2. Bustable
request๋ด์ mem/cpu ๊ฐ์ด limit์ mem/cpu๊ฐ๋ณด๋ค ๋ฎ์ ๊ฒฝ์ฐ๋, request๋ง ์ค์ ๋ ๊ฒฝ์ฐ, ํ๋๋ด ํ ์ปจํ ์ด๋๋ ์ค์ ์ด ๋์์ด๋ ๋ค๋ฅธ ์ปจํ ์ด๋๊ฐ ์ค์ ์ด ์๋ ๊ฒฝ์ฐ๊ฐ ํด๋น๋๋ค.
๋ฑ๊ธ์ด ๊ฐ์๊ฒฝ์ฐ OOM Score
์ ๋ฐ๋ผ์ ํด๋น ์ ์๊ฐ ๋์ ํ๋๊ฐ ๋จผ์ ๋ค์ด๋๋ค.
OOM Score
Out Of Memory์ ์ฝ์๋ก ํ๋ง๋๋ก ์ฌ์ฉ๋์ ์๋ฏธํ๋ค. Request์ ํ ๋น๋์ ๋น๋กํด์ App์ด ์ฌ์ฉํ๊ณ ์๋ ๋.
3. BestEffort
๊ฐ์ฅ ๋จผ์ ๋ค์ด๋๋ ๋จ๊ณ๋ก ์ด๋ค container์๋ request์ limt๊ฐ ๋ฏธ์ค์ ๋ ํ๋๊ฐ ํด๋น๋๋ค.
Reference
Last updated