AKS에 Consul 배포

AKS에 Consul 배포 (Deploy Consul on AKS)

이 주제는 Azure Kubernetes Services(AKS) 클러스터에 Consul 데이터센터를 배포하는 방법을 설명해요. Consul 배포 후 CLI, UI, API로 Consul을 사용하게 돼요.

출처: 문서

본문

이 주제는 Azure Kubernetes Services(AKS) 클러스터에 Consul 데이터센터를 배포하는 방법을 설명해요. Consul 배포 후 CLI, UI, 그리고/또는 API로 Consul과 상호작용하게 돼요.

요구 사항 (Requirements)

AKS에 Consul을 배포하려면 다음이 필요해요:

이 예시는 Azure Cloud Shell에 설치된 최신 버전의 Helm과 kubectl을 사용해요.

AKS 클러스터 생성 (Create an AKS cluster)

공식 Consul Helm 차트 또는 Consul K8S CLI를 사용해 Consul을 배포하려면 최소 3노드 AKS 클러스터가 필요해요. AKS 문서에 따라 AKS에 3노드 클러스터를 생성해요.

kubectl을 클러스터와 상호작용하도록 구성 (Configure kubectl to interact to your cluster)

콘솔에서 Azure Shell에 로그인해요.

$ az login

kubectl이 Kubernetes 클러스터에 연결하도록 구성해요. 이 명령은 자격 증명을 다운로드하고 Kubernetes CLI가 이를 사용하도록 구성해요. myResourceGroup과 myAKSCluster를 자신의 리소스 그룹과 AKS 클러스터 이름으로 바꿔요.

$ az aks get-credentials --resource-group myResourceGroup --name myAKSCluster

Kubernetes 클러스터에 연결되었는지 확인해요.

$ kubectl cluster-info
Kubernetes control plane is running at <your AKS ip(s)>
CoreDNS is running at https://<your AKS ip(s)>/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://<your AKS ip(s)>/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use the command`kubectl cluster-info dump`.

Consul 배포 (Deploy Consul)

공식 Consul Helm 차트 또는 Consul K8S CLI를 사용해 완전한 Consul 데이터센터를 배포할 수 있어요. 기본적으로 이 방법들은 총 3개의 Consul 서버를 설치해요. 이러한 설치 옵션에 대해 더 알아보려면 Consul Kubernetes 설치 문서를 검토해요.

values 파일 생성 (Create a values file)

배포를 사용자 정의하려면 values.yaml 파일을 만들어 Consul 배포를 사용자 정의해요.

values.yaml:

# Contains values that affect multiple components of the chart.
global:
  # The main enabled/disabled setting.
  # If true, servers, clients, Consul DNS and the Consul UI will be enabled.
  enabled: true
  # The prefix used for all resources created in the Helm chart.
  name: consul
  # The name of the datacenter that the agents should register as.
  datacenter: dc1
  # Enables TLS across the cluster to verify authenticity of the Consul servers and clients.
  tls:
    enabled: true
 # Enables ACLs across the cluster to secure access to data and APIs.
 acls:
    # If true, automatically manage ACL tokens and policies for all Consul components.
    manageSystemACLs: true
# Configures values that configure the Consul server cluster.
server:
  enabled: true
  # The number of server agents to run. This determines the fault tolerance of the cluster.
  replicas: 3
# Contains values that configure the Consul UI.
ui:
  enabled: true
  # Registers a Kubernetes Service for the Consul UI as a LoadBalancer.
  service:
    type: LoadBalancer
# Configures and installs the automatic Consul Connect sidecar injector.
connectInject:
  enabled: true

클러스터에 Consul 설치 (Install Consul in your cluster)

이제 공식 Consul Helm 차트 또는 Consul K8S CLI를 사용해 Kubernetes 클러스터에 완전한 Consul 데이터센터를 배포할 수 있어요.

Consul K8S CLI (Mac & Linux): consul-k8s로 AKS 클러스터에 Consul을 설치해요. 프롬프트가 나타나면 y로 설치를 확인해요.

$ consul-k8s install -config-file=values.yaml -set global.image=hashicorp/consul:1.14.0

추가 설정에 대해 더 알아보려면 공식 Consul K8S CLI 문서를 검토해요.

Helm: Helm으로 kind 클러스터에 Consul을 설치해요. 프롬프트가 나타나면 y로 설치를 확인해요.

$ helm install --values values.yaml consul hashicorp/consul --create-namespace --namespace consul --version "1.0.0"

기본 설정에 대해 더 알아보려면 공식 Helm 차트 값을 검토해요.

Consul 리소스가 성공적으로 생성되었는지 확인해요.

$ kubectl get pods --namespace consul
NAME                                           READY   STATUS    RESTARTS   AGE
consul-connect-injector-6fc8d669b8-2n82l       1/1     Running   0          2m34s
consul-connect-injector-6fc8d669b8-9mqfm       1/1     Running   0          2m34s
consul-controller-554c7f79c4-2xc64             1/1     Running   0          2m34s
consul-server-0                                1/1     Running   0          2m34s
consul-server-1                                1/1     Running   0          2m34s
consul-server-2                                1/1     Running   0          2m34s
consul-webhook-cert-manager-64889c4964-wxc9b   1/1     Running   0          2m34s

Consul 클러스터와 상호작용하도록 CLI 구성 (Configure your CLI to interact with Consul cluster)

이 섹션에서는 터미널에 환경 변수를 설정해 Consul CLI가 Consul 클러스터와 상호작용하도록 해요. Consul CLI는 기본 동작을 위해 이 환경 변수들을 읽으며, consul 명령을 실행할 때 이 값들을 참조해요.

토큰은 ACL 시스템에서 사용자, 서비스, Consul 에이전트를 인증하는 데 사용되는 아티팩트예요. 이 Consul 데이터센터에서 ACL이 활성화되어 있으므로 리소스에 대한 접근을 요청하는 엔티티는 리소스에 대한 권한을 부여하는 정책, 서비스 ID 또는 노드 ID와 연결된 토큰을 포함해야 해요. ACL 시스템은 토큰을 확인하고 연결된 권한에 따라 리소스 접근을 허용하거나 거부해요. 부트스트랩 토큰은 모든 리소스와 API에 대한 무제한 권한을 가져요.

해당 Kubernetes secret에서 ACL 부트스트랩 토큰을 조회하고 환경 변수로 설정해요.

$ export CONSUL_HTTP_TOKEN=$(kubectl get --namespace consul secrets/consul-bootstrap-acl-token --template={{.data.token}} | base64 -d)

Consul 대상 주소를 설정해요.

$ export CONSUL_HTTP_ADDR=https://$(kubectl get services/consul-ui --namespace consul -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

Consul 클러스터와의 통신을 단순화하도록 SSL 검증 검사를 제거해요.

$ export CONSUL_HTTP_SSL_VERIFY=false

참고 (Note)

프로덕션 환경에서는 SSL 검증을 true로 유지할 것을 권장해요. 개발 환경과 데모 목적에서 TLS가 구성되지 않은 Consul 클러스터가 있는 경우에만 이 검증을 제거해요.

Consul 서비스 보기 (View Consul services)

이 섹션에서는 CLI, UI, 그리고/또는 API로 Consul 서비스를 확인해 서비스 메시의 세부 사항을 탐색해요.

CLI: CLI 명령 consul catalog services를 실행해 Consul에 등록된 서비스 목록을 반환해요. Consul 클러스터에서 실행 중인 유일한 서비스가 consul이므로 이것만 반환되는 점을 확인해요.

$ consul catalog services
consul

에이전트는 서버(server) 또는 클라이언트(client) 모드로 실행돼요. 서버 에이전트는 서비스와 노드 IP 주소, 헬스 체크, 구성을 포함한 모든 상태 정보를 저장해요. 클라이언트 에이전트는 데이터센터의 대부분을 구성하는 가벼운 프로세스예요. 클라이언트는 서비스 헬스 상태를 서버 에이전트에 보고해요. 클라이언트는 서비스가 실행되는 모든 파드에서 실행되어야 해요.

CLI 명령 consul members를 실행해 환경의 Consul 에이전트 목록을 반환해요.

$ consul members
Node             Address          Status  Type    Build        Protocol  DC   Partition  Segment
consul-server-0  10.0.4.117:8301  alive   server  1.14.0beta1  2         dc1  default    <all>
consul-server-1  10.0.5.11:8301   alive   server  1.14.0beta1  2         dc1  default    <all>
consul-server-2  10.0.4.55:8301   alive   server  1.14.0beta1  2         dc1  default    <all>

토큰 값을 터미널에 출력하고 클립보드에 복사해요. 이 ACL 토큰을 사용해 Consul UI에서 인증할 거예요.

$ echo $CONSUL_HTTP_TOKEN
fe0dd5c3-f2e1-81e8-cde8-49d26cee5efc

UI: 별도의 터미널 창을 열고 consul-ui 서비스 이름을 대상으로 kubectl port-forward를 사용해 Consul UI를 노출해요. 기본적으로 Consul UI는 TLS를 활성화하면 포트 6443, TLS를 비활성화하면 포트 8500에서 실행돼요.

$ kubectl port-forward svc/consul-ui --namespace consul 6443:443

브라우저에서 https://localhost:6443을 열어 Consul UI를 찾아요. 이 환경은 리소스에 자체 서명 TLS 인증서를 사용하므로 인증서 경고를 통과해 진행해요.

왼쪽 탐색 창에서 Services를 클릭해 배포된 서비스를 검토해요. 이 시점에는 consul 서비스만 찾을 수 있어요.

기본적으로 익명 ACL 정책은 Consul 서비스, 노드, 의도의 내용을 볼 수 있게 해요. Consul UI에서 변경하고 더 많은 세부 사항을 보려면 오른쪽 상단의 Log In을 클릭하고 부트스트랩 ACL 토큰을 입력해요.

ACL 토큰으로 인증에 성공하면 이제 UI에서 추가 Consul 구성 요소를 보고 변경할 수 있어요. 왼쪽 탐색 창의 Access Controls 섹션에서 더 많은 옵션을 보고 관리할 수 있음을 확인해요.

왼쪽 탐색 창에서 Nodes를 클릭해요.

에이전트는 서버 또는 클라이언트 모드로 실행돼요. 서버 에이전트는 서비스와 노드 IP 주소, 헬스 체크, 구성을 포함한 모든 상태 정보를 저장해요. 클라이언트 에이전트는 데이터센터의 대부분을 구성하는 가벼운 프로세스예요. 클라이언트는 서비스 헬스 상태를 서버 에이전트에 보고해요. 클라이언트는 서비스가 실행되는 모든 파드에서 실행되어야 해요.

API: Consul에 등록된 서비스 목록을 확인해요.

$ curl -k \
    --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
    $CONSUL_HTTP_ADDR/v1/catalog/services

샘플 출력:

{"consul":[]}

에이전트는 서버 또는 클라이언트 모드로 실행돼요. 서버 에이전트는 서비스와 노드 IP 주소, 헬스 체크, 구성을 포함한 모든 상태 정보를 저장해요. 클라이언트 에이전트는 데이터센터의 대부분을 구성하는 가벼운 프로세스예요. 클라이언트는 서비스 헬스 상태를 서버 에이전트에 보고해요. 클라이언트는 서비스가 실행되는 모든 파드에서 실행되어야 해요.

환경의 서버 및 클라이언트 Consul 에이전트 목록을 확인해요.

$ curl -k \
    --header "X-Consul-Token: $CONSUL_HTTP_TOKEN" \
    $CONSUL_HTTP_ADDR/v1/agent/members\?pretty

샘플 출력:

[
  {
    "Name": "consul-server-0",
    "Addr": "10.244.0.13",
    "Port": 8301,
    "Tags": {
      "acls": "1",
      "bootstrap": "1",
      "build": "1.14.0",
      "dc": "dc1",
      "ft_fs": "1",
      "ft_si": "1",
      "grpc_port": "8502",
      "id": "8016fc4d-767f-8552-b018-0812228bd135",
      "port": "8300",
      "raft_vsn": "3",
      "role": "consul",
      "segment": "",
      "use_tls": "1",
      "vsn": "2",
      "vsn_max": "3",
      "vsn_min": "2",
      "wan_join_port": "8302"
    },
    "Status": 1,
    "ProtocolMin": 1,
    "ProtocolMax": 5,
    "ProtocolCur": 2,
    "DelegateMin": 2,
    "DelegateMax": 5,
    "DelegateCur": 4
  }
  ## ...
]

Consul 카탈로그에 나열된 모든 서비스는 확장성 문제를 단순화하고 애플리케이션 복원력을 개선하는 Consul의 서비스 디스커버리 기능으로 강화돼요. 자세한 내용은 서비스 디스커버리 개요 페이지를 검토해요.

다음 단계 (Next steps)

Azure Kubernetes Service(AKS) 클러스터에 Consul 데이터센터를 배포하는 방법을 배웠어요. Consul 배포 후 CLI, UI, API로 Consul과 상호작용했어요.

배포 모범 사례에 대해 더 알아보려면 Kubernetes 참조 아키텍처 튜토리얼을 검토해요.

더 알아보기 (Learn more)