Kubernetes 배포에서 Consul 관리 파티션 사용

Kubernetes 배포에서 Consul 관리 파티션 사용

이 페이지는 Kubernetes 배포에서 Consul 관리 파티션(admin partitions)을 사용하는 방법을 설명해요. 관리 파티션의 주요 사용 사례 중 하나는 여러 Kubernetes 클러스터에 걸쳐 서비스 메시를 활성화하는 것이에요.

출처: 문서

본문

이 페이지는 Kubernetes 배포에서 Consul 관리 파티션을 사용하는 방법을 설명합니다.

요구 사항 (Requirements)

관리 파티션의 주요 사용 사례 중 하나는 여러 Kubernetes 클러스터에 걸쳐 서비스 메시를 활성화하는 것입니다. Kubernetes에서 관리 파티션을 만들려면 다음 요구 사항을 충족해야 합니다.

  • Consul 서버를 Kubernetes에 배포한다면 Consul 서버가 같은 Kubernetes 클러스터 내에 배포되어 있는지 확인하세요. Consul 서버는 Kubernetes 외부에 배포하고 externalServers 스탠자로 구성할 수 있습니다.
  • Consul 서버와 같은 Kubernetes 클러스터에 배포된 워크로드는 default 파티션을 사용해야 합니다. 워크로드가 기본이 아닌 파티션에서 실행되어야 한다면 클라이언트는 별도의 Kubernetes 클러스터에 배포되어야 합니다.
  • 각 Kubernetes 클러스터에 Consul Enterprise 라이선스가 설치되어 있어야 합니다.
  • consul-k8s v0.39.0 이상의 Helm chart.
  • Consul 1.11.1-ent 이상.
  • Consul 서버 클러스터에 지정된 Kubernetes LoadBalancer 서비스가 노출되어야 합니다. 이는 Consul 서버에 대한 다음 통신 채널을 활성화합니다.
    • 포트 8300의 RPC
    • 포트 8301의 Gossip
    • 포트 443의 HTTPS API 요청
    • API 요청
  • 메시 게이트웨이는 모든 Kubernetes 클러스터에서 포트 443의 Kubernetes LoadBalancer 서비스로 배포되어야 합니다.
  • 교차 파티션 네트워킹은 Cross-Partition Networking에 설명된 대로 구현되어야 합니다.

사용법 (Usage)

이 섹션은 Kubernetes 클러스터에 Consul 관리 파티션을 배포하는 방법을 설명합니다. 명령줄 사용법에 대한 정보는 admin partition CLI 문서를 참조하세요.

Kubernetes에서 관리 파티션으로 Consul 배포

기대되는 사용 사례는 Kubernetes 클러스터에 관리 파티션을 만드는 것입니다. 많은 조직이 단일의 대규모 Kubernetes 클러스터를 배포하는 대신 클라우드 관리 Kubernetes 제공을 사용하여 개별 팀, 사업부 또는 환경에 대해 별도의 Kubernetes 클러스터를 프로비저닝하는 것을 선호하기 때문입니다. 그러나 조직은 서비스 메시를 사용해 관리 작업 및 노드 간 통신 같은 멀티 클러스터 사용 사례를 활성화하려고 할 때 문제를 겪습니다.

다음 절차는 각 Kubernetes 클러스터에 관리 파티션을 만듭니다. 서버가 있는 클러스터에서 실행되는 Consul 클라이언트는 default 파티션에 있습니다. clients라는 다른 파티션도 생성됩니다.

여러 Kubernetes 클러스터에 Consul 설치 준비

진행하기 전에 Consul 배포가 Kubernetes Requirements를 충족하는지 확인하세요.

  1. VPC가 워크로드를 실행하는 pod와 Consul 서버 사이의 연결을 활성화하도록 구성되어 있는지 확인합니다. 네트워크 연결 구성 지침은 가상 클라우드 공급자의 문서를 참조하세요.
  2. 셸 명령에 사용할 환경 변수를 설정합니다.
    $ export HELM_RELEASE_SERVER=server
    $ export HELM_RELEASE_CLIENT=client
    $ export SERVER_CONTEXT=<context for server, run `kubectl config current-context` for cluster provisioned for servers>
    $ export CLIENT_CONTEXT=<context for workload partition, run `kubectl config current-context` for cluster provisioned for workload partition>
    
  3. 서버 클러스터에 라이선스 시크릿을 만듭니다.
    $ kubectl create --context ${SERVER_CONTEXT} namespace consul
    $ kubectl create secret --context ${SERVER_CONTEXT} --namespace consul generic license --from-file=key=./path/to/license.hclic
    
  4. 워크로드를 위한 기본이 아닌 파티션 클러스터에 라이선스 시크릿을 만듭니다. 이 단계는 추가 기본이 아닌 파티션 클러스터마다 반복해야 합니다.
    $ kubectl create --context ${CLIENT_CONTEXT} namespace consul
    $ kubectl create secret --context ${CLIENT_CONTEXT} --namespace consul generic license --from-file=key=./path/to/license.hclic
    

Consul 서버 클러스터 설치

  1. 컨텍스트를 서버 클러스터로 설정합니다.
    $ kubectl config use-context ${SERVER_CONTEXT}
    
  2. 기본 Consul Helm chart 설정을 재정의하는 서버 구성 values 파일을 만듭니다. server.yaml
    global:
      enableConsulNamespaces: true
      tls:
        enabled: true
      image: hashicorp/consul-enterprise:1.16.3-ent
      adminPartitions:
        enabled: true
      acls:
        manageSystemACLs: true
      enterpriseLicense:
        secretName: license
        secretKey: key
    meshGateway:
      enabled: true
    
    파일에서 지정할 수 있는 매개변수에 대한 자세한 내용은 Helm Chart Configuration reference를 참조하세요.
  3. 이전 단계에서 만든 values 파일을 사용해 Consul 서버를 설치합니다.
    $ helm install ${HELM_RELEASE_SERVER} hashicorp/consul --version "1.0.0" --create-namespace --namespace consul --values server.yaml
    
  4. 서버가 시작된 후 파티션 서비스의 외부 IP 주소를 가져와 클라이언트 구성(externalServers.hosts)에 추가할 수 있도록 합니다. 이 IP 주소는 기본이 아닌 파티션 클러스터의 서버와 워크로드 pod 사이의 연결을 부트스트랩하는 데 사용됩니다.
    $ kubectl get services --selector="app=consul,component=server" --namespace consul --output jsonpath="{range .items[*]}{@.status.loadBalancer.ingress[*].ip}{end}"
    34.135.103.67
    
  5. 워크로드를 실행하는 기본이 아닌 파티션 클러스터의 Kubernetes 인증 메서드 URL을 가져옵니다.
    $ kubectl config view --output "jsonpath={.clusters[?(@.name=='${CLIENT_CONTEXT}')].cluster.server}"
    
    콘솔에 인쇄된 IP 주소를 사용하여 워크로드를 실행하는 기본이 아닌 파티션 클러스터의 워크로드 구성 파일에서 externalServers.k8sAuthMethodHost 매개변수를 구성하세요.
  6. 서버 인증서를 워크로드를 실행하는 기본이 아닌 파티션 클러스터로 복사합니다.
    $ kubectl get secret ${HELM_RELEASE_SERVER}-consul-ca-cert --context ${SERVER_CONTEXT} -n consul --output yaml | kubectl apply --namespace consul --context ${CLIENT_CONTEXT} --filename -
    
  7. 서버 키를 워크로드를 실행하는 기본이 아닌 파티션 클러스터로 복사합니다.
    $ kubectl get secret ${HELM_RELEASE_SERVER}-consul-ca-key --context ${SERVER_CONTEXT} --namespace consul --output yaml | kubectl apply --namespace consul --context ${CLIENT_CONTEXT} --filename -
    
  8. 서버 구성 values 파일에서 ACL을 활성화했다면 토큰을 워크로드를 실행하는 기본이 아닌 파티션 클러스터로 복사합니다.
    $ kubectl get secret ${HELM_RELEASE_SERVER}-consul-partitions-acl-token --context ${SERVER_CONTEXT} --namespace consul --output yaml | kubectl apply --namespace consul --context ${CLIENT_CONTEXT} --filename -
    

워크로드를 실행하는 기본이 아닌 파티션 클러스터에 설치

  1. 워크로드를 실행하는 기본이 아닌 파티션 클러스터로 전환합니다.
    $ kubectl config use-context ${CLIENT_CONTEXT}
    
  2. 각 기본이 아닌 관리 파티션에 대한 구성을 만듭니다. client.yaml
    global:
      name: consul
      enabled: false
      enableConsulNamespaces: true
      image: hashicorp/consul-enterprise:1.16.3-ent
      adminPartitions:
        enabled: true
        name: clients
      tls:
        enabled: true
        caCert:
          secretName: server-consul-ca-cert # See step 6 from `Install Consul server cluster`
          secretKey: tls.crt
        caKey:
          secretName: server-consul-ca-key # See step 7 from `Install Consul server cluster`
          secretKey: tls.key
      acls:
        manageSystemACLs: true
        bootstrapToken:
          secretName: server-consul-partitions-acl-token # See step 8 from `Install Consul server cluster`
          secretKey: token
      enterpriseLicense:
        secretName: license
        secretKey: key
    externalServers:
      enabled: true
      hosts: [34.135.103.67] # See step 4 from `Install Consul server cluster`
      tlsServerName: server.dc1.consul
      k8sAuthMethodHost: https://104.154.156.146 # See step 5 from `Install Consul server cluster`
    meshGateway:
      enabled: true
    
  3. 워크로드를 실행하는 기본이 아닌 파티션 클러스터를 설치합니다.
    $ helm install ${HELM_RELEASE_CLIENT} hashicorp/consul --version "1.0.0" --create-namespace --namespace consul --values client.yaml
    

배포 확인 (Verifying the Deployment)

Consul UI에 로그인하여 파티션이 예상대로 나타나는지 확인할 수 있습니다.

  1. 컨텍스트를 서버 클러스터로 설정합니다.
    $ kubectl config use-context ${SERVER_CONTEXT}
    
  2. ACL이 활성화되어 있으면 Kubernetes 시크릿에서 읽을 수 있는 파티션 ACL 토큰이 필요합니다. 토큰은 base64로 디코딩해야 하는 인코딩된 문자열입니다. 예:
    $ kubectl get secret --namespace consul --context ${SERVER_CONTEXT} --template "{{ .data.token | base64decode }}" ${HELM_RELEASE_SERVER}-consul-bootstrap-acl-token
    
    예시 명령은 기본 파티션 클러스터에서 시크릿을 가져와 디코딩하고 콘솔에 토큰을 인쇄합니다.
  3. 이전 단계에서 설명한 외부 IP 주소와 포트 번호를 사용해 브라우저에서 Consul UI를 엽니다(step 4 참조).
  4. Log in을 클릭하고 메시지가 표시되면 디코딩된 토큰을 입력합니다.

Admin Partition 드롭다운 메뉴에서 default 및 clients 파티션이 사용 가능한 것을 볼 수 있습니다.

더 알아보기 (Learn more)