1. Istion 구성
- Istio는 Kubernetes CRD(Kubernetes API의 extension)를 사용하기 때문에 Kubernetes yaml 파일로 구성할 수 있다.
- 서비스 간 통신을 위한 기본 CRD: Virtual Service, Destination Rule
- Virtual Service: 어느 서비스로 트래픽을 라우팅할지 결정
- Destination Rule: 트래픽을 어떻게 보낼지 정의 (EX: 서킷브레이킹, 트래픽 미러링, 트래픽 시프팅 등)
2. Istion Traffic Flow
- CRD 생성
- Istio는 고수준 라우팅 규칙을 Envoy 특정 구성으로 변환
- 구성은 프록시 사이드카로 전파
- 프록시들은 Istio Control Plane에 연결하지 않고도 통신 가능
- 프록시들은 요청에 대한 모든 측정 항목과 추적 정보를 수집하고 이를 Control Plane으로 다시 보냄으로 애플리케이션에 대한 모니터링이 자동으로 이뤄진다.
3. Istio 설치 및 BookInfo 예제 실습
3-1. Istio 다운로드
curl -L https://istio.io/downloadIstio | sh -
cd istio-1.21.0
export PATH=$PWD/bin:$PATH
istioctl version
3-2. Istio 설치
- Istio 설치 시 목적별로 구성된 Profile을 사용한다.
- 기본 제공 Profile 또는 사용자 정의 Profile을 사용할 수 있으며, Profile에 따라 필요한 컴포넌트들이 설치된다.
- 네임스페이스에 Label를 지정함으로서 해당 네임스페이스에 애플리케이션 배포 시 Envoy Sidecar Proxy가 자동으로 추가된다.
# demo 구성 프로필을 사용하여 Istio 설치
istioctl install --set profile=demo -y
# 네임스페이스에 라벨 추가
kubectl label namespace default istio-injection=enabled
- Istio 설치가 완료되면 istio-system 네임스페이스 및 관련 리소스들이 생성된다.
3-3. 샘플 애플리케이션 배포
# Bookinfo 샘플 애플리케이션 배포
kubectl apply -f samples/bookinfo/platform/kube/bookinfo.yaml
# 쿠버네티스에 배포된 svc,pod 확인
kubectl get services,pods
# 앱이 클러스터 내에서 정상적으로 작동하는지 확인
kubectl exec "$(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}')" -c ratings -- curl -sS productpage:9080/productpage | grep -o "<title>.*</title>"
- Sidecar가 함께 생성되기 때문에 모든 Pod에서 2개의 컨테이너가 실행된다.
3-4. 외부 트래픽에 대한 애플리케이션 열기
- 현재 배포된 애플리케이션은 외부에서 액세스할 수가 없어 Istio Ingress Gateway를 생성해야 한다.
# Istio Ingress Gateway 생성
kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
# 구성에 문제가 없는지 확인
istioctl analyze
- yaml을 통해 배포하면 CustomResource인 gateway와 virtualservice가 배포되어 있는 것을 확인할 수 있다.
- gateway
- 외부로부터 트래픽을 받는 최앞단이다.
- 트래픽을 받을 호스트명과 포트, 프로토콜을 정의한다.
- virtualservice
- Envoy 프록시가 어떤 destination(k8s service)로 트래픽을 라우팅할지 결정한다.
- URI 기반으로 라우팅을 하는 Ingress와 유사하다.
- gateway
더보기
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: bookinfo-gateway
spec:
# The selector matches the ingress gateway pod labels.
# If you installed Istio using Helm following the standard documentation, this would be "istio=ingress"
selector:
istio: ingressgateway # use istio default controller
servers:
- port:
number: 8080
name: http
protocol: HTTP
hosts:
- "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: bookinfo
spec:
hosts:
- "*"
gateways:
- bookinfo-gateway # 해당 VirtualService는 bookinfo-gateway를 통해서 들어온 모든 요청에 대해서 처리
http:
- match:
- uri:
exact: /productpage #exact로 정의 되어 있기 때문에 이 URL로 매칭 되는 요청에 대해 라우팅 처리
- uri:
prefix: /static #prefix로 정의 되어 있기 때문에 /static URI로 시작하는 요청에 대해 라우팅 처리
- uri:
exact: /login
- uri:
exact: /logout
- uri:
prefix: /api/v1/products
route:
- destination:
host: productpage # productpage 서비스 9080으로 포워딩
port:
number: 9080
3-5. 수신 IP 및 포트 확인
# istio-ingressgateway의 외부 IP 확인
kubectl get svc istio-ingressgateway -n istio-system
# 외부 LB가 있을 경우 다음 명령어 사용
export INGRESS_HOST=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')
export SECURE_INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="https")].port}')
# GATEWAY_URL 지정
export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
echo "$GATEWAY_URL"
3-6. 외부 액세스 확인
- 하기 명령어를 통해 Bookinfo 애플리케이션 주소를 확인한 후 웹 페이지에서 정상적으로 표시되는지 확인한다.
# Bookinfo 애플리케이션의 외부 주소 확인
echo "http://$GATEWAY_URL/productpage"
3-7. 대시보드 확인
- Kiali: K8s서비스 간의 트래픽을 가시화 Istio의 컴포넌트 간 트래픽과 Service Mesh를 시각화 및 모니터링 할 수 있는 콘솔
# Kiali 및 기타 애드온 설치
kubectl apply -f samples/addons
kubectl rollout status deployment/kiali -n istio-system
# Kiali 대시보드에 액세스
istioctl dashboard kiali
- Kiali 대시보드는 샘플 애플리케이션의 서비스 간 관계와 메시의 개요를 보여준다.
- 또한, 트래픽 흐름을 시각화하는 필터도 제공한다.
- Display 항목 중 'Traffic Distribution'을 선택하면 트래픽 백분율을 확인할 수 있다.
- Application, Workloads, Service에서 현재 배포되어 있는 리소스를 확인할 수 있다.
- Workloads에서 Pod들의 Log, In/outbound Metrics 확인도 가능하다.
참고
'Container > Kubernetes' 카테고리의 다른 글
[Kubernetes] ELK Stack 개념 (0) | 2024.04.29 |
---|---|
[Kubernetes] Probe - Liveness, Readiness, Startup (0) | 2024.04.08 |
[Kubernetes] MSA 및 Service Mash 소개 (0) | 2024.04.03 |
[Kubernetes] Prometheus & Grafana를 통한 Kubernetes 모니터링 설정 (0) | 2024.03.18 |
[Kubernetes] AKS 클러스터 노드 접속 방법 (0) | 2024.03.07 |