ํด๋น ๋ฌธ์์ ์ฟ ๋ฒ๋คํฐ์ค ๋ฒ์ : v1.31
Kubernetes v1.31 ๋ฌธ์๋ ๋ ์ด์ ์ ๊ทน์ ์ผ๋ก ๊ด๋ฆฌ๋์ง ์์. ํ์ฌ ๋ณด๊ณ ์๋ ๋ฌธ์๋ ์ ์ ์ค๋ ์ท์. ์ต์ ๋ฌธ์๋ฅผ ์ํด์๋, ๋ค์์ ์ฐธ๊ณ . ์ต์ ๋ฒ์ .
๋ํ๋ก์ด๋จผํธ(Deployment)๋ก ์คํ ์ดํธ๋ฆฌ์ค ์ ํ๋ฆฌ์ผ์ด์ ์คํํ๊ธฐ
์ด ํ์ด์ง์์๋ ์ฟ ๋ฒ๋คํฐ์ค ๋ํ๋ก์ด๋จผํธ ์ค๋ธ์ ํธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ๋ ๋ฐฉ๋ฒ์ ์ค๋ช ํ๋ค.
๋ชฉ์
- nginx ๋ํ๋ก์ด๋จผํธ ์์ฑํ๊ธฐ
- kubectl์ ์ฌ์ฉํ์ฌ ๋ํ๋ก์ด๋จผํธ ์ ๋ณด ๋์ดํ๊ธฐ
- ๋ํ๋ก์ด๋จผํธ ์ ๋ฐ์ดํธํ๊ธฐ
์์ํ๊ธฐ ์ ์
์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ๊ฐ ํ์ํ๊ณ , kubectl ์ปค๋งจ๋-๋ผ์ธ ํด์ด ํด๋ฌ์คํฐ์ ํต์ ํ ์ ์๋๋ก ์ค์ ๋์ด ์์ด์ผ ํ๋ค. ์ด ํํ ๋ฆฌ์ผ์ ์ปจํธ๋กค ํ๋ ์ธ ํธ์คํธ๊ฐ ์๋ ๋ ธ๋๊ฐ ์ ์ด๋ 2๊ฐ ํฌํจ๋ ํด๋ฌ์คํฐ์์ ์คํํ๋ ๊ฒ์ ์ถ์ฒํ๋ค. ๋ง์ฝ, ์์ง ํด๋ฌ์คํฐ๋ฅผ ๊ฐ์ง๊ณ ์์ง ์๋ค๋ฉด, minikube๋ฅผ ์ฌ์ฉํด์ ์์ฑํ๊ฑฐ๋ ๋ค์ ์ฟ ๋ฒ๋คํฐ์ค ํ๋ ์ด๊ทธ๋ผ์ด๋ ์ค ํ๋๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
์ฟ ๋ฒ๋คํฐ์ค ์๋ฒ์ ๋ฒ์ ์ ๋ค์๊ณผ ๊ฐ๊ฑฐ๋ ๋ ๋์์ผ ํจ. ๋ฒ์ : v1.9. ๋ฒ์ ํ์ธ์ ์ํด์, ๋ค์ ์ปค๋งจ๋๋ฅผ ์คํkubectl version
.
nginx ๋ํ๋ก์ด๋จผํธ ์์ฑํ๊ณ ํ์ํ๊ธฐ
์ฟ ๋ฒ๋คํฐ์ค ๋ํ๋ก์ด๋จผํธ ์ค๋ธ์ ํธ๋ฅผ ์์ฑํ์ฌ ์ ํ๋ฆฌ์ผ์ด์ ์ ์คํํ ์ ์์ผ๋ฉฐ, ๋ํ๋ก์ด๋จผํธ์ ๋ํ ๋ช ์ธ๋ฅผ YAML ํ์ผ์ ๊ธฐ์ ํ ์ ์๋ค. ์๋ฅผ ๋ค์ด ์ด YAML ํ์ผ์ nginx:1.14.2 ๋์ปค ์ด๋ฏธ์ง๋ฅผ ์คํํ๋ ๋ํ๋ก์ด๋จผํธ์ ๋ํ ๋ช ์ธ๋ฅผ ๋ด๊ณ ์๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2 # tells deployment to run 2 pods matching the template
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80
-
YAML ํ์ผ์ ๊ธฐ๋ฐ์ผ๋ก ๋ํ๋ก์ด๋จผํธ๋ฅผ ์์ฑํ๋ค.
kubectl apply -f https://k8s.io/examples/application/deployment.yaml
-
๋ํ๋ก์ด๋จผํธ์ ๋ํ ์ ๋ณด๋ฅผ ์ดํด๋ณธ๋ค.
kubectl describe deployment nginx-deployment
์ถ๋ ฅ์ ๋ค์๊ณผ ์ ์ฌํ๋ค.
Name: nginx-deployment Namespace: default CreationTimestamp: Tue, 30 Aug 2016 18:11:37 -0700 Labels: app=nginx Annotations: deployment.kubernetes.io/revision=1 Selector: app=nginx Replicas: 2 desired | 2 updated | 2 total | 2 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 1 max unavailable, 1 max surge Pod Template: Labels: app=nginx Containers: nginx: Image: nginx:1.14.2 Port: 80/TCP Environment: <none> Mounts: <none> Volumes: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable OldReplicaSets: <none> NewReplicaSet: nginx-deployment-1771418926 (2/2 replicas created) No events.
-
๋ํ๋ก์ด๋จผํธ์ ์ํด ์์ฑ๋ ํ๋๋ฅผ ๋์ดํ๋ค.
kubectl get pods -l app=nginx
์ถ๋ ฅ์ ๋ค์๊ณผ ์ ์ฌํ๋ค.
NAME READY STATUS RESTARTS AGE nginx-deployment-1771418926-7o5ns 1/1 Running 0 16h nginx-deployment-1771418926-r18az 1/1 Running 0 16h
-
ํ๋์ ๋ํ ์ ๋ณด๋ฅผ ์ดํด๋ณธ๋ค.
kubectl describe pod <pod-name>
<pod-name>
์ ํ๋ ์ค ํ๋์ ์ด๋ฆ์ด๋ค.
๋ํ๋ก์ด๋จผํธ ์ ๋ฐ์ดํธํ๊ธฐ
์ YAML ํ์ผ์ ์ ์ฉํ์ฌ ๋ํ๋ก์ด๋จผํธ๋ฅผ ์ ๋ฐ์ดํธํ ์ ์๋ค. ์ด YAML ํ์ผ์ nginx 1.16.1์ ์ฌ์ฉํ๋๋ก ๋ํ๋ก์ด๋จผํธ๋ฅผ ์ ๋ฐ์ดํธํด์ผ ํจ์ ๋ช ์ํ๊ณ ์๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 2
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1 # Update the version of nginx from 1.14.2 to 1.16.1
ports:
- containerPort: 80
-
์ YAML ํ์ผ์ ์ ์ฉํ๋ค.
kubectl apply -f https://k8s.io/examples/application/deployment-update.yaml
-
๋ํ๋ก์ด๋จผํธ๊ฐ ์ ์ด๋ฆ์ผ๋ก ํ๋๋ฅผ ์์ฑํ๊ณ ์ด์ ํ๋๋ฅผ ์ญ์ ํ๋ ๊ฒ์ ํ์ธํ๋ค.
kubectl get pods -l app=nginx
๋ ํ๋ฆฌ์นด ์๋ฅผ ๋๋ ค ์ ํ๋ฆฌ์ผ์ด์ ํ์ฅํ๊ธฐ
์ YAML ํ์ผ์ ์ ์ฉํ์ฌ ๋ํ๋ก์ด๋จผํธ์ ํ๋ ์๋ฅผ ๋๋ฆด ์ ์๋ค.
์ด YAML ํ์ผ์ replicas
๋ฅผ 4๋ก ์ค์ ํ์ฌ ๋ํ๋ก์ด๋จผํธ์
4๊ฐ์ ํ๋๊ฐ ์์ด์ผ ํจ์ ๋ช
์ํ๊ณ ์๋ค.
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 4 # Update the replicas from 2 to 4
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1
ports:
- containerPort: 80
-
์ YAML ํ์ผ์ ์ ์ฉํ๋ค.
kubectl apply -f https://k8s.io/examples/application/deployment-scale.yaml
-
๋ํ๋ก์ด๋จผํธ์ 4๊ฐ์ ํ๋๊ฐ ์๋์ง ํ์ธํ๋ค.
kubectl get pods -l app=nginx
์ถ๋ ฅ์ ๋ค์๊ณผ ์ ์ฌํ๋ค.
NAME READY STATUS RESTARTS AGE nginx-deployment-148880595-4zdqq 1/1 Running 0 25s nginx-deployment-148880595-6zgi1 1/1 Running 0 25s nginx-deployment-148880595-fxcez 1/1 Running 0 2m nginx-deployment-148880595-rwovn 1/1 Running 0 2m
๋ํ๋ก์ด๋จผํธ ์ญ์ ํ๊ธฐ
์ด๋ฆ์ผ๋ก ๋ํ๋ก์ด๋จผํธ๋ฅผ ์ญ์ ํ๋ค.
kubectl delete deployment nginx-deployment
ReplicationControllers -- ์์ ๋ฐฉ์
์ ํ๋ฆฌ์ผ์ด์ ์ ๋ณต์ ํ์ฌ ์์ฑํ๋ ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ์ ๋ด๋ถ์ ์ผ๋ก ๋ ํ๋ฆฌ์นด์ (ReplicaSet)์ ํ์ฉํ๋ ๋ํ๋ก์ด๋จผํธ๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ด๋ค. ์ฟ ๋ฒ๋คํฐ์ค์ ๋ํ๋ก์ด๋จผํธ ๋ฐ ๋ ํ๋ฆฌ์นด์ ์ด ๋์ ๋๊ธฐ ์ ์๋ ๋ ํ๋ฆฌ์ผ์ด์ ์ปจํธ๋กค๋ฌ(ReplicationController)๋ฅผ ์ฌ์ฉํ์ฌ ๋ณต์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๊ตฌ์ฑํ์๋ค.
๋ค์ ๋ด์ฉ
- ๋ํ๋ก์ด๋จผํธ ์ค๋ธ์ ํธ์ ๋ํด ๋ ๋ฐฐ์๋ณด๊ธฐ