/
Service Discovery

Service Discovery

๊ฐœ์š”

Creating a single control-plane cluster with kubeadm | Testing a simple Nginx deployment ์—์„œ ์‹ค์Šตํ–ˆ๋˜ ๋‚ด์šฉ์—์„œ ์กฐ๊ธˆ ๋” ํ™•์žฅํ•˜์—ฌ ์ดํ•ดํ•˜์—ฌ ๋ณธ๋‹ค.

์—ฌ๊ธฐ์—์„œ ์‚ฌ์šฉ๋˜๋Š” config ํŒŒ์ผ์€ https://github.com/snetsystems/K8s-Objects/tree/master/tests ์— ์—…๋กœ๋“œ ๋˜์–ด ์žˆ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ pod๋Š” ๋‚ด๋ถ€ IP๊ฐ€ ํ• ๋‹น๋˜๋ฉฐ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผ์ด ๋ถˆ๊ฐ€๋Šฅ ํ•˜๋‹ค.
๋˜ํ•œ, Pod๋Š” ์–ธ์ œ๋“  ์ฃฝ์„ ์ˆ˜ ์žˆ๋‹ค๋Š” ๊ฒƒ์ด k8s์˜ ์ฒ ํ•™์ด๋ฉฐ pod๊ฐ€ ๋‹ค์‹œ ๋งŒ๋“ค์–ด ์งˆ ๊ฒฝ์šฐ pod์— ํ• ๋‹น๋œ IP๊ฐ€ ๋ณ€๊ฒฝ๋˜๊ฒŒ ๋œ๋‹ค. ํ•ด์„œ, ๋‚ด๋ถ€ Pod๊ฐ„ ํ†ต์‹ ์„ ์œ„ํ•ด์„œ๋„ ์ „ํ†ต์  ๋ฐฉ์‹์ธ IP addr์„ ํ†ตํ•œ ํ†ต์‹ ์œผ๋กœ๋Š” ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค.

์ฆ‰, Service discovery ๋ฐฉ์‹์œผ๋กœ ํ•ด๊ฒฐํ•˜๊ฒŒ ๋˜๋Š”๋ฐ, ์ฆ‰ ๋„๋ฉ”์ธ ๋ฐฉ์‹์œผ๋กœ ์ ‘๊ทผํ•œ๋‹ค.
๊ธฐ๋ณธ์ ์œผ๋กœ K8s๋ฅผ Initializeํ•˜๊ฒŒ ๋˜๋ฉด, coredns pod๊ฐ€ ์ƒ์„ฑ๋˜๋ฉฐ, ์ƒ์„ฑ๋œ ๋ชจ๋“  pod๋Š” ์—ฌ๊ธฐ ๋“ฑ๋ก๋˜์–ด ์•„๋ž˜์™€ ๊ฐ™์ด kube-dns ์„œ๋น„์Šค๋กœ dns ์ฟผ๋ฆฌํ•˜์—ฌ pod IP๋ฅผ ์•Œ์•„๋‚ธ ํ›„ ํ†ต์‹ ์„ ์—ฐ๊ฒฐํ•˜๊ฒŒ ๋œ๋‹ค.

$ kubectl get svc -A NAMESPACE NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE default kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 13d kube-system kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 13d

์ •๋ฆฌํ•˜์ž๋ฉด, ๊ฐ๊ฐ์˜ Pod๋Š” ์–ธ์ œ๋“  IP๊ฐ€ ๋ณ€๊ฒฝ๋  ์ˆ˜ ์žˆ์œผ๋ฉฐ ํ• ๋‹น๋œ IP๋Š” label selector๋กœ ์ง€์ •๋œ ์„œ๋น„์Šค๋ฅผ ํ†ตํ•ด ๋„๋ฉ”์ธ์œผ๋กœ ํ†ต์‹ ํ•˜๊ฒŒ ๋œ๋‹ค.

์ด์ œ ์•„๋ž˜ ์˜ˆ์ œ๋ฅผ ํ†ตํ•ด ์ดํ•ด๋ฅผ ๋†’์—ฌ๋ณด์ž.

์™ธ๋ถ€์—์„œ์˜ Pod ์ ‘์† ํ…Œ์ŠคํŠธ

nginx-deployment.yaml

ํŽธ์˜๋ฅผ ์œ„ํ•ด test namespace๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

apiVersion: v1 kind: Namespace metadata: name: test

nginx pod๋ฅผ 2๊ฐœ(replicas: 2)๋กœ ์ƒ์„ฑํ•œ๋‹ค.

apiVersion: apps/v1 kind: Deployment metadata: name: nginx namespace: test labels: app: nginx spec: replicas: 2 selector: matchLabels: app: nginx # ์ด label์„ Service object์— ์ง€์ •ํ•ด์•ผ ์„œ๋น„์Šค ๋„๋ฉ”์ธ์„ ํ†ตํ•œ ํ†ต์‹  ์—ฐ๊ฒฐ์ด ์ˆ˜ํ–‰๋จ. template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:stable-alpine3.17-slim ports: - containerPort: 80

๊ฐ๊ฐ์˜ ํƒ€์ž… ๋ณ„ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด,
ClusterIP, LB, NodePort ํƒ€์ž…์˜ ์„œ๋น„์Šค๋“ค์„ ๊ฐ๊ฐ ์ƒ์„ฑํ•˜์—ฌ ๋ณธ๋‹ค.

apiVersion: v1 kind: Service metadata: name: nginx-svc namespace: test spec: selector: app: nginx # ์œ„ matchLabels์— ์ง€์ •๋˜์—ˆ๋˜ label ์ง€์ •. type: ClusterIP ports: - name: http port: 80 # targetPort๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, targetPort=port ์„ค์ • ๊ฐ’. externalIPs: - 10.20.2.235 - 10.20.2.236 --- apiVersion: v1 kind: Service metadata: name: nginx-svc-lb namespace: test spec: selector: app: nginx # ์œ„ matchLabels์— ์ง€์ •๋˜์—ˆ๋˜ label ์ง€์ •. type: LoadBalancer ports: - name: http port: 8080 protocol: TCP targetPort: 80 #nodePort: 30036 # ์ƒ๋žต ์‹œ, ์ž„์˜๊ฐ’ ์ง€์ •๋จ.(30000-32767) externalIPs: - 10.20.2.235 - 10.20.2.236 --- apiVersion: v1 kind: Service metadata: name: nginx-svc-np namespace: test spec: selector: app: nginx # ์œ„ matchLabels์— ์ง€์ •๋˜์—ˆ๋˜ label ์ง€์ •. type: NodePort ports: - name: http port: 8081 protocol: TCP targetPort: 80 #nodePort: 30037 # ์ƒ๋žต ์‹œ, ์ž„์˜๊ฐ’ ์ง€์ •๋จ.(30000-32767) externalIPs: - 10.20.2.235 - 10.20.2.236

๋ชจ๋‘ ๋ฌธ์ œ์—†์ด ์ƒ์„ฑ๋œ๋‹ค๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์„ ๊ฒƒ์ด๋‹ค.

$ kubectl get po -n test -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-6c8cf466cd-mpfz4 1/1 Running 0 129m 10.244.1.15 test-k8s-worker01-centos8.snetsystems.com <none> <none> nginx-6c8cf466cd-xgbd7 1/1 Running 0 129m 10.244.2.14 test-k8s-worker02-centos8.snetsystems.com <none> <none>
$ kubectl get svc -n test NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE nginx-svc ClusterIP 10.105.132.127 10.20.2.235,10.20.2.236 80/TCP 45h nginx-svc-lb LoadBalancer 10.110.214.153 10.20.2.235,10.20.2.236 8080:31558/TCP 45h nginx-svc-np NodePort 10.97.16.76 10.20.2.235,10.20.2.236 8081:31511/TCP 45h

์œ„์—์„œ externalIPs๋ฅผ ๊ฐ๊ฐ ์ง€์ •ํ•˜์—ฌ ๋‘์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, ๊ฐ๊ฐ์˜ externalIPs๋ฅผ ํ†ตํ•˜์—ฌ ๊ฐ 80, 8080 ํฌํŠธ๋กœ ์ ‘์†์ด ๊ฐ€๋Šฅํ•˜๋‹ค.

๊ฐ€๋Šฅํ•œ ์กฐํ•ฉ์˜ curl ํ…Œ์ŠคํŠธ:

$ curl http://10.20.2.235 $ curl http://10.20.2.236 $ curl http://10.20.2.235:8080 $ curl http://10.20.2.236:8080 $ curl http://10.20.2.236:8081 $ curl http://10.20.2.236:8081 # ๋ฌผ๋ก  LoadBalancer์™€ NodePort Type ์„œ๋น„์Šค๋Š” nodeport๋กœ๋„ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค. $ curl http://10.20.2.235:31558 $ curl http://10.20.2.236:31558 $ curl http://10.20.2.235:31511 $ curl http://10.20.2.236:31511 <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> ... </html>

๋˜ํ•œ, ๊ฐ๊ฐ์˜ ์„œ๋น„์Šค๋Š” label selector app: nginx๋กœ ์ง€์ •ํ•˜์˜€๊ธฐ ๋•Œ๋ฌธ์— deploy๋กœ ์ƒ์„ฑํ•œ 2๊ฐœ์˜ nginx pod์— Load balancing ๋œ๋‹ค.

nginx-6c8cf466cd-xgbd7 ๋กœ๊ทธ:

10.244.2.1 - - [27/Jun/2023:08:30:40 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:31:58 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:14 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:18 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:19 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:20 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:20 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:40 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-"

nginx-6c8cf466cd-mpfz4 ๋กœ๊ทธ:

10.244.2.1 - - [27/Jun/2023:08:30:40 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:31:58 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:14 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:18 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:19 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:20 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:20 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-" 10.244.2.1 - - [27/Jun/2023:08:34:40 +0000] "GET / HTTP/1.1" 200 615 "-" "curl/7.61.1" "-"

๋‚ด๋ถ€ Pod๊ฐ„ ํ†ต์‹ 

์•ž์„œ ๊ฐœ์š”์—์„œ ์–ธ๊ธ‰ํ•˜์˜€๋“ฏ์ด, ๋ชจ๋“  Pod๋“ค์€ IP ๋Œ€์‹  ๋„๋ฉ”์ธ์œผ๋กœ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋‹ค.
์ฆ‰, Pod๊ฐ„ internal ํ†ต์‹ ์„ ์œ„ํ•ด์„œ๋Š” ์„œ๋น„์Šค๋ช…์œผ๋กœ accessํ•œ๋‹ค.

๊ด€๋ จ ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•ด test namespace์— ์•„๋ž˜์™€ ๊ฐ™์€ pod๋ฅผ ํ•˜๋‚˜ ์ƒ์„ฑํ•˜์ž.

apiVersion: apps/v1 kind: Deployment metadata: name: busybox namespace: test labels: app: busybox spec: replicas: 1 selector: matchLabels: app: busybox template: metadata: labels: app: busybox spec: containers: - name: busybox image: busybox command: - "/bin/sh" - "-c" - "sleep inf"

์ •์ƒ ์ƒ์„ฑ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์„ ๊ฒƒ์ด๋‹ค.

$ kubectl get po -n test -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES busybox-9ff887cc8-f5m46 1/1 Running 0 46h 10.244.1.16 test-k8s-worker01-centos8.snetsystems.com <none> <none> nginx-6c8cf466cd-mpfz4 1/1 Running 0 46h 10.244.1.15 test-k8s-worker01-centos8.snetsystems.com <none> <none> nginx-6c8cf466cd-xgbd7 1/1 Running 0 46h 10.244.2.14 test-k8s-worker02-centos8.snetsystems.com <none> <none>

busybox ๋‚ด๋ถ€ ์‰˜๋กœ ์ง„์ž…ํ•˜์—ฌ ๊ฐ pod ip๋กœ ์ ‘๊ทผํ•ด๋ณด๋ฉด, ๋‹น์—ฐํ•˜๊ฒŒ๋„ overlay networking์„ ํ†ตํ•ด ์ž˜ ์ ‘๊ทผ๋œ๋‹ค๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

# kubectl exec -n test -it busybox-9ff887cc8-f5m46 -- sh / # ping 10.244.2.14 PING 10.244.2.14 (10.244.2.14): 56 data bytes 64 bytes from 10.244.2.14: seq=0 ttl=62 time=1.243 ms 64 bytes from 10.244.2.14: seq=1 ttl=62 time=0.887 ms ^C --- 10.244.2.14 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.887/1.065/1.243 ms --- 10.244.2.15 ping statistics --- 7 packets transmitted, 0 packets received, 100% packet loss / # / # ping 10.244.1.15 PING 10.244.1.15 (10.244.1.15): 56 data bytes 64 bytes from 10.244.1.15: seq=0 ttl=64 time=0.322 ms ^C --- 10.244.1.15 ping statistics --- 1 packets transmitted, 1 packets received, 0% packet loss round-trip min/avg/max = 0.322/0.322/0.322 ms

CRI-O runtime์˜ ๊ฒฝ์šฐ ๋ณด์•ˆ ์ƒ pod ๋‚ด๋ถ€์—์„œ ping์ด ๋‚˜๊ฐ€๋Š” ๊ฒƒ์ด ๋ง‰ํ˜€์žˆ๋‹ค.
๊ฐ K8s ํด๋Ÿฌ์Šคํ„ฐ ๋…ธ๋“œ๋“ค์— /etc/crio/crio.conf.d/default_capabilities.conf๋ฅผ ์ƒ์„ฑํ•˜์—ฌ,
์•„๋ž˜ ์˜ต์…˜(โ€œNET_RAW")์„ ๋„ฃ์–ด์ค€๋‹ค.
[crio.runtime] default_capabilities = [ "CHOWN", "DAC_OVERRIDE", "FSETID", "FOWNER", "SETGID", "SETUID", "SETPCAP", "NET_BIND_SERVICE", "KILL", "NET_RAW", ]

์ดํ›„, systemctl restart crio๋ฅผ ํ†ตํ•ด crio๋ฅผ ์žฌ์‹œ์ž‘ํ•˜๊ณ ,
ping์„ ์‚ฌ์šฉํ•˜๋ ค๋Š” pod(โ€œbusyboxโ€)๋„ ์žฌ์ƒ์„ฑํ•ด์•ผ ํ•œ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ https://flavono123.github.io/posts/crio-capabilities-bug/ ์„ ์ฐธ๊ณ  ํ•˜๊ธฐ ๋ฐ”๋ž€๋‹ค.

๊ทธ๋Ÿฌ๋‚˜, IP๋Š” ์–ธ์ œ๋“  ๋ฐ”๋€” ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ, ์ด๋ฒˆ์—๋Š” ๋ฏธ๋ฆฌ ๋งŒ๋“ค์–ด๋‘” Service๋ฅผ ํ†ตํ•ด ์ ‘๊ทผํ•ด๋ณด๋„๋ก ํ•˜์ž.

๋‹น์—ฐํ•œ ๋ง์ด์ง€๋งŒ, Service๋Š” Pod๊ฐ€ ์•„๋‹ˆ๋ผ pod์˜ ํŠน์ • ํฌํŠธ๋ฅผ cluster ip์™€ ํฌํŠธ๋กœ ์—ฐ๊ฒฐํ•ด์ฃผ๋Š” ์ผ์ข…์˜ ์ •์ฑ…์ด๋ฏ€๋กœ, ์œ„์˜ ping์€ ๋„๋‹ฌํ•˜์ง€ ์•Š๋Š”๋‹ค.

์•„๋ž˜์™€ ๊ฐ™์ด telnet์„ ํ†ตํ•ด ์„œ๋น„์Šค ํฌํŠธ๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๋‹ค๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

/ # telnet nginx-svc 80 Connected to nginx-svc / # telnet nginx-svc-lb 8080 Connected to nginx-svc-lb # telnet nginx-svc-np 8081 Connected to nginx-svc-np

๊ทธ๋Ÿผ ์–ด๋–ป๊ฒŒ pod์—์„œ ์„œ๋น„์Šค ํฌํŠธ๋กœ ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ• ๊นŒ?

nslookup์„ ํ†ตํ•ด ๋„๋ฉ”์ธ ์ฐพ๊ธฐ๋ฅผ ํ•ด๋ณด์ž.

/ # nslookup nginx-svc Server: 10.96.0.10 Address: 10.96.0.10:53 ** server can't find nginx-svc.svc.cluster.local: NXDOMAIN Name: nginx-svc.test.svc.cluster.local Address: 10.105.132.127

์œ„์˜ 10.96.0.10:53์€ kube-dns ์„œ๋น„์Šค์˜ CLUSTER-IP์ด๋‹ค.(kubectl get svc -n kube-system ๋ช…๋ น์œผ๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.)

10.105.132.127๋Š” nginx-svc์„œ๋น„์Šค์˜ CLUSTER-IP์ด๋‹ค.

์ฆ‰, CLUSTER-IP: 10.105.132.127์— ๋Œ€ํ•˜์—ฌ nginx-svc.test.svc.cluster.local์œผ๋กœ ๋„๋ฉ”์ธ์ด ๋“ฑ๋ก๋˜์–ด ์žˆ์Œ์„ ์•Œ ์ˆ˜ ์žˆ์œผ๋ฉฐ, nginx-svc๋Š” label selector๋กœ ๊ฐ pod์™€ ์—ฐ๊ฒฐ๋œ๋‹ค๋Š” ๊ฒƒ์„ ์ถ”์ •ํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ์ด๋‹ค.

์ฐธ๊ณ ๋กœ, ๋‹ค๋ฅธ domain์˜ pod์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์„œ๋น„์Šค๋ช….๋„๋ฉ”์ธ๋ช…์œผ๋กœ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.

/ # telnet kube-dns.kube-system 53 Connected to kube-dns.kube-system Connection closed by foreign host

Headless Service

์œ„ Service ์˜ˆ์ œ์—์„œ๋Š” ํŽธ์˜์ƒ externalIPs๋ฅผ ๋ชจ๋‘ ํ• ๋‹นํ•˜์˜€๋‹ค.
ํ•˜์ง€๋งŒ,

  1. Pod ๊ฐ„ ํ†ต์‹  ์ฆ‰ ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด ํ†ต์‹ ๋งŒ์„ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๊ตณ์ด externalIPs๋ฅผ ํ• ๋‹นํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.

  2. ํด๋Ÿฌ์Šคํ„ฐ๋œ Pod๊ฐ€ 2๊ฐœ ์ด์ƒ์ด๊ณ , ์ด๋“ค pod๋“ค์— load balancing ํ•˜์—ฌ requestํ•  ํ•„์š”๊ฐ€ ์—†๋‹ค.

๋“ฑ์˜ ๊ฒฝ์šฐ, Headless ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•˜๋ฉด ๋˜๋Š”๋ฐ, ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด์—์„œ DNS ์ฟผ๋ฆฌ๋ฅผ ํ•˜๋ฉด, ์•ž ์žฅ์—์„œ ์‚ดํŽด๋ณธ CLUSTER-IP๊ฐ€ ํ• ๋‹น๋˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ํ•ด๋‹น Pod์˜ IP๋ฅผ ์ง์ ‘ ์ œ๊ณตํ•ด์ค€๋‹ค.

๋งŒ์•ฝ 2๊ฐœ ์ด์ƒ์˜ Pod๊ฐ€ seletor๋กœ ์—ฐ๊ฒฐ๋˜์–ด ์žˆ๋‹ค๋ฉด, ๋žœ๋คํ•œ ์ˆœ์„œ๋กœ ์ด ์„œ๋น„์Šค์— ์—ฐ๊ฒฐ๋œ ๋ชจ๋“  IP ๋ฆฌ์ŠคํŠธ๋ฅผ ๋ฆฌํ„ดํ•˜๊ฒŒ ๋œ๋‹ค. ๋ง๊ทธ๋Œ€๋กœ, DNS ์„œ๋ฒ„ ์—ญํ• ๋งŒ ์ˆ˜ํ–‰ํ•œ๋‹ค.

์ž์„ธํ•œ ๋‚ด์šฉ์€ ๊ตฌ๊ธ€ ๊ฒ€์ƒ‰ ๋“ฑ์„ ํ†ตํ•ด ์‚ดํŽด๋ณด๊ธฐ๋ฅผ ๋ฐ”๋ผ๋ฉฐ, ์•„๋ž˜์™€ ๊ฐ™์ด clusterIP: None์„ ๋ช…์‹œ์ ์œผ๋กœ ๋ถ™์—ฌ์ฃผ๋ฉด ๋œ๋‹ค.

apiVersion: v1 kind: Service metadata: name: nginx-svc namespace: test spec: selector: app: nginx # ์œ„ matchLabels์— ์ง€์ •๋˜์—ˆ๋˜ label ์ง€์ •. type: ClusterIP clusterIP: None ports: - name: http port: 80 # targetPort๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ, targetPort=port ์„ค์ • ๊ฐ’.

์ƒ์„ฑ ํ›„, ์•ž ์žฅ์˜ ๋‚ด์šฉ๋Œ€๋กœ nslookup ํ…Œ์ŠคํŠธ๋ฅผ ํ•ด๋ณด๋ฉด ์ดํ•ด๊ฐ€ ๋  ๊ฒƒ์ด๋‹ค.

์ •๋ฆฌ

์ด ์‹ค์Šต๋“ค์„ ํ†ตํ•ด ๋ชจ๋˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹œ์Šคํ…œ์„ ์–ด๋–ป๊ฒŒ K8s ์ƒ์— ๊ตฌ์ถ•ํ•  ๊ฒƒ ์ธ๊ฐ€์— ๋Œ€ํ•œ ํ†ต์ƒ์˜ ๊ฐœ๋…์„ ์•Œ์•„๋ณด์•˜๋‹ค.

๋‹ค์Œ์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์€ ์™„์„ฑ๋œ ํ˜•ํƒœ์˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋น„์Šค์˜ Server side๋ฅผ deploy ํ•ด๋ณผ ๊ฒƒ์ด๋‹ค.

ย 

Related content