๐Ÿณ ํ˜„๋Œ€ ๊ฐœ๋ฐœ์ž๋ฅผ ๋Œ€ํ‘œํ•˜๋Š” Kubernetes๐Ÿณ

14473 ๋‹จ์–ด tutorialdevopskubernetesbeginners
์ด ๊ฐ•์ขŒ์—์„œ, ๋‚˜๋Š” ์ฝ”๋“œ๊ฐ€ ๋ฐ”๋€” ๋•Œ๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ๊ตฌ์ถ•ํ•˜์ง€ ์•Š๊ณ  ๋กœ์ปฌ ๋‹จ์ผ ๋…ธ๋“œ์ธ Kubernetes ์ง‘๋‹จ (์˜ˆ๋ฅผ ๋“ค์–ด microk8s) ์—์„œ ๋กœ์ปฌ ์ผ์ƒ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ์˜ˆ์‹œ ํ”„๋กœ์ ํŠธ๋ฅผ ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•  ๊ฒƒ์ด๋‹ค.

์„ ๊ฒฐ ์กฐ๊ฑด

  • microk8s
  • ์˜ ์ž‘์—… ๋ถ€๋ถ„ Kubernetes ์ง‘๋‹จ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค
  • microk8s.enable registry์„ ์‚ฌ์šฉํ•˜์—ฌ Microk8sdocker ๋“ฑ๋กํ‘œ ํ™œ์„ฑํ™”
  • Docker(microk8s์™€ ํ•จ๊ป˜ ์ œ๊ณต๋˜๊ฑฐ๋‚˜ here์—์„œ ์„ค์น˜)
  • (์˜ต์…˜) ๋กœ์ปฌ ์„ค์น˜ Python 3 ๋ฐ pip
  • ์ด ๊ฐ•์ขŒ๋Š” ๋กœ์ปฌ ์›Œํฌ์Šคํ…Œ์ด์…˜์— Kubernetes ํด๋Ÿฌ์Šคํ„ฐ๋ฅผ ์„ค์น˜ํ•˜๊ณ  ์‹คํ–‰ํ–ˆ์œผ๋ฉฐ CLI ๋ฐ ์ปจํ…Œ์ด๋„ˆ์— ๋Œ€ํ•ด ๊ธฐ๋ณธ์ ์œผ๋กœ ์•Œ๊ณ  ์žˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.๋กœ์ปฌ Kubernetes ํด๋Ÿฌ์Šคํ„ฐ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ ์œ„ ๋งํฌ์˜ ์„ค์น˜ ์ง€์นจ์„ ์ฐธ์กฐํ•˜์‹ญ์‹œ์˜ค.
    ์ฐธ๊ณ : ์ด ๊ฐ•์ขŒ์˜ ๋ชจ๋“  ์ฝ”๋“œ๋‚˜ ์„ค์ •์€ "์ƒ์‚ฐ ์ค€๋น„"๊ฐ€ ์•„๋‹™๋‹ˆ๋‹ค.
    ์ด์ „์— docker ๋˜๋Š” kubectl์ด ์—†์œผ๋ฉด microk8s.์„ ์ ‘๋‘์‚ฌ๋กœ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋„๋ก ๋ช…๋ น ๋ณ„์นญ์„ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
    sudo snap alias microk8s.docker docker
    sudo snap alias microk8s.kubectl kubectl
    

    ์ฟ ๋ฒ ๋ฅด๋‹ˆํ…Œ์Šค๋Š” ๋ฌด์—‡์ž…๋‹ˆ๊นŒ?


    Kubernetes๋Š” ์ž๋™ํ™” ์šฉ๊ธฐ์™€ ์šฉ๊ธฐํ™” ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์˜ ๋ฐฐ์น˜, ์„ค์ •, ํ™•์žฅ์— ์‚ฌ์šฉ๋˜๋Š” ํ˜„๋Œ€ํ™”๋œ ํ”Œ๋žซํผ์ž…๋‹ˆ๋‹ค.๊ธฐ๋ณธ์ ์œผ๋กœ Docker ํ”Œ๋žซํผ์— ๊ตฌ์ถ•๋˜์–ด ๊ฐœ๋ฐœ์ž์™€ ์‹œ์Šคํ…œ ๊ด€๋ฆฌ์ž์—๊ฒŒ ์œ ์—ฐํ•˜๊ณ  ๊ฐ•๋ ฅํ•œ ๋„๊ตฌ๋ฅผ ์ œ๊ณตํ•˜์—ฌ ์–ด๋– ํ•œ ๊ทœ๋ชจ์—์„œ๋“  ๊ทธ๋“ค์˜ ์„œ๋น„์Šค๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.์›Œํฌ์Šคํ…Œ์ด์…˜ ๊ทœ๋ชจ ํฌํ•จ๐Ÿ™‚

    ์ฒซ ๋ฒˆ์งธ ์ผ!


    ๋ชจ๋“  ๊ตฌ์„ฑ ๋ฐ ์ฝ”๋“œ๋Š” GitHub ํ”„๋กœ์ ํŠธ์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

    ์ฒดํ”„๋…ธ / ์ฟ ๋ฒ ํŠธ


    kubernetes ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ์„ค์ •ํ•˜๋Š” ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ


    ์ฟ ๋ฒ ํŠธ


    kubernetes ๊ฐœ๋ฐœ ํ™˜๊ฒฝ์„ ์„ค์ •ํ•˜๋Š” ๊ฐ„๋‹จํ•œ ํ”„๋กœ์ ํŠธ
    View on GitHub

    ์ž…๋ฌธ๐Ÿƒ๐Ÿ’จ


    ์ž, ์‹œ์ž‘ํ•  ์ค€๋น„ ๋์–ด์š”?์ปจํ…Œ์ด๋„ˆ์—์„œ ์‹คํ–‰๋˜๋Š” ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์ด ํ•„์š”ํ•˜๋ฏ€๋กœ Python์˜ Flask ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์„ ์ •์˜ํ•ฉ๋‹ˆ๋‹ค.
    # test_server.py
    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    def kube():
        return "Hello Kubernetes!"
    
    ์ด๊ฒƒ์€ ๋‹จ์ผ ๊ฒฝ๋กœ /์˜ ํ”Œ๋ผ์Šคํฌ ์‘์šฉ์„ ์ •์˜ํ–ˆ๋‹ค.์—ฌ๊ธฐ ๋ฌด์„œ์šด ๊ฑฐ ์—†์–ด!๐Ÿ‘พ
    ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ํ…Œ์ŠคํŠธํ•˜๋ ค๋ฉด Flask ์ข…์†์„ฑ์„ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.
    pip install flask
    
    ... ์‚ฌ์šฉ:
    FLASK_APP=test_server.py flask run
    
    ๊ทธ๋ฆฌ๊ณ  http://127.0.0.1:5000/ ๋ธŒ๋ผ์šฐ์ €๋ฅผ ์—ด์–ด ๊ฒฐ๊ณผ๋ฅผ ๋ณด์‹ญ์‹œ์˜ค.

    ๋ฉˆ์ถ”๋ž˜์š”.๐Ÿ“ฆ


    ๋‹ค์Œ์€ ์ƒˆ๋กœ์šด ์›น ์„œ๋น„์Šค์— Dockerfile์„ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.๋‚˜๋Š” Dockerfiles์— ๋Œ€ํ•ด ์–ด๋Š ์ •๋„ ์ต์ˆ™ํ•˜๋‹ค๊ณ  ๊ฐ€์ •ํ•  ๊ฒƒ์ด๊ธฐ ๋•Œ๋ฌธ์— ์ด ์ ์„ ์ƒ์„ธํ•˜๊ฒŒ ์†Œ๊ฐœํ•˜์ง€ ์•Š์„ ๊ฒƒ์ด๋‹ค.
    FROM python:3.6.7-alpine3.7
    
    RUN mkdir /app
    WORKDIR /app
    
    COPY ./requirements.txt /requirements.txt
    RUN pip install -r /requirements.txt
    
    COPY ./test_server.py /app/test_server.py
    
    ENV FLASK_APP=test_server.py
    ENV FLASK_ENV=development
    
    ENTRYPOINT [ "flask", "run", "--host=0.0.0.0" ]
    
    ํ˜„์žฌ ์šฐ๋ฆฌ๋Š” ์ฝ”๋“œ๋กœ ์ด๋ฏธ์ง€๋ฅผ ๊ตฌ์ถ•ํ•˜๊ณ  ํ‘œ์‹œํ•˜๋ฉฐ ๋“ฑ๋กํ‘œ๋กœ ์ „์†กํ•ด์•ผ ํ•œ๋‹ค.์ด ์‹คํ–‰์„ ์ˆ˜ํ–‰ํ•˜๋ ค๋ฉด:
    docker build -t localhost:32000/kubetest:v1.0.0 .
    docker push localhost:32000/kubetest:v1.0.0
    
    ์ฃผ์˜: ์‚ฌ์šฉํ•œ ์ฟ ๋ฒ ๋ฅด๋„ค์ธ  ๋ฒ„์ „์— ๋”ฐ๋ผ ์ด๋ฏธ์ง€ ์ด๋ฆ„์ด ๋‹ค๋ฅผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๋กœ์ปฌ ๋“ฑ๋กํ‘œ์˜ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์œผ๋กœ localhost:32000์„ ๋ฐ”๊พธ์‹ญ์‹œ์˜ค.
    ์ด ์ด๋ฏธ์ง€๋ฅผ ํ•œ ๋ฒˆ๋งŒ ๊ตฌ์ถ•ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. (์ƒˆ ์˜์กด ํ•ญ๋ชฉ์„ ์ถ”๊ฐ€ํ•˜์ง€ ์•Š์œผ๋ฉด) ๋‚˜์ค‘์— ์ˆ˜์ •๋œ ์ฝ”๋“œ๋ฅผ ์ด๋ฏธ์ง€์— ์ฃผ์ž…ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    ์žฌ๋ฏธ์žˆ๋Š” ์ผ์— ๊ด€ํ•ด์„œ...๐Ÿ˜


    ํ˜„์žฌ ์šฐ๋ฆฌ๋Š” Docker ๋ฏธ๋Ÿฌ๊ฐ€ ํ•˜๋‚˜ ์žˆ๋Š”๋ฐ, ๊ทธ ์•ˆ์—๋Š” ์šฐ๋ฆฌ์˜ ์ตœ์‹  ๋ฒ„์ „์˜ ์ฝ”๋“œ๊ฐ€ ์žˆ์œผ๋ฉฐ, ์šฐ๋ฆฌ์˜ ๋น›๋‚˜๋Š” ์ƒˆ ๊ทธ๋ฃน์—์„œ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค.๋ณดํ†ต ์ง€๊ธˆ, ๋‹น์‹ ์€ docker run์„ ๊ฐ€๋™ํ•˜๊ณ  ํ•˜๋ฃจ๋ฅผ ๋๋‚ผ ์ˆ˜ ์žˆ์ง€๋งŒ, ์šฐ๋ฆฌ๋Š” ๋” ์ž˜ํ•  ๊ฒƒ์ด๋‹ค.
    ์šฐ๋ฆฌ๋Š” ๋‘ ๊ฐ€์ง€ ์œ ํ˜•์˜ ์ž์›์„ ์ •์˜ํ•ด์„œ ์šฐ๋ฆฌ์˜ ์ƒˆ๋กœ์šด ์ด๋ฏธ์ง€๋ฅผ ์ง‘๋‹จ์—์„œ ์‹คํ–‰ํ•ด์•ผ ํ•œ๋‹ค. ํ•˜๋‚˜๋Š” Deployment์ด๊ณ , ๋‹ค๋ฅธ ํ•˜๋‚˜๋Š” Service์ด๋‹ค.๋งŒ์•ฝ ์ด์ „์— docker-compose์„ ์‚ฌ์šฉํ•œ ์ ์ด ์žˆ๋‹ค๋ฉด, ์ด๊ฒƒ์€ ๊ฐœ๋…์ ์œผ๋กœ ๋งค์šฐ ๋น„์Šทํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์•ฝ๊ฐ„ ์ต์ˆ™ํ•ด ๋ณด์ผ ๊ฒƒ์ด๋‹ค.Deployment์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ณด์ž…๋‹ˆ๋‹ค.
    # kubetest.yaml
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: kubetest
    spec:
      selector:
        matchLabels:
          app: kubetest
      template:
        metadata:
          labels:
            app: kubetest
        spec:
          containers:
          - name: kubetest
            image: localhost:32000/kubetest:v1.0.0
            ports:
            - containerPort: 5000
            imagePullPolicy: Always
    ...
    
    
    ์ด๊ฒƒ์€ ์šฐ๋ฆฌ๊ฐ€ ๋ฐฉ๊ธˆ ์ „์†กํ•œ docker ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ kubetest์ด๋ผ๋Š” ๊ธฐ๋ณธ ์„œ๋น„์Šค๋ฅผ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค.์ค‘์š”ํ•œ ๋น„ํŠธ๋Š” spec ๊ตฌ์กฐ์—์„œ kubetest์ด๋ผ๋Š” ์šฉ๊ธฐ ํ•ญ๋ชฉ์„ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ํ•ญ๋ชฉ์€ ์ด๋ฏธ์ง€ localhost:32000/kubetest:v1.0.0์„ ์‚ฌ์šฉํ•˜๊ณ  ํฌํŠธ 5000์„ ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค.๋ณด์ด๋‹คdockercompose์˜ service์ฒ˜๋Ÿผ.๐Ÿ˜„ ํ˜„์žฌ kubectl create -f kubetest.yaml์œผ๋กœpod๋ฅผ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. HTTP๋ฅผ ํ†ตํ•ดpod์— ์ ‘๊ทผํ•  ์ˆ˜ ์—†์ง€๋งŒ ๋‹น๋ถ„๊ฐ„ ๊ทธ๋Ÿฌ์ง€ ๋งˆ์‹ญ์‹œ์˜ค.
    Pod์ด Kubernetes ๋„คํŠธ์›Œํฌ ์™ธ๋ถ€์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋„๋ก Service์„ ์ •์˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.์ด๊ฒƒ์€ -p์˜ docker run ์˜ต์…˜ ๋˜๋Š” ports์˜ docker-compose.yaml ๋ถ€๋ถ„๊ณผ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.
    # kubetest.yaml
    ...
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: kubetest
      labels:
        app: kubetest
    spec:
      selector:
        app: kubetest
      ports:
      - name: http
        port: 5000
        protocol: TCP
      type: NodePort
    
    ์ฃผ์˜: ๊ฐ„๋‹จํ•˜๊ฒŒ ๋ณด๊ธฐ ์œ„ํ•ด์„œ, ๋‚˜๋Š” ๊ฐ™์€ ํŒŒ์ผ์— Deployment๊ณผ Service์˜ ์ •์˜๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค.
    ์ž, ์ด์ œ ์šฐ๋ฆฌ ์ง‘๋‹จ์—์„œ ๊ณ„์† ์„ค์ •ํ•˜์ž!
    noah@kamijou:/opt/kubetest$ kubectl apply -f kubetest.yaml
    deployment.apps/kubetest created
    service/kubetest created
    
    ๋‹ค์Œ ๊ณต์‹์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฒฐ๊ณผ pod์„ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    noah@kamijou:/opt/kubetest$ kubectl get pods
    NAME                        READY   STATUS    RESTARTS   AGE
    kubetest-574958d5fd-zpvn5   1/1     Running   0          15s
    
    ... ์„œ๋น„์Šค ์‚ฌ์šฉ:
    noah@kamijou:/opt/kubetest$ kubectl get svc
    NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
    kubernetes   ClusterIP   10.152.183.1     <none>        443/TCP          8d
    kubetest     NodePort    10.152.183.154   <none>        5000:31065/TCP   20s
    noah@kamijou:/opt/kubetest$
    
    ์„œ๋น„์Šค ๋ชฉ๋ก์˜ 5000:31065/TCP ๋ถ€๋ถ„์„ ์ฃผ์˜ํ•˜์‹ญ์‹œ์˜ค. 31065์€ ์›น ์„œ๋น„์Šค์— ์—ฐ๊ฒฐํ•˜๋Š” ํฌํŠธ์ž…๋‹ˆ๋‹ค.์ด์ œ ์ด๋ ‡๊ฒŒ ํ•ฉ์‹œ๋‹ค.
    noah@kamijou:/opt/kubetest$ curl -i localhost:31065
    HTTP/1.0 200 OK
    Content-Type: text/html; charset=utf-8
    Content-Length: 18
    Server: Werkzeug/0.14.1 Python/3.6.7
    Date: Wed, 12 Dec 2018 05:53:10 GMT
    
    Hello Kubernetes!
    
    ๊ฒฝํƒ„ํ–ˆ์–ด๐ŸŽŠ๐ŸŽ‰๐ŸŽˆ

    ... but wait, I was promised cookies being able to edit my code within the pod! ๐Ÿ˜ฃ How am I supposed to do that!?


    ์ง„์ •ํ•ด, ๊ทธ๋Ÿด ๊ฑฐ์•ผ!๐Ÿ˜…kubetest.yaml ํŒŒ์ผ๋กœ ๋Œ์•„๊ฐ€์„œ ๋ช‡ ์ค„์„ ์ถ”๊ฐ€ํ•ฉ์‹œ๋‹ค.
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: kubetest
    spec:
      selector:
        matchLabels:
          app: kubetest
      template:
        metadata:
          labels:
            app: kubetest
        spec:
          containers:
          - name: kubetest
            image: localhost:32000/kubetest:v1.0.0
            ports:
            - containerPort: 5000
            imagePullPolicy: Always
    +       volumeMounts:
    +         - mountPath: /app
    +           name: kubetest-volume
    +           readOnly: true
    +     volumes:
    +     - name: kubetest-volume
    +       hostPath:
    +         path: /home/noah/kubetest
    +         type: Directory
    
    
    ์—ฌ๊ธฐ์—๋Š” ํŒจํ‚ค์ง€๋ฅผ ํ•ด์ œํ•ด์•ผ ํ•  ์ ์ด ํ•˜๋‚˜ ์žˆ์ง€๋งŒ, ๋””๋ ‰ํ„ฐ๋ฆฌ ๊ธฐ๋ฐ˜ ํด๋” ๋งˆ์šดํŠธ๋ฅผ ๋งŒ๋“ค๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. -v /host/path:/container/path์˜ docker run ๋ฌธ๋ฒ•๊ณผ ์œ ์‚ฌํ•ฉ๋‹ˆ๋‹ค.Kubernetes์˜ ์ฒ˜๋ฆฌ ๋ฐฉ์‹์€ vanilla docker์™€ ์•ฝ๊ฐ„ ๋‹ค๋ฅด๊ธฐ ๋•Œ๋ฌธ์— ๋” ๋งŽ์€ ์ •๋ณด๋ฅผ ์•Œ๊ณ  ์‹ถ์œผ๋ฉด official documentation on persistent volumes์„ ๋ณด์‹ญ์‹œ์˜ค.
    ์ฐธ๊ณ : path ๋ฐ”์ดํŠธ์˜ ๊ฐ’์„ ๋ณ€๊ฒฝํ•˜์—ฌ test_server.py ํŒŒ์ผ์ด ์žˆ๋Š” ์œ„์น˜๋ฅผ ๊ฐ€๋ฆฌํ‚ค๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.์ด๊ฒƒ์€ ์ด ์—…๋ฌด์˜ ์ •์ƒ์ ์ธ ์ง„ํ–‰์— ๋งค์šฐ ์ค‘์š”ํ•˜๋‹ค.
    ๊ณ„์†ํ•˜์—ฌ kubectl apply -f kubetest.yaml์„ ๋‹ค์‹œ ์‹คํ–‰ํ•˜๊ณ  ๋ณผ๋ฅจ์œผ๋กœ ์—…๋ฐ์ดํŠธ ์šฉ๊ธฐ๋ฅผ ๋งˆ์šดํŠธํ•ฉ๋‹ˆ๋‹ค.
    noah@kamijou:~/kubetest$ kubectl apply -f kubetest.yaml
    deployment.apps/kubetest configured
    service/kubetest unchanged
    
    ๊ธฐ์ค‘๊ธฐ๊ฐ€ ์ด๋ฏธ ๊ฐ€๋™๋˜๊ณ  ๋‹ค์‹œ ์šดํ–‰๋˜์—ˆ๋Š”์ง€ ๊ฒ€์‚ฌํ•˜๋‹ค
    noah@kamijou:~/kubetest$ kubectl get pods
    NAME                        READY   STATUS    RESTARTS   AGE
    kubetest-58f7b7d957-cvdch   1/1     Running   0          63s
    
    ์ด ๋กœ๊ทธ๋“ค์€ ๋ชจ๋“ pod์˜ STDOUT๊ณผ STDERR์—์„œ ์ถ”์ถœ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.์ €ํฌ๋Š” kubetest ์„œ๋น„์Šค์—๋งŒ ๊ด€์‹ฌ์„ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
    noah@kamijou:~/kubetest$ kubectl logs svc/kubetest
     * Serving Flask app "test_server.py" (lazy loading)
     * Environment: development
     * Debug mode: on
     * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 124-402-077
    
    ๋ฉ‹์ง€๋‹ค, ์‘์šฉ ํ”„๋กœ๊ทธ๋žจ์ด ์—ฌ์ „ํžˆ ์‹คํ–‰๋˜๊ณ  ์žˆ๋‹ค.
    ๋งˆ์ง€๋ง‰์œผ๋กœ test_server.py์— ์ƒˆ๋กœ์šด ๋‹จ์ ์„ ์ถ”๊ฐ€ํ•ฉ์‹œ๋‹ค
    from flask import Flask
    app = Flask(__name__)
    
    @app.route("/")
    def kube():
        return "Hello Kubernetes!\n"
    
    [email protected]("/healthz")
    +def health():
    +    return "ok\n", 200
    
    ... ๋กœ๊ทธ๋ฅผ ๋‹ค์‹œ ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค.
    noah@kamijou:~/kubetest$ kubectl logs svc/kubetest
     * Serving Flask app "test_server.py" (lazy loading)
     * Environment: development
     * Debug mode: on
     * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 124-402-077
     * Detected change in '/app/test_server.py', reloading
     * Restarting with stat
     * Debugger is active!
     * Debugger PIN: 124-402-077
    
    Flask ์—์„œ test_ ์„œ๋ฒ„๊ฐ€ ๋ณ€๊ฒฝ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.py ํŒŒ์ผ์„ ์ž๋™์œผ๋กœ ๋‹ค์‹œ ๋ถˆ๋Ÿฌ์˜ต๋‹ˆ๋‹ค!
    ํฌํŠธ๊ฐ€ kubectl get svc์—์„œ ๋ณ€๊ฒฝ๋˜์ง€ ์•Š์•˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด ์ƒˆ ๋…ธ๋“œ์— ์ ‘๊ทผํ•ด ๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.
    noah@kamijou:~/kubetest$ curl -i localhost:30788/healthz
    HTTP/1.0 200 OK
    Content-Type: text/html; charset=utf-8
    Content-Length: 3
    Server: Werkzeug/0.14.1 Python/3.6.7
    Date: Wed, 12 Dec 2018 06:25:33 GMT
    
    ok
    
    ์˜ค, ์šฐ๋ฆฌ ๋๋‚ฌ์–ด!

    ์ฝ์–ด์ฃผ์…”์„œ ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!


    ๋‚˜๋Š” ๋„ค๊ฐ€ ๋‚˜์˜ ๋Œ“๊ธ€์ด ๋„ˆ์—๊ฒŒ ๋„์›€์ด ๋˜๋Š” ๊ฒƒ์„ ๋ฐœ๊ฒฌํ•˜๊ธธ ๋ฐ”๋ž€๋‹ค.๋งŒ์•ฝ ๋‹น์‹ ์—๊ฒŒ ์–ด๋–ค ๋ฌธ์ œ๊ฐ€ ์žˆ๋‹ค๋ฉด, ๋Œ“๊ธ€์— ๋ฉ”์‹œ์ง€๋ฅผ ๋‚จ๊ฒจ ์ฃผ์‹ญ์‹œ์˜ค. ๋‚˜๋Š” ๊ธฐ๊บผ์ด ๋‹น์‹ ์„ ๋„์šธ ๊ฒƒ์ž…๋‹ˆ๋‹ค.
    ์ด๊ฒƒ์€ ๋‚˜์˜ ์ฒซ ๋ฒˆ์งธ ๊ฒŒ์‹œ๋ฌผ์ด๊ธฐ ๋•Œ๋ฌธ์— ์–ด๋–ค ํ”ผ๋“œ๋ฐฑ๋„ ๋งค์šฐ ํ™˜์˜ํ•œ๋‹ค.๐Ÿ™‹โ€โ™‚๏ธ

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ