본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

환경 설정 (Environment Set Up)

원문 보기 위키 갱신

이 가이드는 개발, 테스트, 학습 또는 데모 목적으로 로컬 환경을 설정하는 방법을 보여줘요. Helm, Minikube(NGINX Ingress, Istio, Linkerd), 호스트 헤더 전달 방법을 다뤄요.

출처: 문서

본문

이 가이드는 개발, 테스트, 학습 또는 데모 목적으로 로컬 환경을 설정하는 방법을 보여줘요.

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 Setup

다음 안내는 minikube에서 NGINX Ingress Controller를 구성하는 방법을 설명해요. 기본 ingress 지원에는 "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 Setup

다음 안내는 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 메시로 들어오려면 요청이 Istio ingress gateway를 통과해야 해요. 이 게이트웨이는 단순히 일반적인 Kubernetes Deployment와 Service예요. minikube에서 게이트웨이에 도달하는 편리한 방법 중 하나는 minikube tunnel 명령을 사용하는 것이에요. 이 명령은 Services에 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 메시의 서비스에 접근하는 데 사용할 수 있어요. Istio는 Host HTTP 헤더를 기반으로 요청을 올바른 Pod로 라우팅해요. 호스트 헤더를 올바르게 공급해 Pod에 도달하도록 클라이언트 환경을 구성하는 방법은 호스트 헤더 제공 가이드를 참고해요.

Linkerd Setup

Linkerd는 linkerd CLI를 사용해 설치할 수 있어요.

brew install linkerd
linkerd install | kubectl apply -f -

Linkerd는 자체 ingress controller를 제공하지 않으며, 대신 선택한 ingress controller와 함께 동작하도록 설계됐어요. minikube에서는 내장 NGINX ingress 애드온을 사용하고 이를 linkerd 메시의 일부가 되도록 재구성할 수 있어요.

# 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

대부분의 ingress controller와 service mesh 구현은 요청을 올바른 Pod로 라우팅하는 방법을 결정하기 위해 요청에 Host HTTP 요청 헤더가 공급되는 데 의존해요.

Determining the hostname to IP mapping

요청에 Host 헤더가 설정되려면 서비스의 호스트 이름이 ingress 또는 service mesh의 공개 IP 주소로 해석되어야 해요. ingress controller를 사용하는지 service mesh를 사용하는지에 따라 다음 기법 중 하나를 사용해 올바른 호스트 이름 대 IP 매핑을 결정해요:

Ingresses

일반적인 Kubernetes Ingress를 통해 클러스터 네트워크에 도달하는 트래픽의 경우, 호스트 이름은 ingress의 IP로 매핑되어야 해요. kubectl을 사용해 Ingress 객체 자체에서 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의 경우 트래픽은 메시 가장자리에 있는 로드 밸런서인 Ingress Gateway를 통해 메시로 들어와요.

올바른 호스트 이름 대 IP 매핑을 결정하는 것은 VirtualService와 Gateway에서 구성된 내용에 크게 달려 있어요. Istio 시작하기 가이드를 따르는 경우, 예제는 kubectl에서 얻을 수 있는 "default" istio ingress gateway를 사용해요:

$ 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로 해석하도록 구성하는 다양한 방법을 설명해요.

Configuring local hostname resolution

이제 올바른 호스트 이름 대 IP 매핑을 결정했습니다. 다음 단계는 올바르게 해석되도록 시스템을 구성하는 것이에요. 이를 위한 여러 기법이 있어요:

DNS Entry

실제 프로덕션 환경에서 Host 헤더는 일반적으로 DNS 서버의 호스트 이름에 대한 DNS 항목을 추가해 달성돼요. 하지만 로컬 개발에서는 대개 쉽게 접근할 수 있는 옵션이 아니에요.

/etc/hosts Entry

로컬 워크스테이션에서는 ingress의 호스트 이름과 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

host 항목을 사용할 때의 장점은 모든 클라이언트(CLI, 브라우저)에서 동작한다는 점이에요. 반면 IP 주소가 자주 변경되면 유지 관리가 더 어려워져요.

Supply Header in 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

Browser Extension

curl이 헤더를 명시적으로 설정할 수 있는 것과 비슷하게, 브라우저도 브라우저 확장 프로그램을 통해 이를 달성할 수 있어요. 이를 할 수 있는 브라우저 확장 프로그램의 한 예는 ModHeader예요.

더 알아보기 (Learn more)