Kind로 로컬 Kubernetes 클러스터에 Consul 배포

Kind로 로컬 Kubernetes 클러스터에 Consul 배포

이 주제에서는 kind로 로컬 Kubernetes 클러스터를 만들고 생성된 클러스터에 Consul 데이터센터를 배포하는 방법을 설명해요. 배포 후에는 CLI, UI, API로 Consul과 상호작용해요.

출처: 문서

본문

이 주제에서는 kind로 로컬 Kubernetes 클러스터를 만들고 클러스터에 Consul 데이터센터를 배포하는 방법을 설명합니다. Consul을 배포한 후에는 CLI, UI 및/또는 API로 Consul과 상호작용합니다.

요구 사항 (Requirements)

Minikube에 Consul을 배포하려면 다음이 필요합니다.

Kind 클러스터 생성

kind를 사용하면 로컬 Kubernetes 클러스터를 빠르게 만들 수 있습니다. 기본적으로 kind는 클러스터 이름을 "kind"로 지정하지만, --name 옵션을 지정하면 원하는 이름으로 정할 수 있습니다. 이 지침은 클러스터 이름이 dc1이라고 가정합니다. YAML 구성 파일로 추가 매개변수를 지정하는 방법에 대한 정보는 kind 문서를 참조하세요.

$ kind create cluster --name dc1
Creating cluster "dc1" ...
 ✓ Ensuring node image (kindest/node:v1.25.1) 🖼
 ✓ Preparing nodes 📦
 ✓ Writing configuration 📜
 ✓ Starting control-plane 🕹️
 ✓ Installing CNI 🔌
 ✓ Installing StorageClass 💾
Set kubectl context to "kind-dc1"
You can now use your cluster with:

kubectl cluster-info --context kind-dc1

Have a nice day! 👋

Consul 배포

공식 Consul Helm chart 또는 Consul K8S CLI를 사용해 완전한 Consul 데이터센터를 배포할 수 있습니다. chart에는 합리적인 기본값이 있지만 kind와 더 쉽게 통합하고 유용한 기능을 활성화하기 위해 몇 가지 값을 재정의하게 됩니다. 이러한 설치 옵션에 대해 더 알아보려면 Consul Kubernetes 설치 문서를 검토하세요.

values 파일 생성

배포를 사용자 지정하려면 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: 1
# Contains values that configure the Consul UI.
ui:
  enabled: true
  # Registers a Kubernetes Service for the Consul UI as a NodePort.
  service:
    type: NodePort

클러스터에 Consul 설치

이제 공식 Consul Helm chart 또는 Consul K8S CLI를 사용해 Kubernetes 클러스터에 완전한 Consul 데이터센터를 배포할 수 있습니다.

consul-k8s로 kind 클러스터에 Consul을 설치하세요. 메시지가 표시되면 y로 설치를 확인합니다.

$ consul-k8s install -config-file=values.yaml -set global.image=hashicorp/consul:1.15.1
## ...
Proceed with installation? (y/N) y

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

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

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

CLI가 Consul 클러스터와 상호작용하도록 구성

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

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

해당 Kubernetes 시크릿에서 ACL 부트스트랩 토큰을 검색하고 환경 변수로 설정하세요.

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

Consul 대상 주소를 설정하세요. 기본적으로 Consul은 http의 경우 포트 8500, https의 경우 8501에서 실행됩니다.

$ export CONSUL_HTTP_ADDR=https://127.0.0.1:8501

Consul 클러스터와의 통신을 단순화하기 위해 SSL 검증 확인을 제거합니다.

$ export CONSUL_HTTP_SSL_VERIFY=false

참고

프로덕션 환경에서는 이 SSL 검증을 true로 유지하는 것이 좋습니다. TLS가 구성되지 않은 Consul 클러스터에 대해 개발 환경과 데모 목적으로만 이 검증을 제거하세요.

Consul 서비스 보기

이 섹션에서는 CLI, UI 및/또는 API로 Consul 서비스를 확인하여 서비스 메시의 세부 정보를 탐색합니다.

별도의 터미널 창을 열고 kubectl port-forward로 consul-ui 서비스 이름을 대상으로 사용해 Consul 서버를 노출하세요.

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

원래 터미널에서 consul catalog services CLI 명령을 실행하면 Consul에 등록된 서비스 목록이 반환됩니다. Consul 클러스터에서 실행 중인 유일한 서비스가 consul이므로 consul 서비스만 반환됩니다.

$ consul catalog services
consul

에이전트는 서버 또는 클라이언트 모드로 실행됩니다. 서버 에이전트는 서비스 및 노드 IP 주소, 헬스 체크, 구성을 포함한 모든 상태 정보를 저장합니다. 클라이언트 에이전트는 데이터센터의 대부분을 구성하는 경량 프로세스입니다. 서버 에이전트에 서비스 헬스 상태를 보고합니다. 서비스가 실행되는 모든 pod에서 클라이언트를 실행해야 합니다.

consul members CLI 명령을 실행하면 환경의 Consul 에이전트 목록이 반환됩니다.

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

Consul 카탈로그에 나열된 모든 서비스는 확장성 문제를 단순화하고 애플리케이션 복원력을 향상시키는 Consul의 서비스 발견 기능을 활용할 수 있습니다. 자세한 내용은 Service Discovery 개요 페이지를 참조하세요.

정리 (Clean up)

kind delete cluster를 실행하여 로컬 데모 환경을 정리하세요.

$ kind delete cluster --name dc1
Deleting cluster "dc1" ...

더 알아보기 (Learn more)