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

Calico 인그레스 게이트웨이로 카나리 배포 시작하기

원문 보기 위키 갱신

Calico Ingress Gateway를 사용해 카나리(canary) 배포를 만드는 방법을 단계별로 알아봐요. 새 버전의 애플리케이션을 일부 사용자에게만 조금씩 공개하고, 트래픽 분할로 안전하게 검증하는 과정을 직접 따라 해 보세요.

출처: 문서

본문

Overview

**카나리 배포(canary deployment)**는 새 버전의 애플리케이션을 전면 배포하기 전에 소수의 사용자에게 점진적으로 공개하는 프로그레시브 릴리스 전략이에요. 이 접근 방식을 사용하면 문제를 조기에 발견하고, 새 기능을 검증하고, 필요하면 빠르게 롤백할 수 있어서 대다수 사용자가 겪는 장애를 최소화할 수 있어요.

Calico Enterprise에서는 인그레스 게이트웨이에 연결된 라우팅 리소스에 정의되는 트래픽 분할(traffic splitting) 방식으로 카나리 배포를 구현해요. 라우팅 규칙을 정의하면 들어오는 트래픽의 일부만 워크로드의 카나리 버전으로 보내서 테스트할 수 있고, 대다수 트래픽은 계속 안정(stable) 버전으로 흘러가요.

카나리 버전에 대한 확신이 커지면, 그 버전으로 향하는 트래픽 비중을 점진적으로 늘려서 최종적으로 새 안정 버전이 되도록 만들면 돼요.

Use cases

  • 기능 롤아웃: 새 기능을 소수 사용자에게 안전하게 공개해서 기능을 검증하고 피드백을 모은 다음 전면 배포할 수 있어요.
  • 성능 테스트: 모든 사용자에게 영향을 주지 않으면서 새 버전이 실제 트래픽과 리소스 사용량을 어떻게 감당하는지 평가할 수 있어요.
  • 버그 탐지: 사용자 영향을 최소화하면서 프로덕션의 치명적인 버그나 예상치 못한 동작을 잡아낼 수 있어요.
  • A/B 테스트: 하나로 확정하기 전에 서비스의 여러 버전을 비교해서 성능, 사용자 참여도, 전환율을 시험할 수 있어요.
  • 컴플라이언스와 리스크 관리: 규제가 엄격하거나 미션 크리티컬한 환경에서 업데이트를 점진적으로 배포해 광범위한 장애 가능성을 줄일 수 있어요.

카나리 배포는 통제된 저위험 릴리스를 원할 때 이상적이에요. 전면 롤아웃 전에 메트릭을 모니터링하고 가정을 검증하며 안정성을 확인할 수 있거든요.

Before you begin

이 튜토리얼을 완료하려면 몇 가지 도구를 설치해야 해요:

  • kind. 워크스테이션에 클러스터를 만들 때 사용해요. 설치 방법은 kind 문서를 참고하세요.
  • Docker Engine 또는 Docker Desktop. kind 유틸리티용 컨테이너를 실행하는 데 필요해요. 설치 방법은 Docker 문서를 참고하세요.
  • kubectl. 클러스터와 상호작용할 때 사용하는 도구예요. 설치 방법은 Kubernetes 문서를 참고하세요.

Step 1: Set up your environment

이 튜토리얼에서는 Calico Open Source 3.30 이상이 설치된 클러스터에 접근할 수 있어야 해요.

여기서는 kind로 이 환경을 만들지만, 호환 버전의 Calico Enterprise를 갖춘 다른 지원 Kubernetes 배포판을 사용해도 돼요. 이미 적합한 환경이 있다면 Step 2: Create the ingress gateway부터 튜토리얼을 시작하세요.

  1. 컨트롤 플레인 노드 1개와 워커 노드 2개를 가진 kind 클러스터를 만들어요.

    cat > config.yaml <<EOF
    kind: Cluster
    apiVersion: kind.x-k8s.io/v1alpha4
    nodes:
      - role: control-plane
      - role: worker
      - role: worker
    networking:
      disableDefaultCNI: true
      podSubnet: 192.168.0.0/16
    EOF
    
    kind create cluster --config config.yaml --name calico-cluster
    

    kind가 구성 파일을 읽고 몇 분 안에 클러스터를 만들어 줘요.

    예상 출력

    Creating cluster "calico-cluster" ...
    ✓ Ensuring node image (kindest/node:v1.33.1) 🖼
    ✓ Preparing nodes 📦 📦 📦
    ✓ Writing configuration 📜
    ✓ Starting control-plane 🕹️
    ✓ Installing StorageClass 💾
    ✓ Joining worker nodes 🚜
    Set kubectl context to "kind-calico-cluster"
    You can now use your cluster with:
    
    kubectl cluster-info --context kind-calico-cluster
    
    Thanks for using kind! 😊
    
  2. 클러스터가 정상 동작하는지 확인하려면 다음 명령어를 실행해요:

    kubectl get nodes
    

    클러스터에 붙인 이름이 들어간 노드 세 개가 보여야 해요.

    예상 출력

    NAME                           STATUS     ROLES           AGE     VERSION
    calico-cluster-control-plane   NotReady   control-plane   5m46s   v1.33.1
    calico-cluster-worker          NotReady   <none>          5m23s   v1.33.1
    calico-cluster-worker2         NotReady   <none>          5m22s   v1.33.1
    

    다음 단계에서 네트워킹을 구성하기 전까지는 노드가 NotReady 상태로 남아 있어요.

  3. 커스텀 리소스 정의, Tigera Operator, 커스텀 리소스를 추가해서 Calico Open Source를 설치해요.

    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.1/manifests/operator-crds.yaml
    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.1/manifests/tigera-operator.yaml
    kubectl create -f https://raw.githubusercontent.com/projectcalico/calico/v3.31.1/manifests/custom-resources.yaml
    
  4. 다음 명령어로 배포 상태를 감시해요:

    watch kubectl get tigerastatus
    

    몇 분 지나면 모든 Calico 컴포넌트가 AVAILABLE 열에 True로 표시돼요.

    예상 출력

    NAME                            AVAILABLE   PROGRESSING   DEGRADED   SINCE
    apiserver                       True        False         False      4m9s
    calico                          True        False         False      3m29s
    goldmane                        True        False         False      3m39s
    ippools                         True        False         False      6m4s
    whisker                         True        False         False      3m19s
    

Step 2. Create an ingress gateway

GatewayAPI 리소스를 만들어서 Gateway API를 활성화해요. 이 리소스를 만들면 Tigera Operator가 Envoy Gateway 이미지를 받아와서 환경을 준비해요. 준비가 끝나면 Gateway와 라우팅 리소스 같은 지원되는 Gateway API 리소스를 만들 수 있어요.

  1. Gateway API 지원을 활성화하려면 이름이 default인 GatewayAPI 리소스를 만들어요:

    kubectl apply -f - <<EOF
    apiVersion: operator.tigera.io/v1
    kind: GatewayAPI
    metadata:
      name: default
    EOF
    

    잠시 후 Gateway API 리소스를 사용할 수 있게 된 걸 확인할 수 있어요:

    kubectl api-resources | grep gateway.networking.k8s.io
    

    예상 출력

    backendlbpolicies                   blbpolicy                                       gateway.networking.k8s.io/v1alpha2          true         BackendLBPolicy
    backendtlspolicies                  btlspolicy                                      gateway.networking.k8s.io/v1alpha3          true         BackendTLSPolicy
    gatewayclasses                      gc                                              gateway.networking.k8s.io/v1                false        GatewayClass
    gateways                            gtw                                             gateway.networking.k8s.io/v1                true         Gateway
    grpcroutes                                                                          gateway.networking.k8s.io/v1                true         GRPCRoute
    httproutes                                                                          gateway.networking.k8s.io/v1                true         HTTPRoute
    referencegrants                     refgrant                                        gateway.networking.k8s.io/v1beta1           true         ReferenceGrant
    tcproutes                                                                           gateway.networking.k8s.io/v1alpha2          true         TCPRoute
    tlsroutes                                                                           gateway.networking.k8s.io/v1alpha2          true         TLSRoute
    udproutes                                                                           gateway.networking.k8s.io/v1alpha2          true         UDPRoute
    

    그리고 Calico Enterprise에 포함된 Envoy Gateway 구현에 해당하는 GatewayClass 리소스도 존재하는 걸 확인할 수 있어요:

    kubectl get gatewayclass -o=jsonpath='{.items[0].spec}' | jq
    

    예상 출력

    {
      "controllerName": "gateway.envoyproxy.io/gatewayclass-controller",
      "parametersRef": {
        "group": "gateway.envoyproxy.io",
        "kind": "EnvoyProxy",
        "name": "envoy-proxy-config",
        "namespace": "tigera-gateway"
      }
    }
    
  2. tigera-gateway-class에 연결되는 Gateway 리소스를 만들어요.

    kubectl apply -f - <<EOF
    apiVersion: gateway.networking.k8s.io/v1
    kind: Gateway
    metadata:
      name: canary-deployment-gateway
    spec:
      gatewayClassName: tigera-gateway-class
      listeners:
        - name: http
          protocol: HTTP
          port: 80
    EOF
    

    게이트웨이를 사용할 모든 서비스에서 이 게이트웨이 이름을 참조하게 돼요.

Step 3. Deploy v1 (stable) and v2 (canary) of an application

트래픽 분할을 시연하려면 서비스 두 개가 필요해요. ingress-gateway-demo 애플리케이션의 두 버전, 즉 v1(안정)과 v2(카나리 빌드)를 만들 거예요. 이 앱은 HTML 한 줄을 제공하는 간단한 웹 서버예요.

  1. ingress-gateway-demo 애플리케이션용 네임스페이스를 만들어요:

    cat << EOF | kubectl create -f -
    apiVersion: v1
    kind: Namespace
    metadata:
      name: ingress-gateway-demo
    EOF
    
  2. ingress-gateway-demo 앱의 안정 버전을 배포해요. 이 매니페스트 묶음에는 다음이 포함돼요:

    • ConfigMap(app-v1-html): 정적 index.html 파일(앱의 내용)을 저장해요.
    • Deployment(app-v1): BusyBox 컨테이너 복제본 하나를 실행하고 ConfigMap에 저장된 HTML 내용을 제공해요.
    • Service(app-v1): 클러스터 내부에서 접근할 수 있도록 BusyBox 파드를 안정적인 내부 IP 주소로 노출해요.
    cat << EOF | kubectl apply -f -
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: app-v1-html
      namespace: ingress-gateway-demo
    data:
      index.html: |
        <html><body><h1>App Version 1</h1></body></html>
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: app-v1
      namespace: ingress-gateway-demo
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: ingress-gateway-demo
          version: v1
      template:
        metadata:
          labels:
            app: ingress-gateway-demo
            version: v1
        spec:
          containers:
            - name: busybox
              image: busybox:latest
              command: ["sh", "-c", "httpd -f -p 80 -h /var/www/html"]
              ports:
                - containerPort: 80
              volumeMounts:
                - name: html
                  mountPath: /var/www/html
          volumes:
            - name: html
              configMap:
                name: app-v1-html
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: app-v1
      namespace: ingress-gateway-demo
    spec:
      selector:
        app: ingress-gateway-demo
        version: v1
      ports:
        - port: 80
          targetPort: 80
    EOF
    

    예상 출력

    configmap/app-v1-html created
    deployment.apps/app-v1 created
    service/app-v1 created
    
  3. 이제 카나리 빌드인 ingress-gateway-demo v2에도 동일한 리소스를 배포해요:

    cat << EOF | kubectl apply -f -
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: app-v2-html
      namespace: ingress-gateway-demo
    data:
      index.html: |
        <html><body><h1>App Version 2</h1></body></html>
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: app-v2
      namespace: ingress-gateway-demo
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: ingress-gateway-demo
          version: v2
      template:
        metadata:
          labels:
            app: ingress-gateway-demo
            version: v2
        spec:
          containers:
            - name: busybox
              image: busybox:latest
              command: ["sh", "-c", "httpd -f -p 80 -h /var/www/html"]
              ports:
                - containerPort: 80
              volumeMounts:
                - name: html
                  mountPath: /var/www/html
          volumes:
            - name: html
              configMap:
                name: app-v2-html
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: app-v2
      namespace: ingress-gateway-demo
    spec:
      selector:
        app: ingress-gateway-demo
        version: v2
      ports:
        - port: 80
          targetPort: 80
    EOF
    

    예상 출력

    configmap/app-v2-html created
    deployment.apps/app-v2 created
    service/app-v2 created
    

Step 4: Define an HTTPRoute resource to split traffic between app-v1 and app-v2

아래의 HTTPRoute는 요청의 80%를 app-v1로, 20%를 app-v2로 라우팅해요.

cat << EOF | kubectl apply -f -
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: traffic-splitting
spec:
  parentRefs:
    - name: canary-deployment-gateway
      namespace: default
  rules:
    - matches:
        - path:
            type: PathPrefix
            value: /
      backendRefs:
        - name: app-v1
          namespace: ingress-gateway-demo
          port: 80
          weight: 80
        - name: app-v2
          namespace: ingress-gateway-demo
          port: 80
          weight: 20
EOF

Step 5. Allow ingress traffic from the gateway to reach services in the ingress-gateway-demo namespace

ReferenceGrant 리소스에 정의를 추가하면 게이트웨이에서 앱으로 트래픽이 라우팅되는 것을 허용할 수 있어요.

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1beta1
kind: ReferenceGrant
metadata:
  name: ingress-gateway-demo
  namespace: ingress-gateway-demo
spec:
  from:
  - group: gateway.networking.k8s.io
    kind: HTTPRoute
    namespace: default
  to:
  - group: ""
    kind: Service
EOF

1분 정도 지나면 게이트웨이와 서비스가 준비돼요.

Step 6. Test the canary deployment

이 튜토리얼에서는 로컬 워크스테이션으로 포트 포워딩해서 게이트웨이를 통해 앱에 접근해 볼 거예요. 실제 환경에서는 외부 트래픽을 유입시킬 로드 밸런서를 구성하게 돼요.

  1. 인그레스 게이트웨이의 서비스 이름을 확인해요:

    CANARY_DEMO=$(kubectl get svc -n tigera-gateway -o jsonpath='{.items[*].metadata.name}' | tr ' ' '\n' | grep canary)
    echo "CANARY_DEMO is: $CANARY_DEMO"
    

    예시 출력

    CANARY_DEMO is: envoy-default-canary-deployment-gateway-c84e1eb6
    
  2. 서비스에 포트 포워딩을 설정해요:

    kubectl port-forward -n tigera-gateway svc/$CANARY_DEMO 30135:80
    

    이제 웹 브라우저에서 http://localhost:30135로 앱에 접근할 수 있어요.

  3. 이제 다른 터미널에서 앱에 접근하면서 각 버전이 얼마나 자주 응답하는지 확인해서 카나리 빌드를 테스트할 수 있어요:

    for i in $(seq 200); do curl -s http://localhost:30135/ | grep "<h1>"; done | \
    awk '
    /App Version 1/ {v1++}
    /App Version 2/ {v2++}
    END {
      total=v1+v2
      printf("Version 1: %d (%.1f%%)\nVersion 2: %d (%.1f%%)\n",
             v1, v1/total*100, v2, v2/total*100)
    }'
    

    샘플 출력

    Version 1: 161 (80.5%)
    Version 2: 39 (19.5%)
    

Step 7. Clean up your environment

  • 튜토리얼 환경을 정리하려면 다음 명령어를 실행해요:

    kind delete cluster --name calico-cluster
    

더 알아보기 (Learn more)