Kubernetes에 Consul 스냅샷 에이전트 설치
Kubernetes에 Consul 스냅샷 에이전트 설치 (Install Consul Snapshot Agent on Kubernetes)
이 주제는 공식 Helm 차트를 사용해 Kubernetes에 Consul 스냅샷 에이전트(Snapshot Agent)를 설치하는 방법을 설명해요. 스냅샷 에이전트는 서비스로 실행되며 Consul 서버 상태의 스냅샷을 생성해요. 스냅샷은 원자적(atomic)이고 시점(point-in-time) 단위로 생성돼요.
출처: 문서
본문
이 주제는 공식 Helm 차트를 사용해 Kubernetes에 Consul 스냅샷 에이전트를 설치하는 방법을 설명해요. Consul 스냅샷 에이전트는 서비스로 실행되며 Consul 서버 상태의 스냅샷을 생성해요. 스냅샷은 원자적이고 시점 단위로 생성돼요. Consul 스냅샷 에이전트는 이러한 스냅샷을 로컬에 저장하거나 선택적인 원격 스토리지 서비스로 푸시할 수 있어요. Consul 스냅샷에는 다음 항목이 포함되지만 이에 국한되지는 않아요:
- 키/값(Key/Value) 저장소 항목
- 서비스 카탈로그 등록
- 준비된 쿼리(Prepared queries)
- 세션(Sessions)
- 액세스 제어 목록(ACL)
- 네임스페이스(Namespaces)
스냅샷을 자동으로 생성하려면 Consul 스냅샷 에이전트가 필요해요. 스냅샷을 복원할 때 에이전트는 필요하지 않아요.
Enterprise
이 기능은 Consul Enterprise가 필요해요.
요구 사항 (Requirements)
Consul 스냅샷 에이전트는 Consul 클러스터 내에서 Consul 서버와 함께(동일 위치) 실행되어 서버의 nodeSelector, tolerations, affinity를 상속해야 해요.
Consul ACL 시스템이 부트스트랩되어 활성 상태라면 Consul 스냅샷 에이전트용 토큰을 생성해야 해요. 다음은 Consul 스냅샷 에이전트 토큰에 대한 허용적인 예시 정책이에요. 이 구성으로 토큰을 만드는 방법은 스냅샷 에이전트 토큰 생성을 참고해요.
# used for snapshot agent leader election
key_prefix "" {
policy = "write"
}
# used for registering the snapshot agent service
service_prefix "" {
policy = "write"
}
# used for snapshot agent leader election
session_prefix "" {
policy = "write"
}
# used for registering the snapshot agent node
node_prefix "" {
policy = "write"
}
acl = "write"
구성 (Configuration)
다음은 Consul 스냅샷 에이전트의 빈 예시 구성이에요. 모든 필드는 선택 사항이에요. 각 필드에 대한 자세한 내용은 Consul 스냅샷 에이전트 구성 파일 옵션을 참고해요.
consul-snapshot-agent.json:
{
"snapshot_agent": {
"token": "",
"datacenter": "",
"ca_file": "",
"ca_path": "",
"cert_file": "",
"key_file": "",
"license_path": "",
"tls_server_name": "",
"login": {
"auth_method": "",
"bearer_token": "",
"bearer_token_file": "",
"meta": {}
},
"log": {
"level": "INFO",
"enable_syslog": false,
"syslog_facility": "LOCAL0"
},
"snapshot": {
"interval": "1h",
"retain": 30,
"stale": false,
"service": "consul-snapshot",
"deregister_after": "72h",
"lock_key": "consul-snapshot/lock",
"max_failures": 3,
"local_scratch_path": ""
},
"backup_destinations": {
"local_storage": [
{
"path": "."
}
],
"aws_storage": [
{
"access_key_id": "",
"secret_access_key": "",
"session_token": "",
"iam_endpoint": "",
"role_arn": "",
"role_session_name": "",
"web_identity_token_file": "",
"sts_endpoint": "",
"s3_region": "",
"s3_endpoint": "",
"s3_bucket": "",
"s3_key_prefix": "consul-snapshot"
}
],
"azure_blob_storage": [
{
"account_name": "",
"account_key": "",
"container_name": ""
}
],
"google_storage": [
{
"bucket": ""
}
]
}
}
}
구성을 Kubernetes Secret으로 적용 (Apply configuration as a Kubernetes Secret)
Consul 스냅샷 에이전트 구성은 다양한 클라우드 스토리지 백엔드의 액세스 키와 Consul ACL 토큰 같은 민감한 정보를 포함할 수 있어요. 따라서 이 구성을 Kubernetes secret에 보관하는 것을 권장해요. 다음 명령을 사용해 로컬 구성 파일에서 Kubernetes secret을 생성해요:
K8s secret 생성:
# 명령 구조 (Command structure)
kubectl create secret generic <SECRET-NAME> --from-file=<SECRET-KEY>=<PATH-TO-SNAPSHOT-AGENT-CONFIG>
# 명령 예시 (Command example)
kubectl create secret generic consul-snapshot-agent --from-file=snapshot-agent-config="./consul-snapshot-agent.json"
Helm으로 Consul 스냅샷 에이전트 설치 (Install the Consul Snapshot agent using Helm)
Consul 스냅샷 에이전트는 Consul 서버의 사이드카로 실행돼요. Consul 스냅샷 에이전트 구성이 Kubernetes secret으로 존재하는지 확인한 다음, Helm 차트 값을 다음과 같이 수정해요.
기존 Consul 설치를 Consul 스냅샷 에이전트와 함께 업그레이드하는 경우 수정된 Helm 차트와 함께 helm upgrade 명령을 사용해요. 새 Consul 배포를 수행하는 경우 Kubernetes에 Consul Enterprise 배포를 참고해요.
consul-snapshot-agent.yaml:
server:
# snapshotAgent contains settings for setting up and running snapshot agents
# within the Consul clusters. They are required to be co-located with Consul
# clients, so will inherit the clients' nodeSelector, tolerations and affinity.
# This is an Enterprise feature only.
snapshotAgent:
enabled: true
# replicas determines how many snapshot agent pods are created
replicas: 2
# configSecret references the Kubernetes secret that you manually created to
# contain the entire config to be used on the snapshot agent.
# Snapshot agent config details:
# https://developer.hashicorp.com/consul/commands/snapshot/agent#config-file-options
configSecret:
secretName: consul-snapshot-agent
secretKey: snapshot-agent-config
# Resource settings for snapshot agent pods.
resources:
requests:
memory: '200Mi'
cpu: '100m'
limits:
memory: '200Mi'
cpu: '100m'
# Optional PEM-encoded CA certificate that will be added to the trusted system CAs.
# Useful if using an S3-compatible storage exposing a self-signed certificate.
# Example
# caCert: |
# -----BEGIN CERTIFICATE-----
# MIIC7jCCApSgAwIBAgIRAIq2zQEVexqxvtxP6J0bXAwwCgYIKoZIzj0EAwIwgbkx
# ...
caCert: null