환경 설정 (Environment Set Up)
이 가이드는 개발, 테스트, 학습, 데모 목적의 로컬 환경을 구성하는 방법을 보여줍니다. Minikube 위에 NGINX 인그레스, Istio, Linkerd를 설치하고 호스트 헤더를 공급하는 방법까지 다룹니다.
출처: Argo Rollouts 문서
본문
Helm
일부 의존성은 Helm stable 저장소를 통해 설치할 수 있습니다:
helm repo add stable https://charts.helm.sh/stable
helm repo add grafana https://grafana.github.io/helm-charts
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
Minikube
NGINX Ingress Controller 설정
다음 지침은 minikube에서 NGINX Ingress Controller를 구성하는 방법을 설명합니다. 기본 인그레스 지원에는 "ingress" 애드온만 활성화하면 됩니다:
minikube addons enable ingress
선택적으로 Progressive Delivery 기능을 활용하기 위해 Prometheus와 Grafana를 설치할 수 있습니다:
# Install Prometheus
kubectl create ns monitoring
helm install prometheus prometheus-community/prometheus -n monitoring -f docs/getting-started/setup/values-prometheus.yaml
# Patch the ingress-nginx-controller pod so that it has the required
# prometheus annotations. This allows the pod to be scraped by the
# prometheus server.
kubectl patch deploy ingress-nginx-controller -n ingress-nginx -p "$(cat docs/getting-started/setup/ingress-nginx-controller-metrics-scrape.yaml)"
참고 (Note)
Minikube 버전 1.18.1 이하에서는
-n 파라미터 값(네임스페이스)을 kube-system으로 변경하세요.
# Install grafana along with nginx ingress dashboards
helm install grafana grafana/grafana -n monitoring -f docs/getting-started/setup/values-grafana-nginx.yaml
# Grafana UI can be accessed by running:
minikube service grafana -n monitoring
Istio 설정
다음 지침은 minikube에서 Istio를 구성하는 방법을 설명합니다.
# Istio on Minikube requires additional memory and CPU
minikube start --memory=8192mb --cpus=4
# Install istio
minikube addons enable istio-provisioner
minikube addons enable istio
# Label the default namespace to enable istio sidecar injection for the namespace
kubectl label namespace default istio-injection=enabled
Istio에는 이미 사용할 준비가 된 Prometheus 데이터베이스가 함께 제공됩니다. istio 서비스에 대한 메트릭을 시각화하려면 Helm을 통해 Grafana와 Istio 대시보드를 설치해 Progressive Delivery 기능을 활용할 수 있습니다:
# Install Grafana and Istio dashboards
helm install grafana grafana/grafana -n istio-system -f docs/getting-started/setup/values-grafana-istio.yaml
# Grafana UI can be accessed by running
minikube service grafana -n istio-system
트래픽이 Istio mesh로 들어가려면 요청이 Istio 인그레스 게이트웨이를 거쳐야 합니다. 이 게이트웨이는 단순히 일반 Kubernetes Deployment와 Service입니다. minikube에서 게이트웨이에 도달하는 편리한 방법 중 하나는 minikube tunnel 명령을 사용하는 것입니다. 이 명령은 Service에 LoadBalancer를 할당합니다. 이 명령은 보통 별도의 터미널 창에서 백그라운드로 실행해야 합니다:
minikube tunnel
minikube tunnel을 실행하는 동안 istio-ingressgateway Service는 kubectl로 검색할 수 있는 외부 IP를 갖게 됩니다:
$ kubectl get svc -n istio-system istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.100.136.45 10.100.136.45 15020:31711/TCP,80:31298/TCP.... 7d22h
LoadBalancer 외부 IP(이 예제에서는 10.100.136.45)에 이제 Istio mesh의 서비스에 접근할 수 있게 됩니다. Istio는 Host HTTP 헤더를 기반으로 요청을 올바른 Pod로 라우팅합니다. 클라이언트 환경이 올바른 요청을 공급해 Pod에 도달하도록 구성하는 방법은 호스트 헤더 공급 가이드를 따르세요.
Linkerd 설정
Linkerd는 linkerd CLI를 사용해 설치할 수 있습니다.
brew install linkerd
linkerd install | kubectl apply -f -
Linkerd는 자체 인그레스 컨트롤러를 제공하지 않고, 선택한 인그레스 컨트롤러와 함께 동작하도록 설계되었습니다. minikube에서는 내장 NGINX 인그레스 애드온을 사용하고 이를 linkerd mesh의 일부가 되도록 재구성할 수 있습니다.
# Install the NGINX ingress controller addon
minikube addons enable ingress
# Patch the nginx-ingress-controller deployment to allow injection of the linkerd proxy to the
# pod, so that it will be part of the mesh.
kubectl patch deploy ingress-nginx-controller -n kube-system \
-p '{"spec":{"template":{"metadata":{"annotations":{"linkerd.io/inject":"enabled"}}}}}'
호스트 헤더 공급 (Supplying Host Headers)
대부분의 인그레스 컨트롤러와 서비스 메시 구현은 요청에 공급된 Host HTTP 요청 헤더에 의존하여 요청을 올바른 Pod로 라우팅합니다.
호스트네임-IP 매핑 결정
Host 헤더가 요청에 설정되려면 서비스의 호스트네임이 인그레스 또는 서비스 메시의 공개 IP 주소로 해석되어야 합니다. 인그레스 컨트롤러를 사용하는지 서비스 메시를 사용하는지에 따라 올바른 호스트네임-IP 매핑을 결정하는 다음 기법 중 하나를 사용하세요:
인그레스 (Ingresses)
일반 Kubernetes Ingress를 통해 클러스터 네트워크에 도달하는 트래픽의 경우, 호스트네임은 인그레스의 IP로 매핑되어야 합니다. kubectl로 Ingress 객체 자체에서 인그레스의 외부 IP를 검색할 수 있습니다:
$ kubectl get ing rollouts-demo-stable
NAME CLASS HOSTS ADDRESS PORTS AGE
rollouts-demo-stable <none> rollouts-demo.local 192.168.64.2 80 80m
위 예제에서 호스트네임 rollouts-demo.local은 IP 192.168.64.2로 해석되도록 구성해야 합니다. 다음 섹션에서는 로컬 시스템이 호스트네임을 원하는 IP로 해석하도록 구성하는 다양한 방법을 설명합니다.
Istio
Istio의 경우 트래픽은 mesh의 가장자리에 있는 로드 밸런서인 Ingress Gateway를 통해 mesh로 들어갑니다.
올바른 호스트네임-IP 매핑을 결정하는 것은 VirtualService와 Gateway에 무엇이 구성되었는지에 크게 달려 있습니다. Istio getting started 가이드를 따르고 있다면 예제는 "default" istio 인그레스 게이트웨이를 사용하며, 이는 kubectl로 얻을 수 있습니다:
$ kubectl get svc -n istio-system istio-ingressgateway
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
istio-ingressgateway LoadBalancer 10.100.136.45 10.100.136.45 15020:31711/TCP,80:31298/TCP.... 7d22h
위 예제에서 호스트네임 rollouts-demo.local은 IP 10.100.136.45로 해석되도록 구성해야 합니다. 다음 섹션에서는 로컬 시스템이 호스트네임을 원하는 IP로 해석하도록 구성하는 다양한 방법을 설명합니다.
로컬 호스트네임 해석 구성
올바른 호스트네임-IP 매핑을 결정했으므로, 이제 시스템이 올바르게 해석하도록 구성하는 다음 단계가 필요합니다. 이를 위한 다양한 기법이 있습니다:
DNS 항목
실제 프로덕션 환경에서는 Host 헤더가 일반적으로 DNS 서버에 호스트네임에 대한 DNS 항목을 추가하여 달성됩니다. 그러나 로컬 개발에서는 일반적으로 쉽게 접근할 수 있는 옵션이 아닙니다.
/etc/hosts 항목
로컬 워크스테이션에서는 인그레스의 호스트네임과 IP 주소를 매핑하도록 /etc/hosts에 로컬 항목을 추가할 수 있습니다. 예를 들어 다음은 rollouts-demo.local을 IP 10.100.136.45로 매핑하는 /etc/hosts 파일의 예입니다.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
10.100.136.45 rollouts-demo.local
호스트 항목 사용의 장점은 모든 클라이언트(CLI, 브라우저)에서 동작한다는 것입니다. 반면 IP 주소가 자주 변경되면 유지 관리하기가 더 어렵습니다.
Curl에서 헤더 공급
curl 같은 클라이언트는 헤더를 명시적으로 설정할 수 있습니다(curl의 -H 플래그). 예를 들어:
$ curl -I -H 'Host: rollouts-demo.local' http://10.100.136.45/color
HTTP/1.1 200 OK
content-type: text/plain; charset=utf-8
x-content-type-options: nosniff
date: Wed, 24 Jun 2020 08:44:59 GMT
content-length: 6
x-envoy-upstream-service-time: 1
server: istio-envoy
헤더 없이 동일한 요청을 하면 404 Not Found 오류로 실패합니다.
$ curl -I http://10.100.136.45/color
HTTP/1.1 404 Not Found
date: Wed, 24 Jun 2020 08:46:07 GMT
server: istio-envoy
transfer-encoding: chunked
브라우저 확장
curl이 헤더를 명시적으로 설정하는 것처럼 브라우저도 브라우저 확장을 통해 이를 달성할 수 있습니다. 이를 수행할 수 있는 브라우저 확장의 예는 ModHeader입니다.
더 알아보기 (Learn more)
- Migrating to Rollouts — Deployment에서 Rollout으로 전환하기
- Traefik 트래픽 관리 — 인그레스 기반 카나리 라우팅
- Ambassador 트래픽 관리 — 엣지 스택 카나리 라우팅
- Controller Metrics — Prometheus/Grafana로 메트릭 시각화