Information in this document may be out of date
This document has an older update date than the original, so the information it contains may be out of date. If you're able to read English, see the English version for the most up-to-date information: Declarative Management of Kubernetes Objects Using Configuration Files
๊ตฌ์ฑ ํ์ผ์ ์ด์ฉํ ์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ์ ์ ์ธํ ๊ด๋ฆฌ
์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ๋ ์ฌ๋ฌ ๊ฐ์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์
๋๋ ํฐ๋ฆฌ์ ์ ์ฅํ๊ณ ํ์์ ๋ฐ๋ผ kubectl apply
๋ฅผ
์ฌ์ฉํ์ฌ ์ฌ๊ท์ ์ผ๋ก ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๊ณ ์
๋ฐ์ดํธํจ์ผ๋ก์จ ์์ฑ, ์
๋ฐ์ดํธ ๋ฐ ์ญ์ ํ ์ ์๋ค.
์ด ๋ฐฉ์์ ๋ณ๊ฒฝ์ฌํญ์ ๋๋๋ ค ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์ ๋ณํฉํ์ง ์๊ณ
ํ์ฑ ์ค๋ธ์ ํธ์ ๊ฐํด์ง ๊ธฐ๋ก์ ์ ์งํ๋ค. kubectl diff
๋ ๋ํ
apply
๊ฐ ์ด๋ ํ ๋ณ๊ฒฝ์ฌํญ์ ์ด๋ฃจ์ด์ง์ง์ ๋ํ ํ๋ฆฌ๋ทฐ๋ฅผ ์ ๊ณตํ๋ค.
์์ํ๊ธฐ ์ ์
kubectl
๋ฅผ ์ค์นํ๋ค.
์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ๊ฐ ํ์ํ๊ณ , kubectl ์ปค๋งจ๋-๋ผ์ธ ํด์ด ํด๋ฌ์คํฐ์ ํต์ ํ ์ ์๋๋ก ์ค์ ๋์ด ์์ด์ผ ํ๋ค. ์ด ํํ ๋ฆฌ์ผ์ ์ปจํธ๋กค ํ๋ ์ธ ํธ์คํธ๊ฐ ์๋ ๋ ธ๋๊ฐ ์ ์ด๋ 2๊ฐ ํฌํจ๋ ํด๋ฌ์คํฐ์์ ์คํํ๋ ๊ฒ์ ์ถ์ฒํ๋ค. ๋ง์ฝ, ์์ง ํด๋ฌ์คํฐ๋ฅผ ๊ฐ์ง๊ณ ์์ง ์๋ค๋ฉด, minikube๋ฅผ ์ฌ์ฉํด์ ์์ฑํ๊ฑฐ๋ ๋ค์ ์ฟ ๋ฒ๋คํฐ์ค ํ๋ ์ด๊ทธ๋ผ์ด๋ ์ค ํ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
๋ฒ์ ํ์ธ์ ์ํด์, ๋ค์ ์ปค๋งจ๋๋ฅผ ์คํ kubectl version
.
ํธ๋ ์ด๋ ์คํ
kubectl
ํด์ ์ธ ๊ฐ์ง ๋ฐฉ์์ ์ค๋ธ์ ํธ ๊ด๋ฆฌ๋ฅผ ์ง์ํ๋ค.
- ๋ช ๋ นํ ์ปค๋งจ๋
- ๋ช ๋ นํ ์ค๋ธ์ ํธ ๊ตฌ์ฑ
- ์ ์ธํ ์ค๋ธ์ ํธ ๊ตฌ์ฑ
์ค๋ธ์ ํธ ๊ด๋ฆฌ ๋ฐฉ์์ ์ข ๋ฅ๋ณ ์ฅ๋จ์ ์ ๋ํ ๋ ผ์๋ ์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ ๊ด๋ฆฌ๋ฅผ ์ฐธ๊ณ ํ๋ค.
๊ฐ์
์ ์ธํ ์ค๋ธ์ ํธ ๊ตฌ์ฑ์ ์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ ์ ์์ ๊ตฌ์ฑ์ ๋ํ ํ์คํ ์ดํด๊ฐ ํ์ํ๋ค. ์์ง ๊ทธ๋ ์ง ๋ชปํ๋ค๋ฉด, ๋จผ์ ๋ค์ ๋ฌธ์๋ฅผ ์ฝ๊ณ ์ดํดํ๋ค.
- ๋ช ๋ นํ ์ปค๋งจ๋๋ฅผ ์ฌ์ฉํ ์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ ๊ด๋ฆฌํ๊ธฐ
- ๊ตฌ์ฑ ํ์ผ์ ์ฌ์ฉํ ์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ ๋ช ๋ นํ ๊ด๋ฆฌ
๋ค์์ ์ด ๋ฌธ์์์ ์ฌ์ฉ๋๋ ์ฉ์ด์ ๋ํ ์ ์์ด๋ค.
- ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ / ๊ตฌ์ฑ ํ์ผ: ์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ์ ๋ํ
๊ตฌ์ฑ์ ์ ์ํ๋ ํ๋์ ํ์ผ. ์ด ์ฃผ์ ๋ ์ด๋ป๊ฒ
kubectl apply
์ ๊ตฌ์ฑ ํ์ผ์ ์ ๋ฌํ๋์ง์ ๋ํด ๋ณด์ฌ์ค๋ค. ๊ตฌ์ฑ ํ์ผ์ ์ผ๋ฐ์ ์ผ๋ก Git๊ณผ ๊ฐ์, ์์ค ์ปจํธ๋กค์ ์ ์ฅ๋๋ค. - ํ์ฑ ์ค๋ธ์ ํธ ๊ตฌ์ฑ / ํ์ฑ ๊ตฌ์ฑ: ์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ์ ์ํด ๊ด์ธก๋ ์ค๋ธ์ ํธ์ ๋ํ ํ์ฑ ๊ตฌ์ฑ ๊ฐ. ์ด๊ฒ๋ค์ ์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ ์ ์ฅ์์ ์ ์ง๋๋ค. ์ผ๋ฐ์ ์ผ๋ก etcd๊ฐ ์ฌ์ฉ๋๋ค.
- ์ ์ธํ ๊ตฌ์ฑ ์์ฑ์ / ์ ์ธํ ์์ฑ์: ํ์ฑ ์ค๋ธ์ ํธ๋ฅผ ์
๋ฐ์ดํธํด ์ฃผ๋
์ฌ๋์ด๋ ์ํํธ์จ์ด. ์ด ์ฃผ์ ์์ ์ธ๊ธํ๋ ํ์ฑ ์์ฑ์๋ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์ ๋ณ๊ฒฝ์ ๊ฐํ๊ณ
kubectl apply
๋ฅผ ์คํํ์ฌ ๋ณ๊ฒฝ์ฌํญ์ ๊ธฐ๋กํ๋ค.
์ค๋ธ์ ํธ ์์ฑ ๋ฐฉ๋ฒ
๊ธฐ์กด์ ์กด์ฌํ๋ ๊ฒ์ ์ ์ธํ, ์ง์ ํ ๋๋ ํฐ๋ฆฌ ๋ด ๊ตฌ์ฑ ํ์ผ์ ์ํด ์ ์๋ ๋ชจ๋ ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๊ธฐ ์ํด kubectl apply
๋ฅผ
์ฌ์ฉํ๋ค.
kubectl apply -f <๋๋ ํฐ๋ฆฌ>/
์ด๊ฒ์ ๊ฐ ์ค๋ธ์ ํธ์ ๋ํด kubectl.kubernetes.io/last-applied-configuration: '{...}'
์ด๋
ธํ
์ด์
์ ์ค์ ํ๋ค. ํด๋น ์ด๋
ธํ
์ด์
์ ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๊ธฐ ์ํด ์ฌ์ฉํ๋
์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์ ๋ด์ฉ์ ํฌํจํ๋ค.
์ฐธ๊ณ :
์ฌ๊ท์ ์ผ๋ก ๋๋ ํฐ๋ฆฌ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด์-R
ํ๋๊ทธ๋ฅผ ์ถ๊ฐํ๋ค.๋ค์์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์ ๋ํ ์์์ด๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
minReadySeconds: 5
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
์์ฑ๋ ์ค๋ธ์ ํธ๋ฅผ ์ถ๋ ฅํ๋ ค๋ฉด kubectl diff
๋ฅผ ์คํํ๋ค.
kubectl diff -f https://k8s.io/examples/application/simple_deployment.yaml
์ฐธ๊ณ :
diff
๋ kube-apiserver
์ ํ์ฑํ๊ฐ ํ์ํ
์๋ฒ์ฌ์ด๋ dry-run์ ์ฌ์ฉํ๋ค.
diff
๋ dry-run ๋ชจ๋์์ ์๋ฒ ์ธก ์ ์ฉ ์์ฒญ์ ์ํํ๋ฏ๋ก,
PATCH
, CREATE
, ๊ทธ๋ฆฌ๊ณ UPDATE
๊ถํ์ ๋ถ์ฌํด์ผ ํ๋ค.
์์ธํ ๊ฒ์
Dry-Run ์ธ์ฆ์ ๋ณธ๋ค.
kubectl apply
๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๋ค.
kubectl apply -f https://k8s.io/examples/application/simple_deployment.yaml
kubectl get
์ ์ฌ์ฉํ์ฌ ํ์ฑ ๊ตฌ์ฑ์ ์ถ๋ ฅํ๋ค.
kubectl get -f https://k8s.io/examples/application/simple_deployment.yaml -o yaml
์ถ๋ ฅ์ kubectl.kubernetes.io/last-applied-configuration
์ด๋
ธํ
์ด์
์ด
ํ์ฑ ๊ตฌ์ฑ์ ๊ธฐ๋ก๋ ๊ฒ์ ๋ณด์ฌ์ฃผ๋ฉฐ, ๊ทธ๊ฒ์ ๊ตฌ์ฑ ํ์ผ๊ณผ ์ผ์นํ๋ค.
kind: Deployment
metadata:
annotations:
# ...
# This is the json representation of simple_deployment.yaml
# It was written by kubectl apply when the object was created
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment",
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
"spec":{"minReadySeconds":5,"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx",
"ports":[{"containerPort":80}]}]}}}}
# ...
spec:
# ...
minReadySeconds: 5
selector:
matchLabels:
# ...
app: nginx
template:
metadata:
# ...
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
# ...
name: nginx
ports:
- containerPort: 80
# ...
# ...
# ...
# ...
์ค๋ธ์ ํธ ์ ๋ฐ์ดํธ ๋ฐฉ๋ฒ
๋ํ ์ค๋ธ์ ํธ๊ฐ ๊ธฐ์กด์ ์กด์ฌํ๋๋ผ๋ ๋๋ ํฐ๋ฆฌ ๋ด ์ ์๋ ๋ชจ๋ ์ค๋ธ์ ํธ๋ฅผ ์
๋ฐ์ดํธํ๊ธฐ ์ํด kubectl apply
๋ฅผ
์ฌ์ฉํ ์ ์๋ค. ์ด๋ฌํ ์ ๊ทผ๋ฐฉ์์ ๋ค์์ ์ํํ ์ ์๊ฒ ํด์ค๋ค.
- ํ์ฑ ๊ตฌ์ฑ ๋ด ๊ตฌ์ฑ ํ์ผ์ ๋ํ๋๋ ํ๋ ์ค์
- ํ์ฑ ๊ตฌ์ฑ ๋ด ๊ตฌ์ฑ ํ์ผ๋ก๋ถํฐ ์ ๊ฑฐ๋ ํ๋ ์ ๋ฆฌ
kubectl diff -f <๋๋ ํฐ๋ฆฌ>/
kubectl apply -f <๋๋ ํฐ๋ฆฌ>/
์ฐธ๊ณ :
์ฌ๊ท์ ์ผ๋ก ๋๋ ํฐ๋ฆฌ๋ฅผ ์ฒ๋ฆฌํ๊ธฐ ์ํด์-R
ํ๋๊ทธ๋ฅผ ์ถ๊ฐํ๋ค.๋ค์์ ๊ตฌ์ฑ ํ์ผ์ ์์์ด๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
minReadySeconds: 5
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
kubectl apply
๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๋ค.
kubectl apply -f https://k8s.io/examples/application/simple_deployment.yaml
์ฐธ๊ณ :
์ค๋ช ์ ์ํด, ์์ ๋ช ๋ น์ ๋๋ ํฐ๋ฆฌ ๋์ ํ๋์ ๊ตฌ์ฑ ํ์ผ์ ์ฐธ์กฐํ๋ค.kubectl get
์ ์ฌ์ฉํ์ฌ ํ์ฑ ๊ตฌ์ฑ์ ์ถ๋ ฅํ๋ค.
kubectl get -f https://k8s.io/examples/application/simple_deployment.yaml -o yaml
์ถ๋ ฅ์ kubectl.kubernetes.io/last-applied-configuration
์ด๋
ธํ
์ด์
์ด
ํ์ฑ ๊ตฌ์ฑ์ ๊ธฐ๋ก๋ ๊ฒ์ ๋ณด์ฌ์ฃผ๋ฉฐ, ๊ทธ๊ฒ์ ๊ตฌ์ฑ ํ์ผ๊ณผ ์ผ์นํ๋ค.
kind: Deployment
metadata:
annotations:
# ...
# This is the json representation of simple_deployment.yaml
# It was written by kubectl apply when the object was created
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment",
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
"spec":{"minReadySeconds":5,"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx",
"ports":[{"containerPort":80}]}]}}}}
# ...
spec:
# ...
minReadySeconds: 5
selector:
matchLabels:
# ...
app: nginx
template:
metadata:
# ...
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
# ...
name: nginx
ports:
- containerPort: 80
# ...
# ...
# ...
# ...
kubectl scale
์ ์ฌ์ฉํ์ฌ ํ์ฑ ๊ตฌ์ฑ ๋ด replicas
ํ๋๋ฅผ ์ง์ ์
๋ฐ์ดํธํ๋ค.
์ด๋ kubectl apply
๋ฅผ ์ฌ์ฉํ์ง ์๋๋ค.
kubectl scale deployment/nginx-deployment --replicas=2
kubectl get
์ ์ฌ์ฉํ์ฌ ํ์ฑ ๊ตฌ์ฑ์ ์ถ๋ ฅํ๋ค.
kubectl get deployment nginx-deployment -o yaml
์ถ๋ ฅ์ replicas
ํ๋๊ฐ 2๋ก ์ค์ ๋ ๊ฒ์ ๋ณด์ฌ์ฃผ๋ฉฐ, last-applied-configuration
์ด๋
ธํ
์ด์
์ replicas
ํ๋๋ฅผ ํฌํจํ์ง ์๋๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
# ...
# note that the annotation does not contain replicas
# because it was not updated through apply
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment",
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
"spec":{"minReadySeconds":5,"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx",
"ports":[{"containerPort":80}]}]}}}}
# ...
spec:
replicas: 2 # written by scale
# ...
minReadySeconds: 5
selector:
matchLabels:
# ...
app: nginx
template:
metadata:
# ...
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
# ...
name: nginx
ports:
- containerPort: 80
# ...
nginx:1.14.2
์์ nginx:1.16.1
๋ก ์ด๋ฏธ์ง๋ฅผ ๋ณ๊ฒฝํ๊ธฐ ์ํด simple_deployment.yaml
๊ตฌ์ฑ ํ์ผ์ ์
๋ฐ์ดํธ ํ๊ณ , minReadySeconds
ํ๋๋ฅผ ์ญ์ ํ๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1 # update the image
ports:
- containerPort: 80
๊ตฌ์ฑ ํ์ผ์ ์ด๋ฃจ์ด์ง ๋ณ๊ฒฝ์ฌํญ์ ์ ์ฉํ๋ค.
kubectl diff -f https://k8s.io/examples/application/update_deployment.yaml
kubectl apply -f https://k8s.io/examples/application/update_deployment.yaml
kubectl get
์ ์ฌ์ฉํ์ฌ ํ์ฑ ๊ตฌ์ฑ์ ์ถ๋ ฅํ๋ค.
kubectl get -f https://k8s.io/examples/application/update_deployment.yaml -o yaml
์ถ๋ ฅ์ ํ์ฑ ๊ตฌ์ฑ์ ๋ค์์ ๋ณ๊ฒฝ์ฌํญ์ ๋ณด์ฌ์ค๋ค.
replicas
ํ๋๋kubectl scale
์ ์ํด ์ค์ ๋ ๊ฐ 2๋ฅผ ์ ์งํ๋ค.
์ด๋ ๊ตฌ์ฑ ํ์ผ์์ ์๋ต๋์๊ธฐ ๋๋ฌธ์ ๊ฐ๋ฅํ๋ค.image
ํ๋๋nginx:1.14.2
์์nginx:1.16.1
๋ก ์ ๋ฐ์ดํธ๋์๋ค.last-applied-configuration
์ด๋ ธํ ์ด์ ์ ์๋ก์ด ์ด๋ฏธ์ง๋ก ์ ๋ฐ์ดํธ๋์๋ค.minReadySeconds
ํ๋๋ ์ง์์ก๋ค.last-applied-configuration
์ด๋ ธํ ์ด์ ์ ๋ ์ด์minReadySeconds
ํ๋๋ฅผ ํฌํจํ์ง ์๋๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
# ...
# The annotation contains the updated image to nginx 1.11.9,
# but does not contain the updated replicas to 2
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment",
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
"spec":{"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
"spec":{"containers":[{"image":"nginx:1.16.1","name":"nginx",
"ports":[{"containerPort":80}]}]}}}}
# ...
spec:
replicas: 2 # Set by `kubectl scale`. Ignored by `kubectl apply`.
# minReadySeconds cleared by `kubectl apply`
# ...
selector:
matchLabels:
# ...
app: nginx
template:
metadata:
# ...
labels:
app: nginx
spec:
containers:
- image: nginx:1.16.1 # Set by `kubectl apply`
# ...
name: nginx
ports:
- containerPort: 80
# ...
# ...
# ...
# ...
๊ฒฝ๊ณ :
๋ช ๋ นํ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ์ปค๋งจ๋create
์ replace
์ ํจ๊ป kubectl apply
๋ฅผ
ํผํฉํ๋ ๊ฒ์ ์ง์ํ์ง ์๋๋ค. ์ด๋ kubectl apply
๊ฐ ์
๋ฐ์ดํธ ์ฌํญ์ ๊ณ์ฐํ๋๋ฐ ์ฌ์ฉํ๋
kubectl.kubernetes.io/last-applied-configuration
์ create
์ replace
๊ฐ
์ ์งํ์ง ํ์ง ์๊ธฐ ๋๋ฌธ์ด๋ค.์ค๋ธ์ ํธ ์ญ์ ๋ฐฉ๋ฒ
kubectl apply
์ ์ํด ๊ด๋ฆฌ๋๋ ์ค๋ธ์ ํธ๋ฅผ ์ญ์ ํ๋๋ฐ 2๊ฐ์ง ์ ๊ทผ ๋ฐฉ๋ฒ์ด ์๋ค.
๊ถ์ฅ ๋ฐฉ๋ฒ: kubectl delete -f <ํ์ผ๋ช
>
๋ช ๋ นํ ์ปค๋งจ๋๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ธ์ ํธ๋ฅผ ์๋์ผ๋ก ์ญ์ ํ๋ ๊ฒ์ด ๊ถ์ฅ๋๋ ๋ฐฉ์์ธ๋ฐ, ๋ฌด์์ด ์ญ์ ๋๋์ง์ ๋ํด ๋ ๋ช ํํ๊ฒ ๋ํ๋ด๋ฏ๋ก ์ฌ์ฉ์๊ฐ ์๋ํ์ง ์๊ฒ ๋ฌด์ธ๊ฐ๋ฅผ ์ญ์ ํ ๊ฐ๋ฅ์ฑ์ด ์์์ง๊ธฐ ๋๋ฌธ์ด๋ค.
kubectl delete -f <ํ์ผ๋ช
>
๋์: kubectl apply -f <๋๋ ํฐ๋ฆฌ/> --prune -l your=๋ ์ด๋ธ
๋ฌด์์ ํ๋์ง ํ์ ํ๋ ๊ฒฝ์ฐ์๋ง ์ด๋ฅผ ์ฌ์ฉํ๋ค.
๊ฒฝ๊ณ :
kubectl apply --prune
์ ์ํ ์ํ์ด๋ฉฐ, ํ์ ๋ฆด๋ฆฌ์ค์์๋
ํ์ ํธํ๋์ง ์๋ ๋ณ๊ฒฝ ์ฌํญ์ด ๋์
๋ ์ ์๋ค.๊ฒฝ๊ณ :
์ด ๋ช ๋ น์ ์ฌ์ฉํ ๋๋ ์๋ํ์ง ์๊ฒ ์ค๋ธ์ ํธ๋ฅผ ์ญ์ ํ์ง ์๋๋ก ์ฃผ์ํด์ผ๋ง ํ๋ค.kubectl delete
์ ๋ํ ๋์์ผ๋ก, ๋๋ ํฐ๋ฆฌ๋ก๋ถํฐ ๊ตฌ์ฑ ํ์ผ์ด ์ญ์ ๋ ํ์ ์ญ์ ๋ ์ค๋ธ์ ํธ๋ฅผ ์๋ณํ๊ธฐ ์ํด kubectl apply
๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
--prune
์ ์ฌ์ฉํ์ฌ ์ ์ฉํ๋ฉด ์ผ๋ จ์ ๋ ์ด๋ธ์ ์งํฉ๊ณผ ์ผ์นํ๋
๋ชจ๋ ์ค๋ธ์ ํธ์ ๋ํดAPI ์๋ฒ์ ์ฟผ๋ฆฌํ๊ณ , ๋ฐํ๋ ํ์ฑ ์ค๋ธ์ ํธ
๊ตฌ์ฑ์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์ ์ผ์น์ํค๋ ค๊ณ ์๋ํ๋ค.
์ค๋ธ์ ํธ๊ฐ ์ฟผ๋ฆฌ์ ์ผ์นํ๊ณ , ํด๋น ๋๋ ํฐ๋ฆฌ ๋ด ๊ตฌ์ฑ ํ์ผ์ด ์๊ณ
last-applied-configuration
์ด๋
ธํ
์ด์
์ด ์๋ ๊ฒฝ์ฐ,
์ญ์ ๋๋ค.
kubectl apply -f <๋๋ ํฐ๋ฆฌ/> --prune -l <๋ ์ด๋ธ>
๊ฒฝ๊ณ :
prune์ ์ฌ์ฉํ์ฌ ์ ์ฉํ๋ ๊ฒ์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ์ ํฌํจํ๋ ๋ฃจํธ ๋๋ ํฐ๋ฆฌ์ ๋ํด์๋ง ์คํํด์ผ ํ๋ค. ํ์ ๋๋ ํฐ๋ฆฌ์ ๋ํด ์คํํ๊ฒ ๋๋ฉด,-l <๋ ์ด๋ธ>
๋ก ์ง์ ๋ ๋ ์ด๋ธ ์
๋ ํฐ์ ์ํด ๋ฐํ๋๊ณ ํ์ ๋๋ ํฐ๋ฆฌ์ ๋ํ๋์ง ์๋ ๊ฒฝ์ฐ,
์ค๋ธ์ ํธ๊ฐ ์๋ํ์ง ์๊ฒ ์ญ์ ๋ ์ ์๋ค.์ค๋ธ์ ํธ ํ์ธ ๋ฐฉ๋ฒ
ํ์ฑ ์ค๋ธ์ ํธ์ ๊ตฌ์ฑ์ ํ์ธํ๊ธฐ ์ํด -o yaml
๊ณผ ํจ๊ป kubectl get
์ ์ฌ์ฉํ ์ ์๋ค.
kubectl get -f <ํ์ผ๋ช
|url> -o yaml
์ด๋ป๊ฒ apply๊ฐ ์ฐจ์ด๋ฅผ ๊ณ์ฐํ๊ณ ๋ณ๊ฒฝ์ ๋ณํฉํ๋๊ฐ
์ฃผ์:
patch ๋ ์ ์ฒด ์ค๋ธ์ ํธ ๋์ ์ค๋ธ์ ํธ์ ํน์ ํ๋ ๋ฒ์์ ์คํผ๋ ์ด์ ์ ์ ๋ฐ์ดํธํ๋ค. ์ด๋ ๋จผ์ ์ค๋ธ์ ํธ๋ฅผ ์ฝ์ง ์๊ณ ๋ ์ค๋ธ์ ํธ์ ํน์ ํ๋ ์งํฉ๋ง์ ์ ๋ฐ์ดํธํ ์ ์๋๋ก ํด์ค๋ค.kubectl apply
๊ฐ ํ๋์ ์ค๋ธ์ ํธ์ ๋ํ ํ์ฑ ๊ตฌ์ฑ์ ์
๋ฐ์ดํธํ ๋,
API ์๋ฒ์ ํจ์น ์์ฒญ์ ๋ณด๋์ผ๋ก์จ ๊ทธ๊ฒ์ ์ํํ๋ค.
๊ทธ ํจ์น๋ ํ์ฑ ์ค๋ธ์ ํธ ๊ตฌ์ฑ์ ํน์ ํ๋์ ๋ํ ๋ฒ์์
์
๋ฐ์ดํธ๋ก ํ์ ํ๋ค. kubectl apply
์ปค๋งจ๋๋
๊ตฌ์ฑ ํ์ผ, ํ์ฑ ๊ตฌ์ฑ, ๊ทธ๋ฆฌ๊ณ ํ์ฑ ๊ตฌ์ฑ์ ์ ์ฅ๋
last-applied-configuration
์ด๋
ธํ
์ด์
์ ์ฌ์ฉํ์ฌ ์ด ํจ์น ์์ฒญ์ ๊ณ์ฐํ๋ค.
ํจ์น ๊ณ์ฐ ๋ณํฉ
kubectl apply
๋ช
๋ น์
kubectl.kubernetes.io/last-applied-configuration
์ด๋
ธํ
์ด์
์ ๊ตฌ์ฑ ํ์ผ์ ๋ด์ฉ์ ๊ธฐ๋กํ๋ค.
์ด๊ฒ์ ๊ตฌ์ฑ ํ์ผ๋ก๋ถํฐ ์ ๊ฑฐ๋์๊ณ ํ์ฑ ๊ตฌ์ฑ์ผ๋ก๋ถํฐ ์ง์์ง ํ์๊ฐ ์๋
ํ๋๋ฅผ ํ์ธํ๋ ๋ฐ ์ฌ์ฉ๋๋ค. ๋ค์์ ์ด๋ค ํ๋๊ฐ ์ญ์ ๋๋ ์ค์ ๋ผ์ผ ํ๋์ง
๊ณ์ฐํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ ๋จ๊ณ์ด๋ค.
- ์ญ์ ํ ํ๋๋ฅผ ๊ณ์ฐํ๋ค. ์ด๊ฒ์
last-applied-configuration
๋ด ์กด์ฌํ๊ณ ๊ตฌ์ฑ ํ์ผ๋ก๋ถํฐ ์ ์ค๋ ํ๋์ด๋ค. - ์ถ๊ฐ ๋๋ ์ค์ ๋์ด์ผ ํ ํ๋๋ฅผ ๊ณ์ฐํ๋ค. ์ด๊ฒ์ ํ์ฑ ๊ตฌ์ฑ๊ณผ ๋ถ์ผ์นํ๋ ๊ฐ์ ๊ฐ์ง๋ ๊ตฌ์ฑ ํ์ผ ๋ด ์กด์ฌํ๋ ํ๋์ด๋ค.
๋ค์์ ์์์ด๋ค. ๋ํ๋ก์ด๋จผํธ ์ค๋ธ์ ํธ์ ๋ํ ๊ตฌ์ฑ ํ์ผ์ด๋ผ๊ณ ๊ฐ์ ํ๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1 # update the image
ports:
- containerPort: 80
๋ํ, ์ด๊ฒ์ ๋์ผํ ๋ํ๋ก์ด๋จผํธ ์ค๋ธ์ ํธ์ ๋ํ ํ์ฑ ๊ตฌ์ฑ์ด๋ผ๊ณ ๊ฐ์ ํ๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
# ...
# note that the annotation does not contain replicas
# because it was not updated through apply
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment",
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
"spec":{"minReadySeconds":5,"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
"spec":{"containers":[{"image":"nginx:1.14.2","name":"nginx",
"ports":[{"containerPort":80}]}]}}}}
# ...
spec:
replicas: 2 # written by scale
# ...
minReadySeconds: 5
selector:
matchLabels:
# ...
app: nginx
template:
metadata:
# ...
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
# ...
name: nginx
ports:
- containerPort: 80
# ...
๋ค์์ kubectl apply
์ ์ํด ์ํ๋ ๋ณํฉ ๊ณ์ฐ์ด๋ค.
last-applied-configuration
์ผ๋ก๋ถํฐ ๊ฐ์ ์ฝ์ด ๊ตฌ์ฑ ํ์ผ์ ๊ฐ๊ณผ ๋น๊ตํ์ฌ ์ญ์ ํ ํ๋๋ฅผ ๊ณ์ฐํ๋ค.last-applied-configuration
์ ๋ณด์ด๋ ๊ฒ๊ณผ๋ ๋ฌด๊ดํ๊ฒ ๋ก์ปฌ์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ ๋ด null์ด๋ผ๊ณ ๋ช ์์ ์ผ๋ก ์ค์ ๋ ํ๋๋ฅผ ์ง์ด๋ค. ์ด ์์์์,minReadySeconds
์last-applied-configuration
์ด๋ ธํ ์ด์ ๋ด ๋ํ๋์ง๋ง, ๊ตฌ์ฑ ํ์ผ ๋ด์๋ ๋ณด์ฌ์ง์ง ์๋๋ค. ์กฐ์น: ํ์ฑ ๊ตฌ์ฑ์ผ๋ก๋ถํฐminReadySeconds
์ ์ง์ด๋ค.- ๊ตฌ์ฑ ํ์ผ๋ก๋ถํฐ ๊ฐ์ ์ฝ์ด ํ์ฑ ๊ตฌ์ฑ ๋ด ๊ฐ๊ณผ
๋น๊ตํ์ฌ ์ค์ ํ ํ๋๋ฅผ ๊ณ์ฐํ๋ค. ์ด ์์์์,
๊ตฌ์ฑ ํ์ผ ๋ด
image
๊ฐ์ ํ์ฑ ๊ตฌ์ฑ ๋ด ๊ฐ๊ณผ ๋ถ์ผ์นํ๋ค. ์กฐ์น: ํ์ฑ ๊ตฌ์ฑ ๋ดimage
๊ฐ์ ์ค์ ํ๋ค. - ๊ตฌ์ฑ ํ์ผ์ ๊ฐ๊ณผ ์ผ์น์ํค๊ธฐ ์ํด
last-applied-configuration
์ด๋ ธํ ์ด์ ์ ์ค์ ํ๋ค. - 1, 2, 3์ผ๋ก๋ถํฐ์ ๊ฒฐ๊ณผ๋ฅผ API ์๋ฒ์ ๋จ์ผ ํจ์น ์์ฒญ์ผ๋ก ๋ณํฉํ๋ค.
๋ค์์ ๋ณํฉ์ ๊ฒฐ๊ณผ์ธ ํ์ฑ ๊ตฌ์ฑ์ด๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
# ...
# The annotation contains the updated image to nginx 1.11.9,
# but does not contain the updated replicas to 2
kubectl.kubernetes.io/last-applied-configuration: |
{"apiVersion":"apps/v1","kind":"Deployment",
"metadata":{"annotations":{},"name":"nginx-deployment","namespace":"default"},
"spec":{"selector":{"matchLabels":{"app":nginx}},"template":{"metadata":{"labels":{"app":"nginx"}},
"spec":{"containers":[{"image":"nginx:1.16.1","name":"nginx",
"ports":[{"containerPort":80}]}]}}}}
# ...
spec:
selector:
matchLabels:
# ...
app: nginx
replicas: 2 # Set by `kubectl scale`. Ignored by `kubectl apply`.
# minReadySeconds cleared by `kubectl apply`
# ...
template:
metadata:
# ...
labels:
app: nginx
spec:
containers:
- image: nginx:1.16.1 # Set by `kubectl apply`
# ...
name: nginx
ports:
- containerPort: 80
# ...
# ...
# ...
# ...
์ด๋ป๊ฒ ์์ดํ ํ๋ ํ์ ์ด ๋ณํฉ๋๋๊ฐ
๊ตฌ์ฑ ํ์ผ ๋ด ํน์ ํ๋๊ฐ ํ๋์ ํ์ ์ ๋ฐ๋ผ ์ด๋ป๊ฒ ํ์ฑ ๊ตฌ์ฑ๊ณผ ํจ๊ป ๋ณํฉ๋๋๊ฐ. ์ฌ๋ฌ ๊ฐ์ง ํ๋ ํ์ ์ด ์๋ค.
๊ธฐ๋ณธ(primitives): ๋ฌธ์์ด, ์ซ์ ๋๋ ๋ถ๋ฆฌ์ธ ํ์ ์ ํ๋. ์๋ฅผ ๋ค์ด,
image
์replicas
๋ ๊ธฐ๋ณธ ํ๋๋ค. ์กฐ์น: ๊ต์ฒด.๋งต, ๋ํ ์ค๋ธ์ ํธ ๋ผ ์นญํจ: ๋งต ํ์ ๋๋ ์๋ธํ๋๋ฅผ ํฌํจํ๋ ๋ณตํฉ ํ์ ์ ํ๋. ์๋ฅผ ๋ค์ด,
๋ ์ด๋ธ
,์ด๋ ธํ ์ด์
,์คํ
๋ฐ๋ฉํ๋ฐ์ดํฐ
๋ ๋ชจ๋ ๋งต์ด๋ค. ์กฐ์น: ๊ตฌ์ฑ์์ ๋๋ ์๋ธํ๋ ๋ณํฉ.๋ฆฌ์คํธ: ๊ธฐ๋ณธํ์ ๋๋ ๋งต์ด ๋ ์ ์๋ ์์ดํ ์ ๋ฆฌ์คํธ๋ฅผ ํฌํจํ๋ ํ๋. ์๋ฅผ ๋ค์ด,
์ปจํ ์ด๋
,ํฌํธ
, ๊ทธ๋ฆฌ๊ณargs
๋ ๋ฆฌ์คํธ๋ค. ์กฐ์น: ๋ค์ํจ.
kubectl apply
๊ฐ ๋งต ๋๋ ๋ฆฌ์คํธ ํ๋๋ฅผ ์
๋ฐ์ดํธํ๋ ๊ฒฝ์ฐ,
์ผ๋ฐ์ ์ผ๋ก ์ ์ฒด ํ๋๋ฅผ ๊ต์ฒดํ๋ ๋์ , ๊ฐ๋ณ ๋ถ ๊ตฌ์ฑ์์๋ฅผ ์
๋ฐ์ดํธํ๋ค,
์๋ฅผ ๋ค์ด, ๋ํ๋ก์ด๋จผํธ์ ๋ํ spec
์ ๋ณํฉํ ๊ฒฝ์ฐ, ์ ์ฒด spec
์ด
๊ต์ฒด๋์ง ์๋๋ค. ๋์ replicas
์ ๊ฐ์ spec
์ ์๋ธํ๋๊ฐ
๋น๊ต๋๊ณ ๋ณํฉ๋๋ค.
๊ธฐ๋ณธ ํ๋์ ๋ํ ๋ณ๊ฒฝ์ฌํญ ๋ณํฉํ๊ธฐ
๊ธฐ๋ณธ ํ๋๋ ๊ต์ฒด๋๊ฑฐ๋ ์ง์์ง๋ค.
์ฐธ๊ณ :
-
๋ ๊ฐ์ด ์ฌ์ฉ๋์ง ์๊ธฐ ๋๋ฌธ์ "ํด๋น ์์"์ผ๋ก ์ฌ์ฉ๋๋ค.Field in object configuration file | Field in live object configuration | Field in last-applied-configuration | Action |
---|---|---|---|
Yes | Yes | - | ๊ตฌ์ฑ ํ์ผ ๊ฐ ํ์ฑ์ผ๋ก ์ค์ . |
Yes | No | - | ํ์ฑ์ ๋ก์ปฌ ๊ตฌ์ฑ์ผ๋ก ์ค์ . |
No | - | Yes | ํ์ฑ ๊ตฌ์ฑ์ผ๋ก๋ถํฐ ์ง์. |
No | - | No | ์๋ฌด๊ฒ๋ ์ํจ. ํ์ฑ๊ฐ ์ ์ง. |
๋งต ํ๋์ ๋ณ๊ฒฝ์ฌํญ ๋ณํฉํ๊ธฐ
๋งต์ ์์ฒญํ๋ ํ๋๋ ์๋ธํ๋์ ๊ฐ๊ฐ ๋๋ ๋งต์ ๊ตฌ์ฑ์์๋ฅผ ๋น๊ตํจ์ผ๋ก์จ ๋ณํฉ๋๋ค.
์ฐธ๊ณ :
-
๋ ๊ฐ์ด ์ฌ์ฉ๋์ง ์๊ธฐ ๋๋ฌธ์ "ํด๋น ์์"์ผ๋ก ์ฌ์ฉ๋๋ค.Key in object configuration file | Key in live object configuration | Field in last-applied-configuration | Action |
---|---|---|---|
Yes | Yes | - | ์๋ธํ๋ ๊ฐ ๋น๊ต. |
Yes | No | - | ํ์ฑ์ ๋ก์ปฌ ๊ตฌ์ฑ์ผ๋ก ์ค์ . |
No | - | Yes | ํ์ฑ ๊ตฌ์ฑ์ผ๋ก๋ถํฐ ์ญ์ . |
No | - | No | ์๋ฌด๊ฒ๋ ์ํจ. ํ์ฑ๊ฐ ์ ์ง. |
ํ์ ๋ฆฌ์คํธ์ ํ๋์ ๋ํ ๋ณ๊ฒฝ์ฌํญ ๋ณํฉํ๊ธฐ
๋ฆฌ์คํธ์ ๋ํ ๋ณ๊ฒฝ์ฌํญ์ ๋ณํฉํ๋ ๊ฒ์ ์ธ ๊ฐ์ง ์ ๋ต ์ค ํ๋๋ฅผ ์ฌ์ฉํ๋ค.
- ๊ตฌ์ฑ์์๊ฐ ๋ชจ๋ ๊ธฐ๋ณธํ์ธ ๊ฒฝ์ฐ ๋ฆฌ์คํธ๋ฅผ ๊ต์ฒดํ๋ค.
- ๋ณตํฉ ๊ตฌ์ฑ์์์ ๋ฆฌ์คํธ์์ ๊ฐ๋ณ ๊ตฌ์ฑ์์๋ฅผ ๋ณํฉํ๋ค.
- ๊ธฐ์ด ๊ตฌ์ฑ์์์ ๋ฆฌ์คํธ๋ฅผ ๋ณํฉํ๋ค.
์ ๋ต์ ๋ํ ์ ํ์ ํ๋๋ณ๋ก ์ด๋ฃจ์ด์ง๋ค.
๊ตฌ์ฑ์์๊ฐ ๋ชจ๋ ๊ธฐ๋ณธํ์ธ ๊ฒฝ์ฐ ๋ฆฌ์คํธ ๊ต์ฒด
๊ธฐ์ด ํ๋์ ๋์ผํ ๋ฆฌ์คํธ๋ก ์ทจ๊ธํ๋ค. ์ ์ฒด ๋ฆฌ์คํธ๋ฅผ ๊ต์ฒด ๋๋ ์ญ์ ํ๋ค. ์ด๊ฒ์ ์์๋ฅผ ์ ์งํ๋ค.
์์: ํ๋ ๋ด ์ปจํ
์ด๋์ args
ํ๋๋ฅผ ์
๋ฐ์ดํธํ๊ธฐ ์ํด kubectl apply
๋ฅผ ์ฌ์ฉํ๋ค.
์ด๊ฒ์ ํ์ฑ ๊ตฌ์ฑ ๋ด args
์ ๊ฐ์ ๊ตฌ์ฑ ํ์ผ ๋ด ๊ฐ์ผ๋ก ์ค์ ํ๋ค.
ํ์ฑ ๊ตฌ์ฑ์ ์ถ๊ฐํ๋ ์ด์ ์ ๋ชจ๋ args
๊ตฌ์ฑ์์๋ค์ ์ ์ค๋๋ค.
๊ตฌ์ฑ ํ์ผ ๋ด ์ ์ํ args
๊ตฌ์ฑ์์์ ์์๋
ํ์ฑ ๊ตฌ์ฑ ๋ด ์ ์ง๋๋ค.
# last-applied-configuration value
args: ["a", "b"]
# configuration file value
args: ["a", "c"]
# live configuration
args: ["a", "b", "d"]
# result after merge
args: ["a", "c"]
์ค๋ช : ๋ณํฉ์ ์๋ก์ด ๋ฆฌ์คํธ ๊ฐ์ผ๋ก ๊ตฌ์ฑ ํ์ผ ๊ฐ์ ์ฌ์ฉํ๋ค.
๋ณตํฉ ๊ตฌ์ฑ์์ ๋ฆฌ์คํธ์ ๋ํ ๊ฐ๋ณ ๊ตฌ์ฑ์์ ๋ณํฉ
๋ฆฌ์คํธ๋ฅผ ๋งต์ผ๋ก ์ทจ๊ธํ๊ณ ๊ฐ ๊ตฌ์ฑ์์์ ํน์ ํ๋๋ฅผ ํค๋ก ์ทจ๊ธํ๋ค. ๊ฐ๋ณ ๊ตฌ์ฑ์์๋ฅผ ์ถ๊ฐ, ์ญ์ , ๋๋ ์ ๋ฐ์ดํธ ํ๋ค. ์ด๊ฒ์ ์์๋ฅผ ๋ณด์กดํ์ง ์๋๋ค.
์ด ๋ณํฉ ์ ๋ต์ ๊ฐ ํ๋์ patchMergeKey
๋ผ ์นญํ๋ ํน๋ณํ ํ๊ทธ๋ฅผ ์ฌ์ฉํ๋ค.
patchMergeKey
๋ ์ฟ ๋ฒ๋คํฐ์ค ์์ค ์ฝ๋:
types.go
์ ๊ฐ ํ๋์ ๋ํด ์ ์ํ๋ค. ๋งต ๋ฆฌ์คํธ๋ฅผ ๋ณํฉํ ๋, ์ฃผ์ด์ง ๊ตฌ์ฑ์์์ ๋ํ patchMergeKey
๋ก
์ง์ ํ ํ๋๋ ํด๋น ๊ตฌ์ฑ์์์ ๋ํ ๋งตํค์ ๊ฐ์ด ์ฌ์ฉ๋๋ค.
์์: kubectl apply
๋ฅผ ์ฌ์ฉํ์ฌ PodSpec์ ๋ํ containers
ํ๋๋ฅผ ์
๋ฐ์ดํธํ๋ค.
์ด๋ ๊ฒ ํ๋ฉด ๊ฐ ๊ตฌ์ฑ์์๊ฐ
name
๋ณ๋ก ํค๋ก ๋์ด ์๋ ๋งต์ธ ๊ฒ์ฒ๋ผ ๋ฆฌ์คํธ๋ฅผ ๋ณํฉํ๋ค.
# last-applied-configuration value
containers:
- name: nginx
image: nginx:1.10
- name: nginx-helper-a # key: nginx-helper-a; will be deleted in result
image: helper:1.3
- name: nginx-helper-b # key: nginx-helper-b; will be retained
image: helper:1.3
# configuration file value
containers:
- name: nginx
image: nginx:1.10
- name: nginx-helper-b
image: helper:1.3
- name: nginx-helper-c # key: nginx-helper-c; will be added in result
image: helper:1.3
# live configuration
containers:
- name: nginx
image: nginx:1.10
- name: nginx-helper-a
image: helper:1.3
- name: nginx-helper-b
image: helper:1.3
args: ["run"] # Field will be retained
- name: nginx-helper-d # key: nginx-helper-d; will be retained
image: helper:1.3
# result after merge
containers:
- name: nginx
image: nginx:1.10
# Element nginx-helper-a was deleted
- name: nginx-helper-b
image: helper:1.3
args: ["run"] # Field was retained
- name: nginx-helper-c # Element was added
image: helper:1.3
- name: nginx-helper-d # Element was ignored
image: helper:1.3
์ค๋ช :
- ๊ตฌ์ฑ ํ์ผ์ "nginx-helper-a"๋ผ๋ ์ด๋ฆ์ ๊ฐ์ง ์ปจํ ์ด๋๊ฐ ๋ํ๋์ง ์์๊ธฐ ๋๋ฌธ์ "nginx-helper-a"๋ผ๋ ์ปจํ ์ด๋๋ ์ญ์ ๋์๋ค.
- "nginx-helper-b"๋ผ๋ ์ปจํ
์ด๋๋ ํ์ฑ ๊ตฌ์ฑ์
args
์
๋ํ ๋ณ๊ฒฝ์ฌํญ์ ์ ์งํ๋ค.kubectl apply
๋
ํ๋ ๊ฐ์ด ๋ค๋ฆ์๋ ๋ถ๊ตฌํ๊ณ (๊ตฌ์ฑ ํ์ผ์args
๊ฐ ์์) ํ์ฑ ๊ตฌ์ฑ์
"nginx-helper-b"๊ฐ ๊ตฌ์ฑ ํ์ผ๊ณผ ๋์ผํ "nginx-helper-b"์์ ์๋ณํ ์ ์์๋ค. ์ด๊ฒ์patchMergeKey
ํ๋ ๊ฐ(์ด๋ฆ)์ด ๋ ๋ค ๊ฐ์๊ธฐ ๋๋ฌธ์ด๋ค.. - "nginx-helper-c"๋ผ๋ ์ด๋ฆ์ ์ปจํ ์ด๋๊ฐ ํ์ฑ ๊ตฌ์ฑ์ ๋ํ๋์ง ์์์ง๋ง, ๊ตฌ์ฑ ํ์ผ์ ๊ทธ ์ด๋ฆ์ ๊ฐ์ง ์ปจํ ์ด๋๊ฐ ๋ํ๋ฌ๊ธฐ ๋๋ฌธ์ ์ถ๊ฐ๋์๋ค.
- last-applied-configuration์ ๊ทธ ์ด๋ฆ์ ๊ฐ์ง ๊ตฌ์ฑ์์๊ฐ ์์๊ธฐ ๋๋ฌธ์ "nginx-helper-d"๋ผ๋ ์ด๋ฆ์ ์ปจํ ์ด๋๋ ์ ์ง๋์๋ค.
๊ธฐ์ด ๊ตฌ์ฑ์์ ๋ฆฌ์คํธ ๋ณํฉ
์ฟ ๋ฒ๋คํฐ์ค 1.5๋ก๋ถํฐ ๊ธฐ์ด ๊ตฌ์ฑ์์ ๋ณํฉํ๊ธฐ๋ ์ง์๋์ง ์๋๋ค.
์ฐธ๊ณ :
์ฃผ์ด์ง ํ๋์ ๋ํด ์ ์ ๋ต ์ค ์ด๋ค ๊ฒ์ ์ ํํ ์ง์ ๋ํด์๋ types.go์patchStrategy
ํ๊ทธ์ ์ํด ์ ์ด๋๋ค.
ํ์
ํ๋์ ๋ํด patchStrategy
๊ฐ ์ง์ ๋์ง ์์ผ๋ฉด,
๋ฆฌ์คํธ๋ ๋์ฒด๋๋ค.๊ธฐ๋ณธ ํ๋๊ฐ
์ค๋ธ์ ํธ๊ฐ ์์ฑ๋ ๋ ๊ฐ์ด ์ง์ ๋์ง ์๋ ๊ฒฝ์ฐ, API ์๋ฒ๋ ํ์ฑ ๊ตฌ์ฑ ๋ด ํน์ ํ๋๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ ํ๋ค.
๋ค์์ ๋ํ๋ก์ด๋จผํธ์ ๋ํ ๊ตฌ์ฑ ํ์ผ์ด๋ค. ํ์ผ์๋ strategy
๊ฐ ์ง์ ๋์ง ์์๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
minReadySeconds: 5
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
kubectl apply
๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ๋ค.
kubectl apply -f https://k8s.io/examples/application/simple_deployment.yaml
kubectl get
์ ์ฌ์ฉํ์ฌ ํ์ฑ ๊ตฌ์ฑ์ ์ถ๋ ฅํ๋ค.
kubectl get -f https://k8s.io/examples/application/simple_deployment.yaml -o yaml
์ถ๋ ฅ์ API ์๋ฒ๊ฐ ํ์ฑ ๊ตฌ์ฑ ๋ด ์ฌ๋ฌ ํ๋๋ฅผ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ค์ ํ ๊ฒ์ ๋ณด์ฌ์ค๋ค. ์ด ํ๋๋ค์ ๊ตฌ์ฑ ํ์ผ์ ์ง์ ๋์ง ์์๋ค.
apiVersion: apps/v1
kind: Deployment
# ...
spec:
selector:
matchLabels:
app: nginx
minReadySeconds: 5
replicas: 1 # defaulted by apiserver
strategy:
rollingUpdate: # defaulted by apiserver - derived from strategy.type
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate # defaulted by apiserver
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
containers:
- image: nginx:1.14.2
imagePullPolicy: IfNotPresent # defaulted by apiserver
name: nginx
ports:
- containerPort: 80
protocol: TCP # defaulted by apiserver
resources: {} # defaulted by apiserver
terminationMessagePath: /dev/termination-log # defaulted by apiserver
dnsPolicy: ClusterFirst # defaulted by apiserver
restartPolicy: Always # defaulted by apiserver
securityContext: {} # defaulted by apiserver
terminationGracePeriodSeconds: 30 # defaulted by apiserver
# ...
ํจ์น ์์ฒญ์์, ํจ์น ์์ฒญ์ ๋ถ๋ถ์ผ๋ก์ ๋ช ์์ ์ผ๋ก ์ง์์ง์ง ์์ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ์ฒ๋ฆฌ๋ ํ๋๋ ๋ค์ ๊ธฐ๋ณธ์ผ๋ก ์ค์ ๋์ง ์๋๋ค. ์ด๊ฒ์ ๋ค๋ฅธ ํ๋์ ๋ํ ๊ฐ์ ๋ฐ๋ผ ๊ธฐ๋ณธ ์ฒ๋ฆฌ๋ ํ๋์ ๋ํด ์์ํ์ง ๋ชปํ ๋์์ ์ ๋ฐํ ์ ์๋ค. ๋ค๋ฅธ ํ๋๊ฐ ๋์ค์ ๋ณ๊ฒฝ๋๋ฉด, ๊ทธ๋ก๋ถํฐ ๊ธฐ๋ณธ ์ฒ๋ฆฌ๋ ๊ฒ์ด ๋ช ์์ ์ผ๋ก ์ง์์ง์ง ์์ ํ ์ ๋ฐ์ดํธ๋์ง ์์ ๊ฒ์ด๋ค.
์ด๋ฌํ ์ฌ์ ๋ก, ์๋ํ ๊ฐ์ด ์๋ฒ์ ๊ธฐ๋ณธ๊ฐ๊ณผ ์ผ์นํ๋๋ผ๋, ์๋ฒ์ ์ํด ๊ธฐ๋ณธ ์ฒ๋ฆฌ๋ ํน์ ํ๋๋ ๊ตฌ์ฑ ํ์ผ ๋ด ๋ช ์์ ์ผ๋ก ์ ์ํ ๊ฒ์ ๊ถ๊ณ ํ๋ค. ์ด๋ ๊ฒ ํ๋ฉด ์๋ฒ์ ์ํด ๋ค์ ๊ธฐ๋ณธ ์ฒ๋ฆฌ๋์ง ์๊ฒ ๋ ์ถฉ๋ํ๋ ๊ฐ์ ๋ณด๋ค ์ฝ๊ฒ ์ธ์ํ ์ ์๋๋ก ํด์ค๋ค.
Example:
# last-applied-configuration
spec:
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
# configuration file
spec:
strategy:
type: Recreate # updated value
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
# live configuration
spec:
strategy:
type: RollingUpdate # defaulted value
rollingUpdate: # defaulted value derived from type
maxSurge : 1
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
# result after merge - ERROR!
spec:
strategy:
type: Recreate # updated value: incompatible with rollingUpdate
rollingUpdate: # defaulted value: incompatible with "type: Recreate"
maxSurge : 1
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
์ค๋ช :
- ์ฌ์ฉ์๊ฐ
strategy.type
์ ์ ์ํ์ง ์๊ณ ๋ํ๋ก์ด๋จผํธ๋ฅผ ์์ฑํ๋ค. - ์๋ฒ๋
strategy.type
์RollingUpdate
๋ก ๊ธฐ๋ณธ ์ค์ ํ๊ณstrategy.rollingUpdate
๊ฐ์ ๊ธฐ๋ณธ ๊ฐ์ผ๋ก ์ฒ๋ฆฌํ๋ค. - ์ฌ์ฉ์๊ฐ
strategy.type
๋ฅผRecreate
๋ก ๋ณ๊ฒฝํ๋ค. ์๋ฒ์์ ํด๋น ๊ฐ์ด ์ญ์ ๋ ๊ฑฐ๋ผ ์์ํ์ง๋งstrategy.rollingUpdate
๊ฐ์ ๊ธฐ๋ณธ๊ฐ์ผ๋ก ๋จ์ ์๋ค.strategy.rollingUpdate
๊ฐ์ด ์ฒ์์ ๊ตฌ์ฑ ํ์ผ์์ ์ง์ ๋์๋ค๋ฉด, ์ด๊ฒ์ ์ญ์ ํด์ผ ํ๋ค๋ ๊ฒ์ด ๋ ๋ถ๋ช ํ์ ๊ฒ์ด๋ค. strategy.rollingUpdate
๊ฐ ์ง์์ง์ง ์์๊ธฐ ๋๋ฌธ์ ์ ์ฉ์ ์คํจํ๋ค.strategy.rollingupdate
ํ๋๋Recreate
์strategy.type
์ผ๋ก ์ ์๋ ์ ์๋ค.
๊ถ๊ณ : ์ด๋ค ํ๋๋ ์ค๋ธ์ ํธ ๊ตฌ์ฑ ํ์ผ ๋ด ๋ช ์์ ์ผ๋ก ์ ์๋ผ์ผ ํ๋ค.
- ๋ํ๋ก์ด๋จผํธ, ์คํ ์ดํธํ์ , ์ก, ๋ฐ๋ชฌ์ , ๋ ํ๋ฆฌ์นด์ ๋ฐ ๋ ํ๋ฆฌ์ผ์ด์ ์ปจํธ๋กค๋ฌ์ ๊ฐ์ ์ํฌ๋ก๋์ ๋ํ ์ ๋ ํฐ์ ํ๋ํ ํ๋ฆฟ ๋ ์ด๋ธ
- ๋ํ๋ก์ด๋จผํธ ๋กค์์ ์ ๋ต
์๋ฒ ๊ธฐ๋ณธ ํ๋ ๋๋ ๋ค๋ฅธ ์์ฑ์์ ์ํด ์ค์ ๋ ํ๋ ์ง์ฐ๋ ๋ฐฉ๋ฒ
๊ตฌ์ฑ ํ์ผ ๋ด ๋ํ๋์ง ์๋ ํ๋๋ ๊ทธ ๊ฐ์
null
๋ก ์ค์ ํ๊ณ ๋์ ๊ตฌ์ฑ ํ์ผ์ ์ ์ฉํจ์ผ๋ก์จ ์ง์์ง ์ ์๋ค.
์๋ฒ๊ฐ ๊ธฐ๋ณธ ๊ฐ์ ํ ๋นํ๋ ํ๋์ ๋ํด์, ์ด๋ ๋ค์ ๊ธฐ๋ณธ ๊ฐ์
ํ ๋นํ๋๋ก ํ๋ค.
๊ตฌ์ฑ ํ์ผ๊ณผ ์ง์ ๋ช ๋ นํ ์์ฑ์ ๊ฐ์ ํ๋ ์์ ๊ถ์ ๋ณ๊ฒฝ์ํค๋ ๋ฐฉ๋ฒ
๊ฐ๋ณ ์ค๋ธ์ ํธ ํ๋๋ฅผ ๋ณ๊ฒฝ์ํค๋ ๋ฐ ์ฌ์ฉํด์ผ ํ๋ ์ ์ผํ ๋ฐฉ๋ฒ์ ๋ค์๊ณผ ๊ฐ๋ค.
kubectl apply
๋ฅผ ์ฌ์ฉํ๋ค.- ๊ตฌ์ฑ ํ์ผ์ ์์ ํ์ง ์๊ณ ํ์ฑ ๊ตฌ์ฑ์ ์ง์ ์์ฑํ๋ค.
์๋ฅผ ๋ค์ด,
kubectl scale
์ ์ฌ์ฉํ๋ค.
์ง์ ๋ช ๋ นํ ์์ฑ์์์ ๊ตฌ์ฑ ํ์ผ๋ก ์์ ์ ๋ณ๊ฒฝํ๊ธฐ
๊ตฌ์ฑ ํ์ผ์ ํ๋๋ฅผ ์ถ๊ฐํ๋ค. ํด๋น ํ๋์ ๊ฒฝ์ฐ
kubectl apply
๋ฅผ ๊ฑฐ์น์ง ์๋ ํ์ฑ ๊ตฌ์ฑ์ ๋ํด ์ง์ ์
๋ฐ์ดํธ๋ฅผ ์ ์ฉํ์ง ์๋๋ค.
๊ตฌ์ฑ ํ์ผ์์ ์ง์ ๋ช ๋ นํ ์์ฑ์๋ก ์์ ์ ๋ณ๊ฒฝํ๊ธฐ
์ฟ ๋ฒ๋คํฐ์ค 1.5๋ก๋ถํฐ ๊ตฌ์ฑ ํ์ผ์์ ๋ช ๋ นํ ์์ฑ์๋ก ์์ ๊ถ์ ๋ณ๊ฒฝํ๋๋ฐ ์๋ ๋จ๊ณ ํ์ํ๋ค.
- ๊ตฌ์ฑ ํ์ผ์์ ํ๋๋ฅผ ์ ๊ฑฐํ๋ค.
- ํ์ฑ ์ค๋ธ์ ํธ ์์
kubectl.kubernetes.io/last-applied-configuration
์ด๋ ธํ ์ด์ ์์ ํ๋๋ฅผ ์ ๊ฑฐํ๋ค.
๊ด๋ฆฌ ๋ฐฉ๋ฒ ๋ณ๊ฒฝํ๊ธฐ
์ฟ ๋ฒ๋คํฐ์ค ์ค๋ธ์ ํธ๋ ํ ๋ฒ์ ์ค์ง ํ๋์ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ์ฌ ๊ด๋ฆฌ๋ผ์ผ ํ๋ค. ํ๋์ ๋ฐฉ๋ฒ์์ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ผ๋ก ์ ํํ๋ ๊ฒ์ ๊ฐ๋ฅํ๋, ์๋ ํ๋ก์ธ์ค์ด๋ค.
์ฐธ๊ณ :
์ ์ธํ ๊ด๋ฆฌ์ ํจ๊ป ๋ช ๋ นํ ์ญ์ ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๊ด์ฐฎ๋ค.๋ช ๋ นํ ์ปค๋งจ๋ ๊ด๋ฆฌ์์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ์ผ๋ก ์ด์ ํ๊ธฐ
๋ช ๋ นํ ์ปค๋งจ๋ ๊ด๋ฆฌ์์ ์ค๋ธ์ ํธ ๊ตฌ์ฑ์ผ๋ก ์ด์ ํ๋ ๊ฒ์ ์ฌ๋ฌ ์๋ ๋จ๊ณ๋ฅผ ํฌํจํ๋ค.
ํ์ฑ ์ค๋ธ์ ํธ๋ฅผ ๋ก์ปฌ ๊ตฌ์ฑ ํ์ผ๋ก ๋ด๋ณด๋ธ๋ค.
kubectl get <์ข ๋ฅ>/<์ด๋ฆ> -o yaml > <์ข ๋ฅ>_<์ด๋ฆ>.yaml
๊ตฌ์ฑ ํ์ผ์์ ์๋์ผ๋ก
status
ํ๋๋ฅผ ์ ๊ฑฐํ๋ค.์ฐธ๊ณ :
`kubectl apply` ๊ตฌ์ฑ ํ์ผ์ ์กด์ฌํ๋ค๊ณ ํ๋๋ผ๋ ์ํ ํ๋๊ฐ ์ ๋ฐ์ดํธ๋์ง ์๊ธฐ ๋๋ฌธ์, ์ด ๋จ๊ณ๋ ์ ํ์ ์ด๋ค.
์ค๋ธ์ ํธ์
kubectl.kubernetes.io/last-applied-configuration
์ด๋ ธํ ์ด์ ์ ์ค์ ํ๋ค.kubectl replace --save-config -f <์ข ๋ฅ>_<์ด๋ฆ>.yaml
์ค์ง ์ค๋ธ์ ํธ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด
kubectl apply
๋ฅผ ์ฌ์ฉํ๋๋ก ํ๋ก์ธ์ค๋ฅผ ๋ณ๊ฒฝํ๋ค.
๋ช ๋ นํ ์ค๋ธ์ ํธ ๊ตฌ์ฑ์์ ์ ์ธํ ์ค๋ธ์ ํธ ๊ตฌ์ฑ์ผ๋ก ์ด์ ํ๊ธฐ
์ค๋ธ์ ํธ์
kubectl.kubernetes.io/last-applied-configuration
์ด๋ ธํ ์ด์ ์ ์ค์ ํ๋ค.kubectl replace --save-config -f <์ข ๋ฅ>_<์ด๋ฆ>.yaml
์ค์ง ์ค๋ธ์ ํธ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํด
kubectl apply
๋ฅผ ์ฌ์ฉํ๋๋ก ํ๋ก์ธ์ค๋ฅผ ๋ณ๊ฒฝํ๋ค.
์ปจํธ๋กค๋ฌ ์ ๋ ํฐ์ ํ๋ํ ํ๋ฆฟ ๋ ์ด๋ธ ์ ์ํ๊ธฐ
๊ฒฝ๊ณ :
์ปจํธ๋กค๋ฌ์์ ์ ๋ ํฐ๋ฅผ ์ ๋ฐ์ดํธํ๋ ๊ฒ์ ์ถ์ฒ๋์ง ์๋๋ค.๊ถ๊ณ ๋๋ ์ ๊ทผ ๋ฐฉ๋ฒ์ ๋ค๋ฅธ ์๋ฏธ๋ก ์ ์๋ฏธ๋ฅผ ๊ฐ์ง์ง ์๊ณ ์ปจํธ๋กค๋ฌ์ ์ํด์๋ง ์ฌ์ฉ๋๋ ๋จ์ผ, ๋ถ๋ณ์ ํ๋ํ ํ๋ฆฟ ๋ ์ด๋ธ์ ์ ์ํ๋ ๊ฒ์ด๋ค.
์์:
selector:
matchLabels:
controller-selector: "apps/v1/deployment/nginx"
template:
metadata:
labels:
controller-selector: "apps/v1/deployment/nginx"