본문으로 건너뛰기

[Kubernetes] Scale App (kubectl scale)

kubectl scale과 kubectl edit로 Deployment의 replicas를 늘려 Pod를 Scale-out하고, 요청이 여러 Pod로 분산되는지 curl로 확인하는 방법을 정리합니다.

요약

  • kubectl scale deployment --replicas=5 flask-example-app으로 Pod를 1개에서 5개로 Scale-out할 수 있습니다.
  • kubectl edit deployment로 spec.replicas 값을 직접 수정해도 Pod 수를 바꿀 수 있습니다.
  • NodePort로 curl을 반복 호출하면 응답하는 Pod 이름이 바뀌어 여러 Pod가 요청을 나눠 처리하는 것을 확인할 수 있습니다.

목차

Scale APP

이 문서는 Pod 을 Scale-out 하는 방법에 대해 포함되어 있습니다.

Scale 개요

  • Before
  • After

Command 를 이용하여 Scale-out

기존에 1개의 Pod 으로 실행중이던 APP 을 5개의 Pod 으로 Scale-out 하도록 하겠습니다.

$ kubectl scale deployment --replicas=5 flask-example-app
  • Scale 확인
      $ kubectl get deployment
      NAME                READY   UP-TO-DATE   AVAILABLE   AGE
      flask-example-app   5/5     5            5           126m
    
  • Pod 확인
      $ kubectl get pod
      NAME                                READY   STATUS    RESTARTS   AGE
      flask-example-app-959c5f88d-k95wk   1/1     Running   0          127m
      flask-example-app-959c5f88d-rb4rv   1/1     Running   0          2m21s
      flask-example-app-959c5f88d-9kl5k   1/1     Running   0          2m21s
      flask-example-app-959c5f88d-b62j5   1/1     Running   0          2m21s
      flask-example-app-959c5f88d-fbjtl   1/1     Running   0          2m21s
    
  • 서비스 확인(Round-Robin)
      $ while true; do curl 192.168.200.110:32296; done
      $ while true; do curl <TEST-SERVER-IP>:<NODEPORT>; done   << TEST 환경에 맞게 수정합니다.  
    

    아래와 같이 Scale-out 되어 서비스 중인 것을 볼 수 있습니다.

      $ while true; do curl 192.168.200.110:32296; done
       Container LAB | POD Working : flask-example-app-959c5f88d-9kl5k | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-k95wk | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-b62j5 | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-9kl5k | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-b62j5 | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-rb4rv | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-9kl5k | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-b62j5 | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-9kl5k | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-b62j5 | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-k95wk | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-rb4rv | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-k95wk | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-rb4rv | v=1
       Container LAB | POD Working : flask-example-app-959c5f88d-9kl5k | v=1
      ...
    

edit 옵션을 이용하여 수정하는 방법

$ kubectl edit deployment flask-example-app
...
spec:
  progressDeadlineSeconds: 600
  replicas: 5                     << replicas 수정
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: flask-example-app
...

참고 문서

자주 묻는 질문

Kubernetes에서 Pod 개수를 늘리는 명령어는 무엇인가요?

kubectl scale deployment --replicas=5 flask-example-app처럼 --replicas로 원하는 개수를 지정합니다.

명령어 대신 YAML로 replicas를 바꿀 수 있나요?

가능합니다. kubectl edit deployment flask-example-app으로 열어 spec의 replicas 값을 수정하고 저장하면 됩니다.

Scale-out이 실제로 적용됐는지 어떻게 확인하나요?

kubectl get deployment에서 READY가 5/5인지, kubectl get pod에서 Pod 5개가 Running인지 확인합니다. while true; do curl <TEST-SERVER-IP>:<NODEPORT>; done으로 응답하는 Pod 이름이 바뀌는지도 볼 수 있습니다.