Skip to main content

Deployment


Deploymentโ€‹

Deployment and RollingUpdate

ReplicaSet์€ Pod ์ง‘ํ•ฉ์„ ์‹๋ณ„ํ•˜๊ธฐ ์œ„ํ•œ .spec.selector, ์œ ์ง€ํ•˜๊ณ  ์‹ถ์€ Pod ์ˆ˜๋ฅผ ์ง€์ •ํ•˜๋Š” .spec.replicas, ์ƒˆ๋กœ ์ƒ์„ฑ๋  Pod ์ •๋ณด์ธ .spec.template์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

Deployment๋Š” ReplicaSet์„ ์ƒ์„ฑํ•˜๊ณ  ์ปจํŠธ๋กคํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๋ฆฌ์†Œ์Šค์ž…๋‹ˆ๋‹ค. Deployment์— ์˜ํ•ด ์ƒ์„ฑ๋œ ReplicaSet์€ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ๊ด€๋ฆฌํ•˜๋ฉด ์•ˆ๋ฉ๋‹ˆ๋‹ค.

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3 # ์œ ์ง€ํ•˜๊ณ  ์‹ถ์€ Pod ์ˆ˜
minReadySeconds: 10 # readinessProbe ์„ฑ๊ณต ํ›„ ์ตœ์†Œ ์ค€๋น„ ์‹œ๊ฐ„, ์˜๋„์ ์œผ๋กœ ์—…๋ฐ์ดํŠธ ์†๋„๋ฅผ ๋Šฆ์ถœ ์ˆ˜ ์žˆ์Œ
strategy:
type: RollingUpdate # RollingUpdate(default)|Recreate
rollingUpdate:
# replicas - maxUnavailable <= ์‚ฌ์šฉ ๊ฐ€๋Šฅ Pod <= replicas + maxSurge
maxSurge: 25% # ์ •์ˆ˜ ๋˜๋Š” ๋น„์œจ(%, ceil(replicas * maxSurge))
maxUnavailable: 25% # ์ •์ˆ˜ ๋˜๋Š” ๋น„์œจ(%, floor(replicas * maxUnavailable))
selector: # ๊ด€๋ฆฌํ•˜๊ณ  ์‹ถ์€ Pod์˜ ์ •๋ณด
matchLabels:
app: my-app
template: # ์ƒˆ๋กœ ์ƒ์„ฑ๋  Pod
metadata:
labels: # .spec.selector์— ์˜ํ•ด ์„ ํƒ ๋  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •
app: my-app
spec:
containers:
- image: [<url>/]<image>[:tag]
name: my-app
ports:
- name: http # Pod ๋‚ด์—์„œ ํŠน๋ณ„ํ•ด์•ผํ•˜๋ฉฐ, service์— ์˜ํ•ด ์ฐธ์กฐ๋  ์ˆ˜ ์žˆ์Œ
containerPort: 8080
protocol: TCP # TCP(default)|UDP|SCTP

labelโ€‹

.metadata.labels์„ ์ด์šฉํ•˜๋ฉด ์˜ค๋ธŒ์ ํŠธ๋“ค์„ ํŠน์ • ์ง‘ํ•ฉ์œผ๋กœ ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ์–ด์„œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. ์—ฌ๋Ÿฌ label์„ ์‚ฌ์šฉํ•˜๋ฉด ๊ต์ง‘ํ•ฉ ํ•ฉ์ง‘ํ•ฉ ๋“ฑ์— ๋Œ€ํ•œ ์„ ํƒ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

  • key
    • <prefix>/<name> ํ˜•์‹์˜ ๋ฌธ์ž์—ด์„ ์‚ฌ์šฉ
    • prefix๋Š” DNS ํ•˜์œ„ ๋„๋ฉ”์ธ์œผ๋กœ ํ•ด์•ผํ•˜๋ฉฐ kubernetes.io/, k8s.io/๋Š” ์˜ˆ์•ฝ๋œ ๊ฐ’
    • name์€ 63์ž ์ดํ•˜, ์‹œ์ž‘๊ณผ ๋์€ [a-zA-Z0-9], ์ค‘๊ฐ„์— [-\._]๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Œ
info

.metadata.annotation์€ label์ฒ˜๋Ÿผ selector ๊ฐ™์€ ๊ฒƒ์€ ์—†์ง€๋งŒ ์ƒ๋Œ€์ ์œผ๋กœ ๊ธด ๊ฐ’์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ƒˆ๋กœ์šด ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•˜๊ธฐ ์ „, spec์— ์ถ”๊ฐ€ํ•  ๊ฐ’์„ ์šฐ์„  annotation์— ์ถ”๊ฐ€ํ•ด์„œ ํ…Œ์ŠคํŠธ ํ•ด๋ณด๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

namespaceโ€‹

.metadata.namespace๋Š” ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์—์„œ ๋ฆฌ์†Œ์Šค ๊ทธ๋ฃน์„ ๊ฒฉ๋ฆฌํ•˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์ ์€ ๊ฒฝ์šฐ label๋งŒ์œผ๋กœ ์ถฉ๋ถ„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

kubernetes config set-context --current --namespace <namespace> ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์ปจํ…์ŠคํŠธ์˜ ๊ธฐ๋ณธ namespace๋ฅผ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Probeโ€‹

kubelet์— ์˜ํ•ด ์ฃผ๊ธฐ์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜๋Š” ์ง„๋‹จ ์ž‘์—…์„ Probe๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ง„๋‹จ ์ž‘์—… ์ˆ˜ํ–‰์„ ์œ„ํ•ด ๋ฏธ๋ฆฌ ๊ตฌํ˜„๋œ ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ExecAction(exec): ์ฃผ์–ด์ง„ ์ปค๋งจ๋“œ ์ˆ˜ํ–‰ ํ›„ return code == 0 ์ด๋ฉด ์„ฑ๊ณต
  • TCPSocketAction(tcpSocket): ์ง€์ • port๊ฐ€ ํ™œ์„ฑํ™” ๋˜์–ด ์žˆ๋‹ค๋ฉด ์„ฑ๊ณต
  • HTTPGetAction(httpGet): ์ง€์ • <host>:<port><path> ์— GET ์š”์ฒญ ์ˆ˜ํ–‰ ํ›„ 200 <= status code < 400 ์ด๋ฉด ์„ฑ๊ณต

์ง„๋‹จ ์„ฑ๊ณต ๋˜๋Š” probe๊ฐ€ ์—†์„ ์‹œ Success, ์‹คํŒจ ์‹œ Failure, ์ง„๋‹จ ์ž์ฒด๊ฐ€ ์‹คํŒจํ•˜๋Š” ๊ฒฝ์šฐ Unknown์œผ๋กœ ํ‘œ์‹œ๋ฉ๋‹ˆ๋‹ค.

startupProbeโ€‹

์ปจํ…Œ์ด๋„ˆ ๋‚ด์˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹œ์ž‘๋˜์—ˆ๋Š”์ง€๋ฅผ ์ง„๋‹จํ•ฉ๋‹ˆ๋‹ค. startupProbe๊ฐ€ ์ฃผ์–ด์ง„ ๊ฒฝ์šฐ, ์„ฑ๊ณตํ•  ๋•Œ๊นŒ์ง€ ๋‹ค๋ฅธ ๋‚˜๋จธ์ง€ ํ”„๋กœ๋ธŒ๋Š” ํ™œ์„ฑํ™”๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. startupProbe๊ฐ€ ์‹คํŒจํ•˜๋ฉด, kubelet์ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ฃฝ์ด๊ณ , ์ปจํ…Œ์ด๋„ˆ๋Š” restartPolicy์— ๋”ฐ๋ผ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

kubectl explain pod.spec.containers.startupProbe --recursive

livenessProbeโ€‹

์ปจํ…Œ์ด๋„ˆ๊ฐ€ ๋™์ž‘ ์ค‘์ธ์ง€ ์—ฌ๋ถ€๋ฅผ ์ง„๋‹จํ•ฉ๋‹ˆ๋‹ค. livenessProbe๊ฐ€ ์‹คํŒจํ•˜๋ฉด, kubelet์ด ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์ฃฝ์ด๊ณ , ์ปจํ…Œ์ด๋„ˆ๋Š” restartPolicy์— ๋”ฐ๋ผ ์ฒ˜๋ฆฌ๋ฉ๋‹ˆ๋‹ค.

kubectl explain pod.spec.containers.livenessProbe --recursive

readinessProbeโ€‹

์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ์ง„๋‹จํ•ฉ๋‹ˆ๋‹ค. readinessProbe๊ฐ€ ์‹คํŒจํ•˜๋ฉด, Endpoints ์ปจํŠธ๋กค๋Ÿฌ๋Š” Pod์— ์—ฐ๊ด€๋œ ๋ชจ๋“  Service๋“ค์˜ Endpoints์—์„œ Pod์˜ IP์ฃผ์†Œ๋ฅผ ์ œ๊ฑฐํ•ฉ๋‹ˆ๋‹ค.

๋ฌธ์ œ ์žˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์˜์กด์„ฑ์ด ์žˆ๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ์ ‘๊ทผ์„ ์‚ฌ์ „์— ์ฐจ๋‹จํ•ด ์คŒ์œผ๋กœ์จ ๋ฌธ์ œ๊ฐ€ ์ „ํŒŒ๋˜๋Š” ๊ฒƒ์„ ๋ฐฉ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

kubectl explain pod.spec.containers.readinessProbe --recursive

rolloutโ€‹

kubectl rollout <subcommand> <resource> <name>
  • <subcommand>
    • pause: ์ผ์‹œ ์ค‘์ง€
    • resume: ์ผ์‹œ ์ค‘์ง€ ํ•ด์ œ
    • restart: ์žฌ์‹œ์ž‘
    • status: rollout์ด ์™„๋ฃŒ๋  ๋•Œ๊นŒ์ง€ ์ง„ํ–‰ ์ƒํƒœ๋ฅผ ์ถœ๋ ฅ
    • history: revision ๋ชฉ๋ก, --revision <int>์„ ์„ค์ •ํ•˜๋ฉด ์ž์„ธํ•œ ์ •๋ณด๋ฅผ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Œ
    • undo: ์ด์ „ revision ๋กœ ๋˜๋Œ๋ฆฌ๊ธฐ, --to-revision <int>์„ ์„ค์ •ํ•˜๋ฉด ํ•ด๋‹น revision์œผ๋กœ ๋˜๋Œ๋ฆด ์ˆ˜ ์žˆ์Œ
  • <resource>
    • deployment
    • statefulset
    • daemonset

Referenceโ€‹