본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Kong Gateway 블루/그린 업그레이드

원문 보기 위키 갱신

Kong Gateway 블루/그린 업그레이드 (Blue/green upgrades for Kong Gateway)

Kong Operator에서 DataPlane 리소스를 직접 다루면 블루/그린 방식으로 업그레이드할 수 있어요. rollout 전략을 blueGreen으로 설정하면 Kong Operator가 설정 변경을 감지할 때마다 프리뷰 Deployment를 만들어 새 버전을 미리 검증하게 해줘요. 이 문서에서는 전략 설정부터 새 이미지 패치, 프리뷰 Service 확인과 승격(promotion)까지 전체 흐름을 단계별로 살펴봐요. 참고로 이 방법은 하이브리드 모드에서 실행 중일 때만 사용할 수 있다는 점도 기억해 두면 좋아요

출처: 문서

본문

이 방법은 하이브리드 모드로 실행할 때만 사용할 수 있어요.

DataPlane 리소스를 직접 다룰 때는 블루/그린 업그레이드를 수행할 수 있어요.

  1. 블루/그린 배포를 활성화하려면 DataPlane 리소스에 spec.deployment.rollout.strategy를 설정하세요:

    apiVersion: gateway-operator.konghq.com/v1beta1
    kind: DataPlane
    metadata:
      name: dataplane-example
    spec:
      deployment:
        rollout:
          strategy:
            blueGreen:
              promotion:
                strategy: BreakBeforePromotion
        podTemplateSpec:
          spec:
            containers:
            - name: proxy
              image: kong/kong-gateway:3.16
              env:
              - name: KONG_LOG_LEVEL
                value: debug
    

    참고: 현재는 프로모션 전략으로 BreakBeforePromotion만 사용할 수 있어요.

    이렇게 적용하고 나면 Kong Operator가 새로운 Service들을 배포하고, 새 Pod들이 준비되면 그 Service들을 통해 접근할 수 있게 돼요.

    기본적으로는 Pod가 바로 배포되지 않아요. 대신 Kong Operator가 DataPlane 리소스의 spec 변경을 관찰하다가 구성 드리프트가 감지되면, DataPlane 리소스에 적용된 변경 사항을 담은 새로운 "preview" Deployment를 만들어요.

  2. DataPlane이 변경 사항을 받아들일 준비가 될 때까지 기다리세요

    kubectl wait dataplane dataplane-example --for=jsonpath='{.status.rollout.conditions[*].reason}'=AwaitingPromotion
    
  3. DataPlane에 새로운 image를 패치해서 테스트해 보세요:

    kubectl patch dataplane dataplane-example --type='json' -p='[{"op": "replace", "path": "/spec/deployment/podTemplateSpec/spec/containers/0/image", "value":"kong:3.3.1"}]'
    

    출력은 다음과 같이 보일 거예요:

    dataplane.gateway-operator.konghq.com/dataplane-example patched
    

    이 패치가 적용되면 "preview" ingress Service를 통해 새로운 Kong Gateway Pod들에 접근할 수 있어요.

  4. "preview" Service를 찾으려면 DataPlane 상태, 그중에서도 rollout 필드를 확인하면 돼요:

    kubectl get dataplane dataplane-example -o jsonpath-as-json='{.status.rollout}'
    

    출력은 다음과 같이 보일 거예요:

    [
        {
            "conditions": [
                {
                    "lastTransitionTime": "2023-09-21T11:40:25Z",
                    "message": "",
                    "observedGeneration": 2,
                    "reason": "AwaitingPromotion",
                    "status": "False",
                    "type": "RolledOut"
                }
            ],
            "deployment": {
                "selector": "6cf0d993-2319-43d5-bfdc-e2cadd6bd7e3"
            },
            "services": {
                "adminAPI": {
                    "addresses": [
                        {
                            "sourceType": "PrivateIP",
                            "type": "IPAddress",
                            "value": "None"
                        }
                    ],
                    "name": "dataplane-admin-dataplane-example-cx6nq"
                },
                "ingress": {
                    "addresses": [
                        {
                            "sourceType": "PrivateLoadBalancer",
                            "type": "IPAddress",
                            "value": "172.18.0.101"
                        },
                        {
                            "sourceType": "PrivateIP",
                            "type": "IPAddress",
                            "value": "10.96.28.2"
                        }
                    ],
                    "name": "dataplane-ingress-dataplane-example-2249g"
                }
            }
        }
    ]
    

    여기서 새로운 Pod 세트를 검증할 수 있도록 생성된 ingress Service 이름을 볼 수 있어요.

    주소들(type과 sourceType 포함)은 status.rollout.services[].ingress에 저장돼요.

    status.rollout.conditions[]에 Type이 RolledOut이고 Reason이 AwaitingPromotion으로 설정된 조건이 포함되어 있는 점에 주목하세요. 이는 스테이징된 변경 사항으로 DataPlane을 프로모션할 준비가 모두 끝났다는 뜻이에요. 그 전에 한번 테스트해 볼게요.

  5. 생성된 "preview" Service에는 LB 주소(status.rollout.services[].ingress.addresses[].value 필드에서 가져온 값)를 사용해서 접근할 수 있어요:

    $ curl -s -D - -o /dev/null 172.18.0.101
    HTTP/1.1 404 Not Found
    Date: Thu, 21 Sep 2023 11:40:26 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Content-Length: 52
    X-Kong-Response-Latency: 0
    Server: kong/3.3.1
    

    이렇게 하면 새로운 Kong Gateway Pod들이 배포되었고, 업데이트된 이미지로 "preview" ingress Service를 통해 접근할 수 있다는 것을 확인할 수 있어요.

  6. 기존 Pod들이 여전히 사용 가능한 상태이고 트래픽을 계속 처리하고 있는지 확인하세요. "live" ingress Service에 접근해서 확인할 수 있어요

    주소는 다음과 같이 가져올 수 있어요:

    kubectl get dataplane dataplane-example -o jsonpath-as-json='{.status.addresses}'
    

    출력은 다음과 같이 보일 거예요:

    [
      [
        {
            "sourceType": "PrivateLoadBalancer",
            "type": "IPAddress",
            "value": "172.18.0.100"
        },
        {
            "sourceType": "PrivateIP",
            "type": "IPAddress",
            "value": "10.96.11.156"
        }
      ],
    ]
    

    LoadBalancer IP 주소가 172.18.0.100인 것을 확인했으니, 요청을 보내 볼 수 있어요:

    $ curl -s -D - -o /dev/null 172.18.0.100
    HTTP/1.1 404 Not Found
    Date: Thu, 21 Sep 2023 11:40:26 GMT
    Content-Type: application/json; charset=utf-8
    Connection: keep-alive
    Content-Length: 52
    X-Kong-Response-Latency: 0
    Server: kong/3.9.3
    

    보시다시피, live Service는 여전히 3.9.3을 사용해서 트래픽을 처리하고 있어요.

  7. 이제 배포된 리소스를 살펴보면서 추가 검증 단계를 수행할 수 있어요.

  8. 새로 생성된 리소스 검증이 끝나면 kubectl annotate dataplanes.gateway-operator.konghq.com dataplane-example gateway-operator.konghq.com/promote-when-ready=true를 실행해서 Kong Operator가 트래픽을 새로운 Pod들로 전환하도록 허용하세요.

    이 어노테이션은 새로운 Pod들이 live로 프로모션되면 Kong Operator가 자동으로 지워 줘요.

  9. 프로모션이 끝나면 업데이트된 Pod들이 트래픽 처리를 시작하고, 리소스를 절약하기 위해 기존 Pod들과 그 Deployment는 삭제돼요.

더 알아보기 (Learn more)

  • 이 업그레이드 방식은 하이브리드 모드에서 실행할 때만 사용할 수 있어요, 하이브리드 모드 설치 방법을 담은 문서예요 — hybrid mode