1. PV, PVC
1-1. API ๋ก ํ์ผ ์์ฑ
http://192.168.56.30:31231/create-file-pod
http://192.168.56.30:31231/create-file-pv
- wmdaihnepr.txt, xhfwqtqaeo.txt ํ์ผ ์์ฑ
1-2. ํ์ผ ์์ฑ ํ์ธ
Continer ์์ ํด๋ ํ์ธ => wmdaihnepr.txt
Contianer ์๊ตฌ์ ์ฅ ํด๋ ํ์ธ => xhfwqtqaeo.txt
master node ํด๋ ํ์ธ => xhfwqtqaeo.txt
1-3. Pod ์ญ์
1-4. ํ์ผ ์กฐํ
http://192.168.56.30:31231/list-file-pod
http://192.168.56.30:31231/list-file-pv
๋ ํ์ผ ๋ชจ๋ ์กฐํ๋์ง ์์
1-5. hostPath ์ค์ ํ ๋ค์ ๋์
- name: files
hostPath:
path: /root/k8s-local-volume/1231
http://192.168.56.30:31231/list-file-pod
http://192.168.56.30:31231/list-file-pv
- list-file-pod ๋ ์กฐํ๋์ง ์์ง๋ง
- list-file-pv ๋ ํ์ผ๋ช ์ด ์กฐํ๋๋ค
2. Deployment
2-1. RollingUpdate ํ๊ธฐ
HPA minReplica ๋ฅผ 2๋ก ๋ฐ๊พธ๊ธฐ
kubectl patch -n anotherclass-123 hpa api-tester-1231-default -p '{"spec":{"minReplicas":2}}'
์ง์์ ์ผ๋ก Version ํธ์ถํ๊ธฐ
while true; do curl http://192.168.56.30:31231/version; sleep 2; echo ''; done;
์ด๋ฏธ์ง ์ ๋ฐ์ดํธ ์คํ
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v2.0.0
๋ฒ์ ์ด v1.0.0 ๊ณผ v.2.0.0 ์ด ํผ์ฉ๋์ด์ ๋ ธ์ถ๋จ
2-2. RollingUpdate (maxUnavailable: 0%, maxSurge: 100%) ํ๊ธฐ
maxUnavailable: 25% -> 0% # ์์
maxSurge: 25% -> 100% # ์์
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v1.0.0
- maxUnavailable : 0%, maxSurge : 100% ๋ก ํ๋ฉด Blue/Green ์ ๊ฐ๊น์ด ํจ๊ณผ
- ๋ ๋ฒ์ ์ด ๋์์ ํธ์ถ๋์ง ์๋๋ก ์ค์
๋ฒ์ v1.0.0 ๊ณผ v2.0.0 ์ด ํผ์ฉ๋์ด์ ๋ ธ์ถ๋์ง ์์
2-3. Recreate ํ๊ธฐ
strategy:
type: RollingUpdate -> Recreate # ์์
rollingUpdate: # ์ญ์
maxUnavailable: 0% # ์ญ์
maxSurge: 100% # ์ญ์
kubectl set image -n anotherclass-123 deployment/api-tester-1231 api-tester-1231=1pro/api-tester:v2.0.0
- ๋ฐ๋ก ๊ธฐ์กด Pod ๋ฅผ ์ญ์ ์ํค๋ ๋์์ ์ Pod 2๊ฐ๋ฅผ ๋ง๋ ๋ค
- ์ ๋ฐ์ดํธ ์ค ์๋น์ค ์ค๋จ
2-4. Rollback
kubectl rollout undo -n anotherclass-123 deployment/api-tester-1231
3. Service
3-1. Pod ๋ด๋ถ์์ Service ๋ช ์ผ๋ก API ํธ์ถ
3-2. Deployment์์ Pod์ ports ์ ์ฒด ์ญ์ , Service targetPort๋ฅผ http -> 8080์ผ๋ก ์์
containers:
- name: api-tester-1231
ports: // ์ญ์
- name: http // ์ญ์
containerPort: 8080 // ์ญ์
ports:
- port: 80
targetPort: http -> 8080 // ๋ณ๊ฒฝ
nodePort: 31231
์๋ก ๋ฌ Pod ๋ด๋ถ์์ Service ๋ช ์ผ๋ก API ํธ์ถ
์ ์์ ์ผ๋ก ํธ์ถ๋จ ๐โ๏ธ
4. HPA
4-1. ๋ถํ ๋ฐ์ & ๋ถํ ํ์ธ
๋ถํ ๋ฐ์
http://192.168.56.30:31231/cpu-load?min=3
๋ถํ ํ์ธ
6% -> 57 % -> 99% ๋ก ์ค๋ฆ
์ํ ์๋ณต ๋ฐฉ๋ฒ
// 1. hpa ์ญ์
kubectl delete -n anotherclass-123 hpa api-tester-1231-default
// 2. deployment replicas 2๋ก ๋ณ๊ฒฝ
kubectl scale -n anotherclass-123 deployment api-tester-1231 --replicas=2
// 3. hpa ๋ค์ ์์ฑ
kubectl apply -f - <<EOF
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
namespace: anotherclass-123
name: api-tester-1231-default
labels:
part-of: k8s-anotherclass
component: backend-server
name: api-tester
instance: api-tester-1231
version: 1.0.0
managed-by: dashboard
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: api-tester-1231
minReplicas: 2
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
behavior:
scaleUp:
stabilizationWindowSeconds: 120
EOF
93% -> 12% ๋จ์ด์ง
4-2. [behavior] ๋ฏธ์ฌ์ฉ์ผ๋ก ์ ์ฉ
spec:
behavior: # ์ญ์
scaleUp: # ์ญ์
stabilizationWindowSeconds: 120 # ์ญ์
๋ถํ ๋ฐ์์ํค๋ฉด ์์ฒญ๋๊ฒ ๋นจ๋ฆฌ ์ฆ๊ฐํจ
'๐ฑ ์ธํ๋ฐ > โ ์ฟ ๋ฒ๋คํฐ์ค ์ด๋๋ ํด๋์ค (์ง์ํธ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
(10) ์์ฝ๊ฒ ๋ฐ๋ธ์ต์ค ํ๊ฒฝ์ ๊ตฌ์ถํ๋ ๋ฐฉ๋ฒ (2) | 2025.06.10 |
---|---|
(9) ๋ฐ๋ธ์ต์ค ํ๋ฐฉ ์ ๋ฆฌ (8) | 2025.06.09 |
[๋ฏธ์ 3] Application ๊ธฐ๋ฅ์ผ๋ก ์ดํดํ๊ธฐ - Configmap, Secret > ์์ฉ๊ณผ์ (0) | 2025.06.08 |
[๋ฏธ์ 2] Application ๊ธฐ๋ฅ์ผ๋ก ์ดํดํ๊ธฐ - Probe > ์์ฉ๊ณผ์ (0) | 2025.06.08 |
(8) Component ๋์์ผ๋ก ์ดํดํ๊ธฐ (0) | 2025.06.08 |