- ์คํฝ์ค๋น
- ์ด๋ธ์
- python
- appetizer
- TSQL
- linux
- ํ๋ก๋ณด๋ ธ
- ์คํฝ๋ ํ
- SQL
- ํ์ด์ฌ
- ์กํ๊ณ
- Naver Cloud
- Java
- DB
- ํ์ด์
- ํ์ด์๊ณต๋ชจ์
- ์จ์ผ๋ํ
- ICT
- Spring
- JOBํ๊ณ
- ICT๋ฉํ ๋ง
- ict๊ณต๋ชจ์
- mysql
- ์๋์ด๋ ธ
- DATABASE
- API๋ง์ผํ๋ ์ด์ค
- ๋ฐ์ดํฐ๋ฒ ์ด์ค
- API MarketPlace ๊ธ๋ก๋ฒ ์ํฌํฐ์ฆ
- ์๋ฐ
- RaspberryPi
- Today
- Total
miinsun
[์ค์ต] ์ฟ ๋ฒ๋คํฐ์ค Controller ํ์ฉ ๋ณธ๋ฌธ
๐ป ์ค์ต ํ๊ฒฝ
OS : Ubuntu 20.04 LTS
RAM : <= 4GIB
CPU : <= 2Core
๐ ReplicaSet & ์ค์ผ์ผ ์์
๋ง์คํฐ์์ ๋ ธ๋ 'rs-controller.yaml' ํ ํ๋ฆฟ์ ์์ฑํ๋ค.
$ vim rs-controller.yaml
apiVersion: apps/v1
kind: ReplicaSet
metadata:
name: app-rs
spec:
replicas: 3
selector:
matchLabels:
app: webui
template:
metadata:
labels:
app: webui
spec:
containers:
- name: nginx
image: nginx:1.14
# ReplicaSet ์์ฑ
$ kubectl create -f rs-controller.yaml
# pod ํ์ธ
$ kubectl get pods
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
app-rs-ck4n7 1/1 Running 0 3s 10.36.0.1 node1.example.com <none> <none>
app-rs-j7mxm 1/1 Running 0 3s 10.44.0.2 node2.example.com <none> <none>
app-rs-v9dd8 1/1 Running 0 3s 10.44.0.1 node2.example.com <none> <none>
์์ฑ๋ Pod๋ฅผ ๋ณด๋ฉด Node1๊ณผ Node2์ ๋ชจ๋ app์ด ์์ฑ๋ ๊ฒ์ ํ์ธ ํ ์ ์๋ค.
โป label ์ฃผ์
replicaset์ label๋ก Pod๋ฅผ ์๋ณํจ
# pod์ ๋ผ๋ฒจ ํ์ธ
$ kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
app-rs-ck4n7 1/1 Running 0 117s app=webui
app-rs-j7mxm 1/1 Running 0 117s app=webui
app-rs-v9dd8 1/1 Running 0 117s app=webui
# label ์ ๊ฑฐ
$ kubectl label pod/app-rs-ck4n7 app-
pod/app-rs-ck4n7 unlabeled
# label ํ์ธ
# replica์ ํด๋นํ๋ ๋ผ๋ฒจ์ด 3๊ฐ์์ 2๊ฐ๋ก ์ค์๊ธฐ ๋๋ฌธ์, ๋ค์ 1๊ฐ๊ฐ ์์ฑ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
$ kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
app-rs-ck4n7 1/1 Running 0 3m51s <none>
app-rs-j7mxm 1/1 Running 0 3m51s app=webui
app-rs-thwjb 1/1 Running 0 8s app=webui
app-rs-v9dd8 1/1 Running 0 3m51s app=webui
# label ์ถ๊ฐ
$ kubectl label pod/app-rs-ck4n7 app=webui
pod/app-rs-ck4n7 labeled
# webui๋ฅผ ๊ฐ๋ ๋ผ๋ฒจ์ด 4๊ฐ๊ฐ ๋๊ธฐ ๋๋ฌธ์, ์์ฑ ์๊ฐ์ด ๊ฐ์ฅ ์งง์ app-rs-thwjb๊ฐ ์ ๊ฑฐ ๋์๋ค
root@master:~/test# kubectl get pod --show-labels
NAME READY STATUS RESTARTS AGE LABELS
app-rs-ck4n7 1/1 Running 0 7m20s app=webui
app-rs-j7mxm 1/1 Running 0 7m20s app=webui
app-rs-v9dd8 1/1 Running 0 7m20s app=webui
- ReplicaSet ScaleOut
๋์ ์ค์ธ pod์ scale์ ์์ ํ ์ ์๋ ๋ฐฉ๋ฒ์ edit, scale, apply๋ก 3๊ฐ์ง๊ฐ ์๋ค.
๊ทธ ์ค scale์ ์ด์ฉํด ๋์์ค์ธ replicaSet์ scale์ ์ ๋ฐ์ดํธ๋ฅผ ์งํํ์๋ค.
# scale์ ์ฌ์ฉํ update
$ kubectl scale rs app-rs --replicas=10
replicaset.apps/app-rs scaled
# pod๊ฐ 3๊ฐ์์ 10๊ฐ๋ก ๋์๋ค
$ kubectl get pods -o wide
NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES
app-rs-8m7m5 1/1 Running 0 18s 10.36.0.3 node1.example.com <none> <none>
app-rs-ck4n7 1/1 Running 0 10m 10.36.0.1 node1.example.com <none> <none>
app-rs-dw2f2 1/1 Running 0 18s 10.44.0.4 node2.example.com <none> <none>
app-rs-j7mxm 1/1 Running 0 10m 10.44.0.2 node2.example.com <none> <none>
app-rs-lgx8f 1/1 Running 0 18s 10.36.0.5 node1.example.com <none> <none>
app-rs-nmtc6 1/1 Running 0 18s 10.36.0.4 node1.example.com <none> <none>
app-rs-q7xtb 1/1 Running 0 18s 10.44.0.3 node2.example.com <none> <none>
app-rs-qf7pz 1/1 Running 0 18s 10.44.0.5 node2.example.com <none> <none>
app-rs-rgglj 1/1 Running 0 18s 10.36.0.2 node1.example.com <none> <none>
app-rs-v9dd8 1/1 Running 0 10m 10.44.0.1 node2.example.com <none> <none>
# nginx ์ ์
$ curl 10.36.0.3
<!DOCTYPE html>
<html>
...
- ReplicaSet delete
ํ์ฌ ๋์์ค์ธ pod๋ค์ replicaSet์ ์ข ์๋๊ธฐ ๋๋ฌธ์ replicaSet์ ์ญ์ ํ๋ฉด ๋ชจ๋ ๋ ธ๋๊ฐ ์ญ์ ๋๋ค.
๊ทธ๋ ์ง๋ง replicaSet์ ์ญ์ ํ ๋ --cascade ์ต์ ์ ์ถ๊ฐํ๋ฉด replicaSet๋ง์ ์ญ์ ํ ์ ์๋ค.
# Replicaset์ ์ญ์ ํ๋ฉด ์ฐ๊ด๋ ๋ชจ๋ pod๊ฐ ์ญ์ ๋๋ค.
$ kubectl delete rs app-rs
replicaset.apps "app-rs" deleted
$ kubectl get pod
No resources found in default namespace.
# cascade ์ต์
์ถ๊ฐ
$ kubectl delete rs app-rs --cascade=false
# ReplicaSet์ ์ญ์ ๋์์ง๋ง pod๋ ์ญ์ ๋์ง ์์๋ค
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
app-rs-8m7m5 1/1 Running 0 6m36s
app-rs-ck4n7 1/1 Running 0 17m
app-rs-dw2f2 1/1 Running 0 6m36s
app-rs-j7mxm 1/1 Running 0 17m
app-rs-v9dd8 1/1 Running 0 17m
๐ Deploy & RollingUpdate
๋ง์คํฐ์์ ๋ ธ๋ 'deploy-controller.yaml' ํ ํ๋ฆฟ์ ์์ฑํ๋ค.
$ vim deploy-controller.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-app
spec:
replicas: 5
selector:
matchLabels:
app: webui
template:
metadata:
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
# deploy ์์ฑ
$ kubectl create -f deploy-controller.yaml
deployment.apps/deploy-app created
# ์์ฑ๋ resource ํ์ธ
$ kubectl get po,rs,deploy
NAME READY STATUS RESTARTS AGE
pod/deploy-app-7944565747-2vh77 1/1 Running 0 17s
pod/deploy-app-7944565747-dcdgw 1/1 Running 0 17s
pod/deploy-app-7944565747-j7w4b 1/1 Running 0 17s
pod/deploy-app-7944565747-mr972 1/1 Running 0 17s
pod/deploy-app-7944565747-nnmct 1/1 Running 0 17s
NAME DESIRED CURRENT READY AGE
replicaset.apps/deploy-app-7944565747 5 5 5 17s
NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/deploy-app 5/5 5 5 17s
- RollingUpdate
nginx์ด๋ฏธ์ง๋ฅผ ๊ธฐ์กด 1.14์์ 1.15๋ก ์ ๊ทธ๋ ์ด๋ ํ๋ค.
# nginx ์ด๋ฏธ์ง upgrade
$ kubectl set image deploy deploy-app nginx-container=nginx:1.15 --record
deployment.apps/deploy-app image updated
# ๋ฐฐํฌ ์ค์ง
$ kubectl rollout pause deploy deploy-app
# ๋ฐฐํฌ ์ฌ์คํ
$ kubectl rollout resume deploy deploy-app
์๋ ์ฌ์ง์ ๋ณด๋ฉด ์๋ก์ด ๋ฒ์ ์ ์ปจํ ์ด๋๊ฐ ์๊ธฐ๊ณ , ๊ธฐ์กด์ ์ปจํ ์ด๋๋ ์ญ์ ๋๋ ๋ชจ์ต์ ํ์ธ ํ ์ ์๋ค.
- Update ๋ฒ์ ๊ด๋ฆฌ
์ง๊ธ๊น์ง ๋ฒ์ ์ ๋ฐ๊ฟจ๋ ๊ธฐ๋ก์ ๋ช ๋ น์ด๋ฅผ ํตํด ํ์ธํ ์ ์๋ค.
# ๋ฒ์ ๊ธฐ๋ก ํ์ธ
$ kubectl rollout history deployment deploy-app
deployment.apps/deploy-app
REVISION CHANGE-CAUSE
1 kubectl set image deploy deploy-app web=nginx:1.15 --record=true
2 kubectl set image deploy deploy-app nginx-container=nginx:1.15 --record=true
3 kubectl set image deploy deploy-app nginx-container=nginx:1.16 --record=true
4 kubectl set image deploy deploy-app nginx-container=nginx:1.17 --record=true
6 kubectl set image deploy deploy-app nginx-container=nginx:1.17 --record=true
7 kubectl set image deploy deploy-app nginx-container=nginx:1.18 --record=true
# ๋ฒ์ 1.15(2)๋ก ๋กค๋ฐฑ
$ kubectl rollout undo deployment deploy-app --to-revision=2
deployment.apps/deploy-app rolled back
# Pod ํ์ธ
$ kubectl describe pod deploy-app-78444bbfbb-4kq4w
...
Containers:
nginx-container:
Container ID: docker://7b738c9728153f190184394ef8353585e2904c33327509b424142e7af910ee3f
Image: nginx:1.15
Image ID: docker-pullable://nginx@sha256:23b4dcdf0d34d4a129755fc6f52e1c6e23bb34ea011b315d87e193033bcd1b68
Port: <none>
Host Port: <none>
State: Running
- Annotation์ ์ด์ฉํ history ๊ด๋ฆฌ
# nginx:1.14๋ก deploy template ์์ฑ
$ vim deploy-controller.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-app
annotations:
kubernetes.io/change-cause: version 1.14
spec:
replicas: 5
selector:
matchLabels:
app: webui
template:
metadata:
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.14
# deploy ์์ฑ
$ kubectl create -f deploy-controller.yaml
# nginx:1.15๋ก ์์
$ vim deploy-controller.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: deploy-app
annotations:
kubernetes.io/change-cause: version 1.15
spec:
replicas: 5
selector:
matchLabels:
app: webui
template:
metadata:
labels:
app: webui
spec:
containers:
- name: nginx-container
image: nginx:1.15
# ๋ฐ๋ ๋ด์ญ ์ ์ฉ
$ kubectl apply -f deploy-controller.yaml
# ๋ฒ์ ํ์ธ
$ kubectl rollout history deployment deploy-app
deployment.apps/deploy-app
REVISION CHANGE-CAUSE
1 version 1.14
2 version 1.15
'Infra > Kubernetes' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[์ค์ต] minikube๋ก ์ฑ ์ธ๋ถ๋ก ๋ ธ์ถํ๊ธฐ (0) | 2023.06.09 |
---|---|
[์ธํ ] minikube๋ก ์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ ๊ตฌ์ถํ๊ธฐ (0) | 2023.06.09 |
[์ด๋ก ] ์ฟ ๋ฒ๋คํฐ์ค Controller (0) | 2023.06.09 |
[์ค์ต] ์ฟ ๋ฒ๋คํฐ์ค Pod ํ์ฉ (0) | 2023.06.08 |
KUBERNETES _ ํด๋ฌ์คํฐ ์์ฑ (2) | 2021.11.24 |