๐๐ป ๋กค๋ง ์ ๋ฐ์ดํธ / Rolling Update
โ๏ธ ์ ํ๋ฆฌ์ผ์ด์
์ ๋ฌด์ค๋จ์ผ๋ก ์ ์ง์ ์ผ๋ก ์๋ก์ด ๋ฒ์ ์ผ๋ก ๊ต์ฒดํ๋ ๊ณผ์ ์ ์๋ฏธํฉ๋๋ค.
It refers to the process of gradually replacing an application with a new version without interruption.
๐๐ป ์ค์ผ์ผ๋ง / Scaling
โ๏ธ ์์คํ
์ด๋ ์ ํ๋ฆฌ์ผ์ด์
์์ ์์์ ์์ ๋๋ฆฌ๊ฑฐ๋ ์ค์ฌ์ ์ฒ๋ฆฌ ๋ฅ๋ ฅ์ด๋ ์ฑ๋ฅ์ ์กฐ์ ํ๋ ๊ฒ์ ์๋ฏธํฉ๋๋ค.
It refers to adjusting processing power or performance in a system or application by increasing or decreasing the amount of resources.
๐๐ป ClusterIP์ NodePort์ ์ฐจ์ด
Difference between ClusterIP and NodePort
โ๏ธ ClusterIP
— ๊ธฐ๋ณธ ์๋น์ค ํ์ ์ ๋๋ค. / This is the basic service type.
— ์ธ๋ถ์์ ์ง์ ์ ๊ทผํ ์ ์๊ณ , ํด๋ฌ์คํฐ ๋ด๋ถ ํต์ ์ฉ์ผ๋ก ์ฃผ๋ก ์ฌ์ฉ๋ฉ๋๋ค.
It cannot be accessed directly from the outside and is primarily used for internal cluster communication.
โ๏ธ NodePort
— ํด๋ฌ์คํฐ ๋ด๋ถ๋ฟ ์๋๋ผ, ๊ฐ ์์ปค ๋
ธ๋์์ ์ง์ ๋ ํฌํธ(30000 ~ 32767 ๋ฒ์)๋ฅผ ํตํด ์ธ๋ถ์์ ๋
ธ๋ IP์ ์ด ํฌํธ๋ฅผ ํตํด ์ ๊ทผ์ด ๊ฐ๋ฅํฉ๋๋ค.
In addition to within the cluster, external access is possible through the node IP and the designated port (range 30000 to 32767) on each worker node.
— ClusterIP๋ ํด๋ฌ์คํฐ ๋ด๋ถ ์ ์ฉ ๋คํธ์ํฌ๋ก ์๋น์ค์ ์ ๊ทผํ ๋, NodePort๋ ์ธ๋ถ์์๋(๋
ธ๋ IP + ์ง์ ํฌํธ๋ก) ์ ๊ทผ์ ๊ฐ๋ฅํ๊ฒ ํด์ฃผ๋ ์๋น์ค ํ์
์
๋๋ค.
ClusterIP is a service type that allows access to the service via a private network within the cluster, while NodePort enables access from the outside (via Node IP + specified port).
๐๐ป ์ ํ๋ฆฌ์ผ์ด์
ํ์ฅ(์ค์ผ์ผ๋ง) ๋ฐ ๋กค๋ง ์
๋ฐ์ดํธ
Application scaling and rolling updates
โ๏ธ nginx-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 1
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
— yamlํ์ผ ์ ์ฉ / Apply YAML file
kubectl apply -f nginx-deployment.yaml
โ๏ธ ์ ํ๋ฆฌ์ผ์ด์
ํ์ฅ (Replica ์ ์กฐ์ )
Application expansion (controlling the number of replicas)
— ํ์ฌ pod ์๊ฐ 1๊ฐ๋ฅผ(replicas: 1) 3๊ฐ๋ก ํ์ฅํฉ๋๋ค.
Expands the current pod count from 1 (replicas: 1) to 3.
kubectl scale deployment nginx-deployment --replicas=3
โ๏ธ ๋กค๋ง ์ ๋ฐ์ดํธ / rolling updates
— nginx1.23๋ฒ์ ์ผ๋ก ๊ต์ฒด / Replaced with nginx version 1.23
— deployment(nginx-deployment)์์ nginx๋ผ๋ ์ด๋ฆ์ ์ปจํ
์ด๋ ์ด๋ฏธ์ง๋ฅผ nginx:1.23์ผ๋ก ๊ต์ฒดํฉ๋๋ค.
Replace the container image named nginx in deployment(nginx-deployment) with nginx:1.23.
kubectl set image deployment/nginx-deployment nginx=nginx:1.23
— ์ ๋ฐ์ดํธ ์งํ์ํ ๋ณด๊ธฐ / View update progress
kubectl rollout status deployment/nginx-deployment
— ํ์ฌ ๋ฐฐํฌ(Deployment)์ ์ํ๋ฅผ ์ด์ ์ฑ๊ณต์ ์ด์๋ ๋ฒ์ ์ผ๋ก ๋๋๋ฆฌ๋ ๋กค๋ฐฑ ๋ช
๋ น์
๋๋ค.
This is a rollback command that reverts the current deployment state to a previously successful version.
kubectl rollout undo deployment/nginx-deployment
โ๏ธ ์ค์ ์์ / actual work
–์ปจํธ๋กค ํ๋ ์ธ์์ ๋์ปค์ด๋ฏธ์ง ๋ค์ด๋ก๋(nginx:1.23์ด ์๋ ๊ฒฝ์ฐ)
Download Docker image from the control plane (if nginx:1.23 is not available)
docker pull nginx:1.23
–๋ค์ด๋ก๋๋ ์ด๋ฏธ์ง ํ์ธ / Check downloaded images
(nginx:1.23 f5747a42e3ad 205MB 55.6MB )
MacBookAir nginx-test1 % docker images
i Info โ U In Use
IMAGE ID DISK USAGE CONTENT SIZE EXTRA
docker/desktop-cloud-provider-kind:v0.5.0 4ad59ce20658 574MB 150MB U
docker/desktop-containerd-registry-mirror:v0.0.3 179a9ea3ae47 48.8MB 15.5MB U
docker/desktop-kubernetes:kubernetes-v1.34.1-cni-v1.7.1-critools-v1.33.0-cri-dockerd-v0.3.20-1-debian 12d6673564e0 552MB 169MB
docker/desktop-storage-provisioner:v3.0 57d2b6ad1c6f 75.4MB 21.9MB
docker/desktop-vpnkit-controller:v4.0 bdaff3408b1c 50MB 10.7MB
envoyproxy/envoy:v1.36.4 08acc53db6f4 233MB 58.8MB
kindest/node:v1.31.1 cd224d8da58d 1.47GB 413MB
kindest/node:v1.35.1 05d7bcdefbda 1.26GB 346MB U
nginx:1.23 f5747a42e3ad 205MB 55.6MB
nginx:latest 6e23479198b9 258MB 64.2MB
registry.k8s.io/coredns/coredns:v1.11.3 9caabbf6238b 81.8MB 16.9MB
registry.k8s.io/coredns/coredns:v1.12.1 e8c262566636 95.8MB 20.4MB
registry.k8s.io/etcd:3.5.16-0 c6a9d11cc5c0 213MB 67.9MB
registry.k8s.io/etcd:3.6.4-0 e36c08168342 306MB 98.2MB
registry.k8s.io/kube-apiserver:v1.32.2 c47449f3e751 123MB 26.2MB
registry.k8s.io/kube-apiserver:v1.34.1 b9d7c117f8ac 112MB 24.5MB
registry.k8s.io/kube-controller-manager:v1.32.2 399aa50f4d13 114MB 24MB
registry.k8s.io/kube-controller-manager:v1.34.1 2bf47c1b01f5 95.5MB 20.6MB
registry.k8s.io/kube-proxy:v1.32.2 83c025f0faa6 128MB 27.4MB
registry.k8s.io/kube-proxy:v1.34.1 913cc83ca0b5 101MB 22.8MB
registry.k8s.io/kube-scheduler:v1.32.2 45710d74cfd5 90.1MB 18.9MB
registry.k8s.io/kube-scheduler:v1.34.1 6e9fbc4e25a5 69.6MB 15.7MB
registry.k8s.io/pause:3.10 ee6521f290b2 786kB 266kB
— ๋กค๋ง ์ ๋ฐ์ดํธ ์คํ / Run rolling update
kubectl set image deployment/nginx-deployment nginx=nginx:1.23
— ๋ชจ๋ pod์ nginx:1.23์ ์ ์ฉ๋๋์ง ํ์ธํ๊ธฐ(์ด๋ฏธ์ง ์ ์ฉ)
Check if nginx:1.23 has been applied to all pods (apply image)
MacBookAir nginx-test1 % kubectl set image deployment/nginx-deployment nginx=nginx:1.23
deployment.apps/nginx-deployment image updated
MacBookAir nginx-test1 % kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-deployment-7878ff98b4-597k4 1/1 Running 0 3s
nginx-deployment-7878ff98b4-mqm62 1/1 Running 0 7s
nginx-deployment-7878ff98b4-nwn9r 1/1 Running 0 5s
MacBookAir nginx-test1 % kubectl describe pod nginx-deployment-7878ff98b4-597k4
... ์ค๊ฐ ์๋ต / skipping the middle ...
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 41s default-scheduler Successfully assigned default/nginx-deployment-7878ff98b4-597k4 to desktop-worker
Normal Pulling 41s kubelet Pulling image "nginx:1.23"
Normal Pulled 41s kubelet Successfully pulled image "nginx:1.23" in 8ms (8ms including waiting). Image size: 55571911 bytes.
Normal Created 41s kubelet Container created
Normal Started 41s kubelet Container started
๐๐ป ์์ปค๋ ธ๋ ์ ์ ํ์ธ ํ๊ธฐ / Check worker node connection
โ๏ธ NodePort๋ก deployment ๋ ธ์ถํ๊ธฐ / Exposing a deployment via NodePort
MacBookAir nginx-test1 % kubectl expose deployment nginx-deployment --type=NodePort --port=80
โ๏ธ nodeIP ํ์ธํ๊ธฐ / Check nodeIP
MacBookAir ~ % kubectl get nodes -o wide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
desktop-control-plane Ready control-plane 28h v1.35.1 172.18.0.3 <none> Debian GNU/Linux 13 (trixie) 6.12.69-linuxkit containerd://2.2.1
desktop-worker Ready <none> 28h v1.35.1 172.18.0.6 <none> Debian GNU/Linux 13 (trixie) 6.12.69-linuxkit containerd://2.2.1
desktop-worker2 Ready <none> 28h v1.35.1 172.18.0.4 <none> Debian GNU/Linux 13 (trixie) 6.12.69-linuxkit containerd://2.2.1
— ์๋น์ค ์์ฑํ์ธ(ํฌํธ๋ฒํธ 32497 ํ์ธ)
Verify service creation (verify port number 32497)
MacBookAir nginx-test1 % kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 28h
nginx-deployment NodePort 10.96.49.237 <none> 80:32497/TCP 2m43s
— ์์ปค๋ ธ๋ ์ ์ / Worker node connection
# worker node 1
MacBookAir nginx-test1 % docker exec -it desktop-worker bash
# worker node 2
MacBookAir nginx-test1 % docker exec -it desktop-worker2 bash
— ์์ปค ๋ ธ๋์์ nginx์ ์ ์ํด ๋ณด๊ธฐ / Trying to access nginx from a worker node
root@desktop-worker:/# curl 172.18.0.6:32497
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
— ์์ปค ๋ ธ๋2๋ ์๋์ฒ๋ผ ์ ์ํฉ๋๋ค. / Worker Node 2 connects as follows.
# curl 172.18.0.4:32497
๐๐ป๋ธ๋ผ์ฐ์ ์ ์ํ๊ธฐ / Access browser
โ๏ธ ํฐ๋ฏธ๋์์ 8080ํฌํธ๋ก NodePort 80ํฌํธ์ ์ฐ๊ฒฐ
Connect NodePort 80 to port 8080 in the terminal
MacBookAir nginx-test1 % kubectl port-forward svc/nginx-deployment 8080:80
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
โ๏ธ ๋ธ๋ผ์ฐ์ ์์ localhost:8080์ผ๋ก ์ ์ํ๋ฉด “Welcome to nginx”ํ๋ฉด์ ๋ณผ ์ ์์ต๋๋ค.
If you access localhost:8080 in your browser, you can see the “Welcome to nginx” screen.