[Kubernetes]Docker Desktop+Mutinodes (3 nodes)[MacOS]

๐Ÿ‘‰๐Ÿป ๋„์ปค ๋ฐ์Šคํฌํƒ‘์—์„œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ์ด์šฉํ•ด์„œ ๋ฉ€ํ‹ฐ ๋…ธ๋“œ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์— ๋Œ€ํ•œ ์„ค๋ช…์ž…๋‹ˆ๋‹ค.
This is an explanation of how to implement multi-nodes using Kubernetes on Docker Desktop.

๐Ÿ‘‰๐Ÿป ์ „์ฒด ๋…ธ๋“œ๋Š” ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ+์›Œ์ปค๋…ธ๋“œ2๊ฐœ๋กœ ๊ตฌ์„ฑํ•ฉ๋‹ˆ๋‹ค.
The entire node consists of a control plane + 2 worker nodes.

๐Ÿ‘‰๐Ÿป ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ / test environment

โœ”๏ธ ๋žจ์ด 8๊ธฐ๊ฐ€ ์ด์ƒ์ธ ํ™˜๊ฒฝ์—์„œ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ตฌ์„ฑํ•˜๊ธฐ๋ฅผ ์ถ”์ฒœํ•ฉ๋‹ˆ๋‹ค.
We recommend configuring the cluster in an environment with 8GB or more of RAM.

โœ”๏ธ MacOS ,M3, RAM 16GB

๐Ÿ‘‰๐Ÿป ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ฉ€ํ‹ฐ ๋…ธ๋“œ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
Install a Kubernetes multi-node cluster.

ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ / Create Cluster

โœ”๏ธ kind๋ฅผ ์„ ํƒํ•˜๊ณ  Node๋ฅผ 3๊ฐœ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.
Select kind and select 3 nodes.

โœ”๏ธ Create๋ฒ„ํŠผ์„ ํด๋ฆญํ•ด์„œ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
Click the Create button to create a cluster.

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ์ƒ์„ฑ / Create Kubernetes Cluster

โœ”๏ธ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ์„ค์น˜ / Kubernetees Cluster Installation

Kubernetees Cluster Installation

โœ”๏ธ ์„ค์น˜ ์ค‘ / installing

โœ”๏ธ ํด๋Ÿฌ์Šคํ„ฐ ์…‹ํŒ… ์™„๋ฃŒ / Cluster setup complete

โœ”๏ธ ๋…ธ๋“œ ํ™•์ธ / Check node status

— ์•„๋ž˜ ๊ทธ๋ฆผ์€ ๋„์ปค๋ฐ์Šคํฌํƒ‘์—์„œ ํ™•์ธํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ํ„ฐ๋ฏธ๋„์—์„œ๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
The image below shows the results verified in Docker Desktop. In the terminal, you can verify it as follows.

— ํด๋Ÿฌ์Šคํ„ฐ ๋ฒ„์ „์€ 1.35.1์ด๊ณ  ๋‚ด๋ถ€ ์•„์ดํ”ผ๋Š” 172.18.0.2 ~ 172.18.0.4๋ฒˆ๊นŒ์ง€ ๋ถ€์—ฌ๋œ๊ฒƒ์„ ํ™•์ธ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
You can confirm that the cluster version is 1.35.1 and internal IPs from 172.18.0.2 to 172.18.0.4 have been assigned.

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   10m   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>          10m   v1.35.1   172.18.0.2    <none>        Debian GNU/Linux 13 (trixie)   6.12.69-linuxkit   containerd://2.2.1
desktop-worker2         Ready    <none>          10m   v1.35.1   172.18.0.4    <none>        Debian GNU/Linux 13 (trixie)   6.12.69-linuxkit   containerd://2.2.1

— ๋„์ปค ๋ฐ์Šคํฌํƒ‘์—์„œ ๋…ธ๋“œ ์ƒํƒœ ํ™•์ธํ•œ ๊ฒฝ์šฐ
If you checked the node status in Docker Desktop

๐Ÿ‘‰๐Ÿป ์—ฌ๊ธฐ๊นŒ์ง€ ํ•˜๋ฉด ํด๋Ÿฌ์Šคํ„ฐ ์„ค์น˜๊ฐ€ ๋๋‚ฉ๋‹ˆ๋‹ค.
Once you get to this point, the cluster installation is complete.


๐Ÿ‘‰๐Ÿป ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์— Nginx๋ฅผ ์„ค์น˜ํ•ด ๋ด…๋‹ˆ๋‹ค.
Let’s try installing Nginx on Kubernetes.

โœ”๏ธ deployment ์ƒ์„ฑ / Create deployment

— deployment๋ฅผ ์ƒ์„ฑํ•˜๋ฉด pod์ด ํ•จ๊ป˜ ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.
When you create a deployment, a pod is created along with it.

— deployment๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.์ด๋ฆ„์€ my-app์ด๊ณ  image=nginx์ž…๋‹ˆ๋‹ค.
Create a deployment. The name is my-app and image=nginx.

MacBookAir ~ % kubectl create deployment my-app --image=nginx
deployment.apps/my-app created

— deployment๋ฅผ ํ™•์ธํ•˜๋ฉด ๋‹ค์Œ์ฒ˜๋Ÿผ ๋‚˜์˜ค๋ฉด ์ •์ƒ์ž…๋‹ˆ๋‹ค.
If you check the deployment and it appears as follows, it is normal.

MacBookAir ~ % kubectl get deployment
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
my-app   1/1     1            1           4m2s

— ๊ทธ๋Ÿฐ๋ฐ ์•„๋ž˜์ฒ˜๋Ÿผ deployment์™€ pod์„ ํ™•์ธํ•˜๋ฉด “READE 0/1”, “ImagePullBackOff”๋กœํ™•์ธ๋˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.
However, if you check the deployment and pod as shown below, there are cases where they are confirmed as “READE 0/1” and “ImagePullBackOff”.

MacBookAir ~ % kubectl get deployment
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
my-app   0/1     1            0           19s
MacBookAir ~ % kubectl get pods      
NAME                     READY   STATUS             RESTARTS   AGE
my-app-64b78bfff-7v7rc   0/1     ImagePullBackOff   0          23s

— ์œ„์˜ ๊ฒฝ์šฐ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด rollout restart๋กœ pod์„ ํ•˜๋‚˜์”ฉ ์ƒˆ๋กœ ๋งŒ๋“ค๊ณ  ๊ต์ฒดํ•ฉ๋‹ˆ๋‹ค.
If the above case occurs, create new pods one by one and replace them using a rollout restart.

MacBookAir ~ % kubectl rollout restart deployment my-app

โญ๏ธ pod์ƒ์ œ์ •๋ณด ๋ณด๊ธฐ / View Pod Information

MacBookAir ~ % kubectl describe pod my-app-64b78bfff-7v7rc

— ๋‹ค์‹œ deployment์ •๋ณด๋ฅผ ํ™•์ธํ•˜๋ฉด ์•„๋ž˜์ฒ˜๋Ÿผ ๋‚˜์˜ต๋‹ˆ๋‹ค.
If you check the deployment information again, it appears as shown below.

MacBookAir ~ % kubectl get deployment
NAME     READY   UP-TO-DATE   AVAILABLE   AGE
my-app   1/1     1            1           4m2s

๐Ÿ‘‰๐Ÿป deployment๋ฅผ ์™ธ๋ถ€์— ๋…ธ์ถœ ํ•˜๋„๋ก ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.
Create a service to expose the deployment externally.

— ์„œ๋น„์Šค์˜ ์ข…๋ฅ˜๋ฅผ NodePort๋กœ ์„ค์ •ํ•˜๊ณ  ์„œ๋น„์ŠคํฌํŠธ๋Š” 80๋ฒˆ์œผ๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
Set the service type to NodePort and the service port to 80.

— ๋ชจ๋“  ์›Œ์ปค ๋…ธ๋“œ์˜ ํŠน์ • ํฌํŠธ(์˜ˆ: 31515)๋ฅผ ๊ฐœ๋ฐฉํ•˜์—ฌ, “๋…ธ๋“œ IP:ํฌํŠธ” ์ฃผ์†Œ๋กœ ์ ‘์†ํ•˜๋ฉด ํ•ด๋‹น Pod๋กœ ์—ฐ๊ฒฐํ•ด ์ค๋‹ˆ๋‹ค.
By opening a specific port (e.g., 31515) on all worker nodes, connecting to the corresponding Pod via the “node IP:port” address will connect you.

— ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋Š” ๋ณดํ†ต 30000~32767 ์‚ฌ์ด์˜ ํฌํŠธ ์ค‘ ํ•˜๋‚˜๋ฅผ ๋ฌด์ž‘์œ„๋กœ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.
Kubernetes usually assigns one of the ports between 30000 and 32767 randomly.

MacBookAir ~ % kubectl expose deployment my-app --type=NodePort --port=80

— ์„œ๋น„์Šค๊ฐ€ ์ œ๋Œ€๋กœ ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.
Check if the service was created properly.

MacBookAir ~ % kubectl get svc
NAME         TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes   ClusterIP   10.96.0.1       <none>        443/TCP        9m
my-app       NodePort    10.96.177.193   <none>        80:31515/TCP   37s

๐Ÿ‘‰๐Ÿป ์›Œํฌ ๋‚ด๋ถ€์—์„œ nginx์ ‘์†ํ…Œ์ŠคํŠธ / Nginx connection test inside the workspace

— ์›Œ์ปค ๋…ธ๋“œ์— ์ ‘์†ํ•˜๊ธฐ / Connect to the worker node

-MacBookAir ~ % docker exec -it desktop-worker bash

— ์›Œ์ปค ๋…ธ๋“œ2์— ์ ‘์†ํ•˜๊ธฐ / Connect to Worker Node 2

-MacBookAir ~ % docker exec -it desktop-worker2 bash

— ์›Œ์ปค ๋…ธ๋“œ ๋‚ด๋ถ€์—์„œ ํ…Œ์ŠคํŠธํ•˜๊ธฐ(curl localhost:31515 ๋˜๋Š” curl 172.18.0.2:31515)
Testing inside a worker node (curl localhost:31515 or curl 172.18.0.2:31515)

— ์›Œ์ปค๋…ธ๋“œ2 ๋‚ด๋ถ€์—์„œ ํ…Œ์ŠคํŠธ ํ•  ๊ฒฝ์šฐ ์•„์ดํ”ผ ์ฃผ์†Œ๋Š” curl 172.18.0.4:31515 ์ž…๋‹ˆ๋‹ค.
When testing inside Worker Node 2, the IP address is curl 172.18.0.4:31515.

root@desktop-worker:/# curl localhost:31515
<!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, nginx is successfully installed and working.
Further configuration is required for the web server, reverse proxy, 
API gateway, load balancer, content cache, or other features.</p>

<p>For online documentation and support please refer to
<a href="https://nginx.org/">nginx.org</a>.<br/>
To engage with the community please visit
<a href="https://community.nginx.org/">community.nginx.org</a>.<br/>
For enterprise grade support, professional services, additional 
security features and capabilities please refer to
<a href="https://f5.com/nginx">f5.com/nginx</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
root@desktop-worker:/# exit
exit

— ๋…ธ๋“œ ์•„์ดํ”ผ ์ฃผ์†Œ ํ™•์ธ ํ•˜๊ธฐ / Checking Node IP Address

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   10m   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>          10m   v1.35.1   172.18.0.2    <none>        Debian GNU/Linux 13 (trixie)   6.12.69-linuxkit   containerd://2.2.1
desktop-worker2         Ready    <none>          10m   v1.35.1   172.18.0.4    <none>        Debian GNU/Linux 13 (trixie)   6.12.69-linuxkit   containerd://2.2.1

๐Ÿ‘‰๐Ÿป๋ธŒ๋ผ์šฐ์ € ์ ‘์†ํ•˜๊ธฐ / Access browser

— ๋ธŒ๋ผ์šฐ์ €์—์„œ 8080๋ฒˆ์œผ๋กœ ์ ‘์†ํ• ๋•Œ my-app์˜ 80๋ฒˆ์„œ๋น„์Šค์— ์ ‘์†์„ค์ •
Connection settings for the 80-service in my-app when accessing 8080 from the browser

MacBookAir ~ % kubectl port-forward svc/my-app 8080:80

Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80
Handling connection for 8080

— ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ ‘์†ํ•˜๊ธฐ / Access from browser

๐Ÿ‘‰๐Ÿป ํด๋Ÿฌ์Šคํ„ฐ ์…‹ํŒ… ์‚ญ์ œ / Delete cluster settings

MacBookAir ~ % kubectl delete service my-app
MacBookAir ~ % kubectl delete deployment my-app

Leave a Reply