[Kubernetes]Docker Desktop+MultiNodes +Rolling Update+Scalling[MacOS]

👉🏻 롤링 업데이트 / 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.

Leave a Reply