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: Run a Stateless Application Using a Deployment

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

์ด ํŽ˜์ด์ง€์—์„œ๋Š” ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์„ค๋ช…ํ•œ๋‹ค.

๋ชฉ์ 

  • nginx ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์ƒ์„ฑํ•˜๊ธฐ
  • kubectl์„ ์‚ฌ์šฉํ•˜์—ฌ ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์ •๋ณด ๋‚˜์—ดํ•˜๊ธฐ
  • ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ

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

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

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ์„œ๋ฒ„์˜ ๋ฒ„์ „์€ ๋‹ค์Œ๊ณผ ๊ฐ™๊ฑฐ๋‚˜ ๋” ๋†’์•„์•ผ ํ•จ. ๋ฒ„์ „: v1.9.

๋ฒ„์ „ ํ™•์ธ์„ ์œ„ํ•ด์„œ, ๋‹ค์Œ ์ปค๋งจ๋“œ๋ฅผ ์‹คํ–‰ kubectl version.

nginx ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์ƒ์„ฑํ•˜๊ณ  ํƒ์ƒ‰ํ•˜๊ธฐ

์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์˜ค๋ธŒ์ ํŠธ๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— ๋Œ€ํ•œ ๋ช…์„ธ๋ฅผ YAML ํŒŒ์ผ์— ๊ธฐ์ˆ ํ•  ์ˆ˜ ์žˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด ์ด YAML ํŒŒ์ผ์€ nginx:1.14.2 ๋„์ปค ์ด๋ฏธ์ง€๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— ๋Œ€ํ•œ ๋ช…์„ธ๋ฅผ ๋‹ด๊ณ  ์žˆ๋‹ค.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2 # tells deployment to run 2 pods matching the template
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
  1. YAML ํŒŒ์ผ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.

     kubectl apply -f https://k8s.io/examples/application/deployment.yaml
    
  2. ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์‚ดํŽด๋ณธ๋‹ค.

     kubectl describe deployment nginx-deployment
    

    ์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•˜๋‹ค.

     Name:     nginx-deployment
     Namespace:    default
     CreationTimestamp:  Tue, 30 Aug 2016 18:11:37 -0700
     Labels:     app=nginx
     Annotations:    deployment.kubernetes.io/revision=1
     Selector:   app=nginx
     Replicas:   2 desired | 2 updated | 2 total | 2 available | 0 unavailable
     StrategyType:   RollingUpdate
     MinReadySeconds:  0
     RollingUpdateStrategy:  1 max unavailable, 1 max surge
     Pod Template:
       Labels:       app=nginx
       Containers:
        nginx:
         Image:              nginx:1.14.2
         Port:               80/TCP
         Environment:        <none>
         Mounts:             <none>
       Volumes:              <none>
     Conditions:
       Type          Status  Reason
       ----          ------  ------
       Available     True    MinimumReplicasAvailable
       Progressing   True    NewReplicaSetAvailable
     OldReplicaSets:   <none>
     NewReplicaSet:    nginx-deployment-1771418926 (2/2 replicas created)
     No events.
    
  3. ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— ์˜ํ•ด ์ƒ์„ฑ๋œ ํŒŒ๋“œ๋ฅผ ๋‚˜์—ดํ•œ๋‹ค.

     kubectl get pods -l app=nginx
    

    ์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•˜๋‹ค.

     NAME                                READY     STATUS    RESTARTS   AGE
     nginx-deployment-1771418926-7o5ns   1/1       Running   0          16h
     nginx-deployment-1771418926-r18az   1/1       Running   0          16h
    
  4. ํŒŒ๋“œ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์‚ดํŽด๋ณธ๋‹ค.

     kubectl describe pod <pod-name>
    

    <pod-name>์€ ํŒŒ๋“œ ์ค‘ ํ•˜๋‚˜์˜ ์ด๋ฆ„์ด๋‹ค.

๋””ํ”Œ๋กœ์ด๋จผํŠธ ์—…๋ฐ์ดํŠธํ•˜๊ธฐ

์ƒˆ YAML ํŒŒ์ผ์„ ์ ์šฉํ•˜์—ฌ ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์—…๋ฐ์ดํŠธํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด YAML ํŒŒ์ผ์€ nginx 1.16.1์„ ์‚ฌ์šฉํ•˜๋„๋ก ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์—…๋ฐ์ดํŠธํ•ด์•ผ ํ•จ์„ ๋ช…์‹œํ•˜๊ณ  ์žˆ๋‹ค.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16.1 # Update the version of nginx from 1.14.2 to 1.16.1
        ports:
        - containerPort: 80
  1. ์ƒˆ YAML ํŒŒ์ผ์„ ์ ์šฉํ•œ๋‹ค.

      kubectl apply -f https://k8s.io/examples/application/deployment-update.yaml
    
  2. ๋””ํ”Œ๋กœ์ด๋จผํŠธ๊ฐ€ ์ƒˆ ์ด๋ฆ„์œผ๋กœ ํŒŒ๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ด์ „ ํŒŒ๋“œ๋ฅผ ์‚ญ์ œํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•œ๋‹ค.

      kubectl get pods -l app=nginx
    

๋ ˆํ”Œ๋ฆฌ์นด ์ˆ˜๋ฅผ ๋Š˜๋ ค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ™•์žฅํ•˜๊ธฐ

์ƒˆ YAML ํŒŒ์ผ์„ ์ ์šฉํ•˜์—ฌ ๋””ํ”Œ๋กœ์ด๋จผํŠธ์˜ ํŒŒ๋“œ ์ˆ˜๋ฅผ ๋Š˜๋ฆด ์ˆ˜ ์žˆ๋‹ค. ์ด YAML ํŒŒ์ผ์€ replicas๋ฅผ 4๋กœ ์„ค์ •ํ•˜์—ฌ ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— 4๊ฐœ์˜ ํŒŒ๋“œ๊ฐ€ ์žˆ์–ด์•ผ ํ•จ์„ ๋ช…์‹œํ•˜๊ณ  ์žˆ๋‹ค.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 4 # Update the replicas from 2 to 4
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.16.1
        ports:
        - containerPort: 80
  1. ์ƒˆ YAML ํŒŒ์ผ์„ ์ ์šฉํ•œ๋‹ค.

     kubectl apply -f https://k8s.io/examples/application/deployment-scale.yaml
    
  2. ๋””ํ”Œ๋กœ์ด๋จผํŠธ์— 4๊ฐœ์˜ ํŒŒ๋“œ๊ฐ€ ์žˆ๋Š”์ง€ ํ™•์ธํ•œ๋‹ค.

     kubectl get pods -l app=nginx
    

    ์ถœ๋ ฅ์€ ๋‹ค์Œ๊ณผ ์œ ์‚ฌํ•˜๋‹ค.

     NAME                               READY     STATUS    RESTARTS   AGE
     nginx-deployment-148880595-4zdqq   1/1       Running   0          25s
     nginx-deployment-148880595-6zgi1   1/1       Running   0          25s
     nginx-deployment-148880595-fxcez   1/1       Running   0          2m
     nginx-deployment-148880595-rwovn   1/1       Running   0          2m
    

๋””ํ”Œ๋กœ์ด๋จผํŠธ ์‚ญ์ œํ•˜๊ธฐ

์ด๋ฆ„์œผ๋กœ ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์‚ญ์ œํ•œ๋‹ค.

kubectl delete deployment nginx-deployment

ReplicationControllers -- ์˜ˆ์ „ ๋ฐฉ์‹

์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๋ณต์ œํ•˜์—ฌ ์ƒ์„ฑํ•˜๋Š” ๊ธฐ๋ณธ์ ์ธ ๋ฐฉ๋ฒ•์€ ๋‚ด๋ถ€์ ์œผ๋กœ ๋ ˆํ”Œ๋ฆฌ์นด์…‹(ReplicaSet)์„ ํ™œ์šฉํ•˜๋Š” ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค์— ๋””ํ”Œ๋กœ์ด๋จผํŠธ ๋ฐ ๋ ˆํ”Œ๋ฆฌ์นด์…‹์ด ๋„์ž…๋˜๊ธฐ ์ „์—๋Š” ๋ ˆํ”Œ๋ฆฌ์ผ€์ด์…˜์ปจํŠธ๋กค๋Ÿฌ(ReplicationController)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ณต์ œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์„ฑํ–ˆ์—ˆ๋‹ค.

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

์ตœ์ข… ์ˆ˜์ • October 08, 2021 at 3:11 AM PST: Translate tasks/run-application/run-stateless-application-deployment.md in Korean (a2040433f6)