OpenShift에 Consul 배포
OpenShift에 Consul 배포
OpenShift Kubernetes 클러스터에 Consul 데이터센터를 배포하는 과정을 설명하는 문서예요. OpenShift Local을 사용해 로컬 개발 환경에서부터 Helm 차트로 배포하는 전 과정을 다뤄요.
출처: 문서
본문
이 페이지는 OpenShift Kubernetes 클러스터에 Consul 데이터센터를 배포하는 과정을 설명해요.
개요 (Overview)
Red Hat OpenShift는 다양한 사용성과 보안 개선을 제공하는 Kubernetes 플랫폼의 배포판이에요. OpenShift 클러스터에 Consul을 배포하는 과정은 Kubernetes에서의 과정과 비슷해요.
이 지침은 새 OpenShift 클러스터를 배포하는 과정으로 시작해요. 이미 실행 중인 OpenShift 클러스터가 있다면 Consul 배포로 건너뛰어 Helm 차트 구성을 시작하세요.
요구 사항 (Requirements)
OpenShift에 Consul을 배포하려면 다음이 필요해요:
- OpenShift로 배포된 Kubernetes 클러스터에 대한 접근
- Red Hat 계정
- Red Hat OpenShift Local 2.49.0
- consul v1.20.5+
- Helm v3.17.2+
- consul-k8s v1.6.3+
OpenShift 배포 (Deploy OpenShift)
OpenShift는 여러 플랫폼에 배포할 수 있으며, 프로덕션 및 개발 환경에 OpenShift를 설치하는 다양한 설치 옵션이 있어요. 이 가이드는 Kubernetes에 Consul을 배포하기 위해 실행 중인 OpenShift 클러스터가 필요해요. Kubernetes에 Consul을 배포하는 데 사용할 OpenShift 클러스터가 프로덕션이나 개발 환경에 이미 프로비저닝되어 있다면 Consul 배포로 건너뛰세요.
이 지침은 로컬 머신에 사전 구성된 개발용 OpenShift 환경을 제공하는 OpenShift Local을 사용해요. OpenShift Local은 Linux, macOS, Windows 10용 네이티브 하이퍼바이저를 지원하는 Red Hat Enterprise Linux 가상 머신으로 번들되어 있어요. OpenShift Local은 OpenShift 클러스터 구축을 시작하는 가장 빠른 방법이에요. 설정을 단순화하고 컨테이너 기반 앱 개발에 필요한 모든 도구와 함께 클라우드 개발 환경을 로컬에서 에뮬레이션하도록 설계되었어요. 여기서는 OpenShift Local을 사용하지만, Consul Helm 배포 프로세스는 어떤 OpenShift 클러스터에서도 동작하며 프로덕션 준비가 되어 있어요.
OpenShift Local 설정 (OpenShift Local Setup)
OpenShift Local을 설치한 후 다음 명령을 실행해 환경을 설정해요.
$ crc setup
INFO Using bundle path /Users/hashicorp/.crc/cache/crc_vfkit_4.17.14_arm64.crcbundle
INFO Checking if running macOS version >= 13.x
INFO Checking if running as non-root
INFO Checking if crc-admin-helper executable is cached
INFO Checking if running on a supported CPU architecture
INFO Checking if crc executable symlink exists
INFO Checking minimum RAM requirements
INFO Check if Podman binary exists in: /Users/hashicorp/.crc/bin/oc
INFO Checking if running emulated on Apple silicon
INFO Checking if vfkit is installed
INFO Checking if CRC bundle is extracted in '$HOME/.crc'
INFO Checking if /Users/hashicorp/.crc/cache/crc_vfkit_4.17.14_arm64.crcbundle exists
INFO Getting bundle for the CRC executable
INFO Downloading bundle: /Users/hashicorp/.crc/cache/crc_vfkit_4.17.14_arm64.crcbundle...
4.86 GiB / 4.86 GiB [---------------------------------------] 100.00% 1.81 MiB/s
INFO Uncompressing /Users/hashicorp/.crc/cache/crc_vfkit_4.17.14_arm64.crcbundle
crc.img: 31.00 GiB / 31.00 GiB [-------------------------------------------------------------] 100.00%
oc: 125.37 MiB / 125.37 MiB [----------------------------------------------------------------] 100.00%
INFO Checking if old launchd config for tray and/or daemon exists
INFO Checking if crc daemon plist file is present and loaded
INFO Adding crc daemon plist file and loading it
INFO Checking SSH port availability
Your system is correctly setup for using CRC. Use 'crc start' to start the instance
OpenShift Local 시작 (OpenShift Local start)
설정이 완료된 후 다음 명령으로 OpenShift Local을 실행하는 CRC 서비스를 시작할 수 있어요. 이 명령은 시스템이 최소 요구 사항을 충족하는지 확인하는 몇 가지 시스템 검사를 수행한 다음 이미지 풀 시크릿(image pull secret)을 입력하도록 요청해요. Red Hat 계정을 열어서 메시지가 표시될 때 이미지 풀 시크릿을 쉽게 복사할 수 있게 해두세요.
$ crc start
INFO Using bundle path /Users/hashicorp/.crc/cache/crc_vfkit_4.17.14_arm64.crcbundle
INFO Checking if running macOS version >= 13.x
INFO Checking if running as non-root
INFO Checking if crc-admin-helper executable is cached
INFO Checking if running on a supported CPU architecture
INFO Checking if crc executable symlink exists
INFO Checking minimum RAM requirements
INFO Check if Podman binary exists in: /Users/hashicorp/.crc/bin/oc
INFO Checking if running emulated on Apple silicon
INFO Checking if vfkit is installed
INFO Checking if old launchd config for tray and/or daemon exists
INFO Checking if crc daemon plist file is present and loaded
INFO Checking SSH port availability
INFO Loading bundle: crc_vfkit_4.17.14_arm64...
CRC requires a pull secret to download content from Red Hat.
You can copy it from the Pull Secret section of https://console.redhat.com/openshift/create/local.
? Please enter the pull secret
다음으로 이미지 풀 시크릿을 터미널에 붙여넣고 엔터를 누른 다음 프로세스가 완료될 때까지 기다려요.
INFO Creating CRC VM for OpenShift 4.17.14...
INFO Generating new SSH key pair...
INFO Generating new password for the kubeadmin user
##...
Started the OpenShift cluster.
The server is accessible via web console at:
https://console-openshift-console.apps-crc.testing
Log in as administrator:
Username: kubeadmin
Password: <redacted>
Log in as user:
Username: developer
Password: developer
Use the 'oc' command line interface:
$ eval $(crc oc-env)
$ oc login -u developer https://api.crc.testing:6443
출력이 oc-env를 구성하라고 안내하고 로그인 명령과 시크릿 비밀번호도 포함되어 있음을 주목하세요. 시크릿은 설치마다 다르며 특정한 값이에요. 이 명령을 메모해 두세요. 나중에 개발 호스트에서 OpenShift Local(CRC)에 로그인하는 데 필요해요.
OpenShift Local(CRC) 환경 구성 (Configure OpenShift Local (CRC) environment)
다음으로 CRC가 안내한 대로 다음 명령을 사용해 환경을 구성해요.
$ eval $(crc oc-env)
OpenShift 클러스터에 로그인 (Login to the OpenShift cluster)
다음으로 아까 메모해 둔 로그인 명령을 사용해 OpenShift 클러스터에 인증해요.
참고 아래의 시크릿 비밀번호를 OpenShift Local CRC가 출력한 값으로 바꿔야 해요.
$ oc login -u kubeadmin -p <redacted> https://api.crc.testing:6443
Login successful.
You don't have any projects. You can try to create a new project, by running
oc new-project <projectname>
구성 확인 (Verify configuration)
다음 명령으로 OpenShift Local CRC 설정이 성공했는지 검증해요.
$ kubectl cluster-info
Kubernetes control plane is running at https://api.crc.testing:6443
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
새 프로젝트 만들기 (Create a new project)
먼저 Kubernetes에 Consul을 설치할 OpenShift 프로젝트를 만들어요. OpenShift 프로젝트를 만들면 Kubernetes 리소스를 배포할 Kubernetes 네임스페이스가 생성돼요.
$ oc new-project consul
Now using project "consul" on server "https://api.crc.testing:6443".
You can add applications to this project with the 'new-app' command. For example, try:
oc new-app rails-postgresql-example
to build a new example application in Ruby. Or use kubectl to deploy a simple Kubernetes application:
kubectl create deployment hello-node --image=registry.k8s.io/e2e-test-images/agnhost:2.43 -- /agnhost serve-hostname
RedHat Registry 서비스 어카운트용 이미지 풀 시크릿 만들기
RedHat Registry에 인증하고 컨테이너 레지스트리에서 이미지를 가져오기 전에 이미지 풀 시크릿을 만들어야 해요. 먼저 RedHat 고객 포털에서 레지스트리 서비스 어카운트를 만들어요. 그런 다음 레지스트리 서비스 어카운트와 연결된 OpenShift 시크릿을 다운로드하고 적용해요. 다음 예시에서 다운로드한 파일의 이름은 15490118-openshift-secret.yml이었지만, 여러분의 파일 이름은 다를 거예요.
$ kubectl create -f 15490118-openshift-secret.yml --namespace=consul
secret/15490118-openshift-secret-secret created
Kubernetes 시크릿 생성 확인 메시지와 함께 이름이 반환돼요. 지금 이 이름을 기록해 두세요. Helm 차트 값 파일, 특히 imagePullSecrets 스탠자에서 사용하게 돼요. 다음 예시에서 이름은 15490118-openshift-secret-secret이에요.
Consul 배포 (Deploy Consul)
OpenShift 클러스터에 Consul 서버를 배포하는 프로세스는 다음 단계로 구성돼요:
- Helm 값을 구성한다.
- Helm 차트 버전을 확인한다.
- RedHat 카탈로그에서 이미지를 가져온다.
- Helm 또는
consul-k8sCLI로 Consul을 설치한다.
Helm 값 구성 (Configure Helm values)
배포를 사용자 정의하려면 배포 중에 사용할 YAML 구성 파일을 전달할 수 있어요. 값 파일에 지정된 모든 값은 Helm 차트의 기본 설정을 재정의해요. 다음 예시 파일은 OpenShift에서 Consul을 운영하는 데 필요한 global.openshift.enabled 항목을 true로 설정해요.
values.yaml 파일을 만들고 배포에 맞게 수정해요. imagePullSecrets를 이전 단계에서 생성한 이름으로 수정하는 것을 잊지 마세요.
values.yaml
global:
name: consul
datacenter: dc1
image: registry.connect.redhat.com/hashicorp/consul:1.20.5-ubi
imagePullSecrets:
- name: <Insert image pull secret name for RedHat Registry Service Account>
openshift:
enabled: true
server:
replicas: 1
bootstrapExpect: 1
disruptionBudget:
enabled: true
maxUnavailable: 0
ui:
enabled: true
connectInject:
enabled: true
default: true
cni:
enabled: true
logLevel: info
multus: true
cniBinDir: /var/lib/cni/bin
cniNetDir: /etc/kubernetes/cni/net.d
차트 버전 확인 (Verify chart version)
로컬 리포지토리에서 Consul Helm 차트를 검색해요.
$ helm search repo hashicorp/consul
NAME CHART VERSION APP VERSION DESCRIPTION
hashicorp/consul 1.6.3 1.20.5 Official HashiCorp Consul Chart
출력에 올바른 버전이 표시되지 않으면 helm 리포지토리를 업데이트해 보세요.
$ helm repo update
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "hashicorp" chart repository
Update Complete. ⎈Happy Helming!⎈
RedHat 카탈로그에서 이미지 가져오기 (Import images from RedHat Catalog)
RedHat Registry에서 이미지를 직접 가져오는 대신, oc import 명령을 사용해 Consul 및 Consul on Kubernetes 이미지를 내부 OpenShift 레지스트리에 미리 로드할 수도 있어요. RedHat OpenShift 쿡북에서 내부 OpenShift 레지스트리로 이미지 가져오기에 대해 자세히 알아보세요.
$ oc import-image hashicorp/consul:1.20.5-ubi --from=registry.connect.redhat.com/hashicorp/consul:1.20.5-ubi --confirm
imagestream.image.openshift.io/consul imported
<output omitted for brevity>
$ oc import-image hashicorp/consul-k8s-control-plane:1.6.1-ubi --from=registry.connect.redhat.com/hashicorp/consul-k8s-control-plane:1.6.1-ubi --confirm
imagestream.image.openshift.io/consul-k8s-control-plane imported
<output omitted for brevity>
$ oc import-image hashicorp/consul-dataplane:1.6.1-ubi --from=registry.connect.redhat.com/hashicorp/consul-dataplane:1.6.1-ubi --confirm
imagestream.image.openshift.io/consul-dataplane imported
<output omitted for brevity>
클러스터에 Consul 설치 (Install Consul in your cluster)
이제 공식 Consul Helm 차트 또는 Consul K8S CLI를 사용해 Kubernetes 클러스터에 완전한 Consul 데이터센터를 배포할 수 있어요.
Helm
이제 helm install 명령을 실행해요. 다음 명령은 설치가 다음을 수행하도록 지정해요:
- 앞서 만든 커스텀 값 파일 사용
- 마지막 단계에서 다운로드한
hashicorp/consul차트 사용 - Consul 설치 이름을
consul로 설정 consul네임스페이스에 Consul 리소스 생성consul-helm차트 버전1.6.3사용
$ helm install consul hashicorp/consul --values values.yaml --create-namespace --namespace consul --version "1.6.3" --wait
출력은 다음과 비슷할 거예요.
NAME: consul
LAST DEPLOYED: Wed Sep 28 11:00:16 2022
NAMESPACE: consul
STATUS: deployed
REVISION: 1
NOTES:
Thank you for installing HashiCorp Consul!
Your release is named consul.
To learn more about the release, run:
$ helm status consul
$ helm get all consul
Consul on Kubernetes Documentation:
https://developer.hashicorp.com/docs/platform/k8s
Consul on Kubernetes CLI Reference:
https://developer.hashicorp.com/docs/reference/k8s/consul-k8s-cli
Consul K8S CLI (Linux and Mac)
Consul K8s CLI는 Kubernetes에서 Consul을 빠르게 설치하고 상호 작용하는 도구예요. CLI와 컨트롤 플레인은 버전에 의존하므로, Consul on Kubernetes 배포에 맞는 올바른 버전의 CLI를 설치하고 있는지 확인하세요.
Consul K8s CLI를 시작하려면 CLI를 로컬 시스템에 설치하는 지침을 따르세요. 추가 설정에 대해 알아보려면 Consul K8S CLI 문서를 참고하세요.
$ consul-k8s install -config-file=values.yaml
Consul이 성공적으로 설치되면 다음 출력이 예상돼요:
==> Installing Consul
✓ Downloaded charts
--> creating 1 resource(s)
--> creating 46 resource(s)
--> beginning wait for 46 resources with timeout of 10m0s
...
✓ Consul installed in namespace "consul".
설치 확인 (Verify installation)
kubectl get pods를 사용해 설치를 확인해요.
$ watch kubectl get pods --namespace consul
NAME READY STATUS RESTARTS AGE
consul-cni-45fgb 1/1 Running 0 3m
consul-connect-injector-574799b944-n6jf6 1/1 Running 0 3m
consul-connect-injector-574799b944-xvksv 1/1 Running 0 3m
consul-server-0 1/1 Running 0 3m
consul-webhook-cert-manager-74467cdd8d-88m6j 1/1 Running 0 3m
모든 파드의 상태가 Running이 되면 CTRL-C를 입력해 watch를 중지해요.
Consul UI 접근 (Access the Consul UI)
Consul을 배포한 후 Consul UI에 접근해 설치가 성공했는지, 환경이 정상인지 확인할 수 있어요.
UI 서비스를 호스트에 노출 (Expose the UI service to the host)
애플리케이션이 로컬 개발 호스트에서 실행 중이므로 kubectl port-forward를 사용해 Consul UI를 개발 호스트에 노출할 수 있어요. UI와 HTTP API 서버는 consul-server-0 파드에서 실행돼요. 다음 명령을 실행해 서버 엔드포인트를 포트 8500으로 로컬 개발 호스트에 노출하세요.
$ kubectl port-forward consul-server-0 --namespace consul 8500:8500
Forwarding from 127.0.0.1:8500 -> 8500
Forwarding from [::1]:8500 -> 8500
새 브라우저 탭에서 http://localhost:8500을 열어요.
CLI와 HTTP API로 Consul 접근 (Access Consul with the CLI and HTTP API)
CLI로 Consul에 접근하려면 개발 호스트의 CONSUL_HTTP_ADDR 환경 변수를 설정해 Consul CLI가 어떤 Consul 서버와 상호 작용할지 알도록 해요.
$ export CONSUL_HTTP_ADDR=http://127.0.0.1:8500
consul members 명령을 실행해 사용 가능한 모든 Consul 데이터센터 멤버를 확인할 수 있어야 해요.
$ consul members
Node Address Status Type Build Protocol DC Partition Segment
consul-server-0 10.217.0.106:8301 alive server 1.20.5 2 dc1 default <all>
crc-dzk9v-master-0 10.217.0.104:8301 alive client 1.20.5 2 dc1 default <default>
동일한 URL을 사용해 커스텀 코드로 HTTP API 요청을 보낼 수 있어요.
다음 단계 (Next steps)
생성한 Consul 서버는 아직 프로덕션 준비가 되지 않았어요. 차트는 여전히 보호해야 하는 안전하지 않은 Consul 구성으로 설치되었어요. 프로덕션 환경에서 사용하기 위해 Consul 서버를 보호하는 방법은 Consul 보안을 참고하세요.
Consul Helm 차트 구성 옵션에 대한 자세한 내용은 Consul Helm 차트 참조 문서를 검토하세요.