Information in this document may be out of date

This document has an older update date than the original, so the information it contains may be out of date. If you're able to read English, see the English version for the most up-to-date information: Use a Service to Access an Application in a Cluster

ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด ์„œ๋น„์Šค ์‚ฌ์šฉํ•˜๊ธฐ

์ด ๋ฌธ์„œ๋Š” ์™ธ๋ถ€ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์‹คํ–‰ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์„œ๋น„์Šค ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•œ๋‹ค. ์„œ๋น„์Šค๋Š” ์‹คํ–‰ ์ค‘์ธ ๋‘ ๊ฐœ์˜ ์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ–๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ๋กœ๋“œ ๋ฐธ๋Ÿฐ์‹ฑ์„ ์ œ๊ณตํ•œ๋‹ค.

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ํ•„์š”ํ•˜๊ณ , kubectl ์ปค๋งจ๋“œ-๋ผ์ธ ํˆด์ด ํด๋Ÿฌ์Šคํ„ฐ์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •๋˜์–ด ์žˆ์–ด์•ผ ํ•œ๋‹ค. ์ด ํŠœํ† ๋ฆฌ์–ผ์€ ์ปจํŠธ๋กค ํ”Œ๋ ˆ์ธ ํ˜ธ์ŠคํŠธ๊ฐ€ ์•„๋‹Œ ๋…ธ๋“œ๊ฐ€ ์ ์–ด๋„ 2๊ฐœ ํฌํ•จ๋œ ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค. ๋งŒ์•ฝ, ์•„์ง ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์ง€ ์•Š๋‹ค๋ฉด, minikube๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ƒ์„ฑํ•˜๊ฑฐ๋‚˜ ๋‹ค์Œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํ”Œ๋ ˆ์ด๊ทธ๋ผ์šด๋“œ ์ค‘ ํ•˜๋‚˜๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ชฉ์ 

  • Hello World ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ธ์Šคํ„ด์Šค ๋‘ ๊ฐœ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.
  • ๋…ธ๋“œ ํฌํŠธ๋ฅผ ๋…ธ์ถœํ•˜๋Š” ์„œ๋น„์Šค ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
  • ์‹คํ–‰ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ์ ‘๊ทผํ•˜๊ธฐ ์œ„ํ•ด ์„œ๋น„์Šค ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.

๋‘ ๊ฐœ์˜ ํŒŒ๋“œ์—์„œ ์‹คํ–‰ ์ค‘์ธ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์— ๋Œ€ํ•œ ์„œ๋น„์Šค ์ƒ์„ฑํ•˜๊ธฐ

๋‹ค์Œ์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””ํ”Œ๋กœ์ด๋จผํŠธ(Deployment) ์„ค์ • ํŒŒ์ผ์ด๋‹ค.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world
spec:
  selector:
    matchLabels:
      run: load-balancer-example
  replicas: 2
  template:
    metadata:
      labels:
        run: load-balancer-example
    spec:
      containers:
        - name: hello-world
          image: gcr.io/google-samples/node-hello:1.0
          ports:
            - containerPort: 8080
              protocol: TCP
  1. ํด๋Ÿฌ์Šคํ„ฐ ๋‚ด Hello World ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜์ž. ์œ„ ํŒŒ์ผ์„ ์‚ฌ์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์ƒ์„ฑํ•˜์ž.

    kubectl apply -f https://k8s.io/examples/service/access/hello-application.yaml
    

    ์•ž์˜ ๋ช…๋ น์€ ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์˜ค๋ธŒ์ ํŠธ์™€ ์—ฐ๊ด€๋œ ๋ ˆํ”Œ๋ฆฌ์นด์…‹(ReplicaSet) ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ๋ ˆํ”Œ๋ฆฌ์นด์…‹์€ ๋‘ ๊ฐœ์˜ ํŒŒ๋“œ๋ฅผ ๊ฐ–๊ณ , ๊ฐ๊ฐ์€ Hello World ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•œ๋‹ค.

  2. ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

    kubectl get deployments hello-world
    kubectl describe deployments hello-world
    
  3. ๋ ˆํ”Œ๋ฆฌ์นด์…‹ ์˜ค๋ธŒ์ ํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

    kubectl get replicasets
    kubectl describe replicasets
    
  4. ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ๋…ธ์ถœํ•˜๋Š” ์„œ๋น„์Šค ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

    kubectl expose deployment hello-world --type=NodePort --name=example-service
    
  5. ์„œ๋น„์Šค์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋ณด์—ฌ์ค€๋‹ค.

    kubectl describe services example-service
    

    ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    Name:                   example-service
    Namespace:              default
    Labels:                 run=load-balancer-example
    Annotations:            <none>
    Selector:               run=load-balancer-example
    Type:                   NodePort
    IP:                     10.32.0.16
    Port:                   <unset> 8080/TCP
    TargetPort:             8080/TCP
    NodePort:               <unset> 31496/TCP
    Endpoints:              10.200.1.4:8080,10.200.2.5:8080
    Session Affinity:       None
    Events:                 <none>
    

    ์„œ๋น„์Šค์˜ ๋…ธ๋“œํฌํŠธ(NodePort) ๊ฐ’์„ ๋ฉ”๋ชจํ•˜์ž. ์˜ˆ๋ฅผ ๋“ค์–ด, ์•ž์„  ๊ฒฐ๊ณผ์—์„œ, ๋…ธ๋“œํฌํŠธ ๊ฐ’์€ 31496์ด๋‹ค.

  6. Hello World ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰ ์ค‘์ธ ํŒŒ๋“œ๋ฅผ ๋‚˜์—ดํ•œ๋‹ค.

    kubectl get pods --selector="run=load-balancer-example" --output=wide
    

    ๊ฒฐ๊ณผ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

    NAME                           READY   STATUS    ...  IP           NODE
    hello-world-2895499144-bsbk5   1/1     Running   ...  10.200.1.4   worker1
    hello-world-2895499144-m1pwt   1/1     Running   ...  10.200.2.5   worker2
    
  7. Hello World ํŒŒ๋“œ๊ฐ€ ์‹คํ–‰ ์ค‘์ธ ๋…ธ๋“œ๋“ค ์ค‘ ํ•˜๋‚˜์˜ ๋…ธ๋“œ์— ๋Œ€ํ•ด ๊ณต์šฉ IP ์ฃผ์†Œ๋ฅผ ์–ป์ž. ์ด ์ฃผ์†Œ๋ฅผ ์–ป๋Š” ๋ฐฉ๋ฒ•์€ ์–ด๋–ป๊ฒŒ ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์„ค์น˜ํ–ˆ๋Š”์ง€์— ๋”ฐ๋ผ ๋‹ค๋ฅด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, Minikube๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, kubectl cluster-info๋ฅผ ์‹คํ–‰ํ•˜์—ฌ ๋…ธ๋“œ ์ฃผ์†Œ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค. Google Compute Engine ์ธ์Šคํ„ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด, gcloud compute instances list ๋ช…๋ น์–ด๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋…ธ๋“œ๋“ค์˜ ๊ณต์šฉ ์ฃผ์†Œ๋ฅผ ์•Œ ์ˆ˜ ์žˆ๋‹ค.

  8. ์„ ํƒํ•œ ๋…ธ๋“œ์—์„œ ๋…ธ๋“œ ํฌํŠธ์— ๋Œ€ํ•ด TCP ํ†ต์‹ ์„ ํ—ˆ์šฉํ•˜๋„๋ก ๋ฐฉํ™”๋ฒฝ ๊ทœ์น™์„ ์ƒ์„ฑํ•˜์ž. ์˜ˆ๋ฅผ ๋“ค์–ด, ์„œ๋น„์Šค์˜ ๋…ธ๋“œํฌํŠธ ๊ฐ’์ด 31568์ธ ๊ฒฝ์šฐ, 31568 ํฌํŠธ๋กœ TCP ํ†ต์‹ ์„ ํ—ˆ์šฉํ•˜๋„๋ก ๋ฐฉํ™”๋ฒฝ ๊ทœ์น™์„ ์ƒ์„ฑํ•˜์ž. ๋‹ค๋ฅธ ํด๋ผ์šฐ๋“œ ๊ณต๊ธ‰์ž๋Š” ๋ฐฉํ™”๋ฒฝ ๊ทœ์น™์„ ์„ค์ •ํ•˜๋Š” ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค.

  9. Hello World ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ ‘๊ทผ์„ ์œ„ํ•ด ๋…ธ๋“œ ์ฃผ์†Œ์™€ ๋…ธ๋“œ ํฌํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ž.

    curl http://<public-node-ip>:<node-port>
    

    <public-node-ip>๋Š” ๋…ธ๋“œ์˜ ๊ณต์šฉ IP ์ฃผ์†Œ์ด๊ณ , <node-port>๋Š” ์„œ๋น„์Šค์˜ ๋…ธ๋“œํฌํŠธ ๊ฐ’์ด๋‹ค. ์„ฑ๊ณต์ ์ธ ์š”์ฒญ์— ๋Œ€ํ•œ ์‘๋‹ต์€ hello ๋ฉ”์‹œ์ง€์ด๋‹ค.

    Hello Kubernetes!
    

์„œ๋น„์Šค ์„ค์ • ํŒŒ์ผ ์‚ฌ์šฉํ•˜๊ธฐ

kubectl expose๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋Œ€์‹ , ์„œ๋น„์Šค ์„ค์ • ํŒŒ์ผ์„ ์‚ฌ์šฉํ•ด ์„œ๋น„์Šค๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

์ •๋ฆฌํ•˜๊ธฐ

์„œ๋น„์Šค๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์ž.

kubectl delete services example-service

๋””ํ”Œ๋กœ์ด๋จผํŠธ, ๋ ˆํ”Œ๋ฆฌ์นด์…‹, Hello World ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด ์‹คํ–‰ ์ค‘์ธ ํŒŒ๋“œ๋ฅผ ์‚ญ์ œํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค์Œ ๋ช…๋ น์–ด๋ฅผ ์ž…๋ ฅํ•˜์ž.

kubectl delete deployment hello-world

๋‹ค์Œ ๋‚ด์šฉ

ํŠœํ† ๋ฆฌ์–ผ ์„œ๋น„์Šค์™€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์—ฐ๊ฒฐํ•˜๊ธฐ ๋”ฐ๋ผํ•˜๊ธฐ

์ตœ์ข… ์ˆ˜์ • March 26, 2023 at 1:12 AM PST: [ko] Update outdated files dev-1.26-ko.1 (M143 - M148) (eda4f1d533)