devops/ETC

Istio - service mesh

gepp 2024. 6. 15. 15:32

 

Service Mesh


 

Service Mesh는 마이크로서비스 아키텍처에서 서비스 간의 통신을 관리하는 인프라 계층입니다.

즉 서비스 간의 상호작용을 더욱 효율적이고 안전하게 만들기 위해 다양한 기능을 제공합니다.

Service Mesh는 주로 다음과 같은 기능을 포함합니다:

트래픽 관리: 서비스 간의 트래픽을 제어하고 라우팅합니다. 이를 통해 A/B 테스트, 카나리아 배포, 트래픽 분할 등을 쉽게 구현할 수 있습니다.
서비스 디스커버리: 서비스 인스턴스가 동적으로 변경될 때 이를 자동으로 감지하고 업데이트합니다.
로드 밸런싱: 서비스 요청을 여러 인스턴스에 고르게 분산시켜 시스템의 부담을 줄입니다.
보안: 서비스 간 통신을 암호화하고 인증을 관리하여 보안성을 높입니다.
모니터링 및 로깅: 서비스 간의 통신 데이터를 수집하고 분석하여 성능 문제를 파악하고 문제를 해결하는 데 도움을 줍니다.
정책 관리: 서비스 간의 통신 규칙을 설정하고 적용합니다.
ETC: 또한 서비스 메시는 A/B 테스트, 카나리아 배포, 속도 제한, 액세스 제어, 암호화, 엔드투엔드 인증과 같은 보다 복잡한 운영 요구 사항을 해결하는 경우도 있습니다.
Service Mesh는 일반적으로 사이드카 패턴을 사용하여 구현됩니다. 각 서비스 인스턴스 옆에 프록시(사이드카 프록시)를 배치하고, 이 프록시가 서비스 간의 모든 트래픽을 처리합니다.

이를 통해서 애플리케이션 코드의 변경 없이 통신 기능을 추가할 수 있습니다.

대표적인 Service Mesh 솔루션으로는 Istio, Linkerd, Consul 등이 있습니다.

해당 도구로 마이크로서비스 환경에서의 복잡성을 줄이고,

개발자와 운영자가 더 쉽게 서비스 간의 통신을 관리할 수 있게됩니다.

 

 

 

How to use Istio Service Mesh in Kubernetes

 


 

 

Helm 으로 설치하기

kubectl create namespace istio-system

helm repo add istio https://istio-release.storage.googleapis.com/charts
helm repo update
helm install <release> <chart> --namespace <namespace> --create-namespace [--set <other_parameters>]
helm install istio-base istio/base -n istio-system --set defaultRevision=default

 

 

설치되면 다음과 같이 DEPLOYED 로 확인됩니다.

$ helm status istiod -n istio-system
NAME: istiod
LAST DEPLOYED: Fri Jan 20 22:00:44 2023
NAMESPACE: istio-system
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
"istiod" successfully installed!

 

또한 Istio 는 istioctl 명령어를 제공하여, 해당 명령어로 설치할 수도 있습니다.

설치하고 나중에 어플리케이션 배포하면 Istio가 Envoy sidecar 프록시를 주입시키도록 라벨을 정할 수 있습니다.

 

$ curl -L https://istio.io/downloadIstio | sh -
$ cd istio-<version>
$ export PATH=$PWD/bin:$PATH

$ istioctl install --set profile=demo -y

# Add a namespace label to instruct Istio to automatically inject Envoy sidecar proxies
$ kubectl label namespace default istio-injection=enabled

 

애플리케이션 배포 후, 바깥쪽에서 접근 가능하게 하여 서비스 메쉬 엣지로 라우팅할 수 있도록 path를 맵핑하는 

Istio Ingress Gateway를 설정합니다.

 

kubectl apply -f samples/bookinfo/networking/bookinfo-gateway.yaml
gateway.networking.istio.io/bookinfo-gateway created
virtualservice.networking.istio.io/bookinfo created

# check the config
$ istioctl analyze
✔ No validation issues found when analyzing namespace: default.

# check if there's external load balancer to support
kubectl get svc istio-ingressgateway -n istio-system
NAME                   TYPE           CLUSTER-IP       EXTERNAL-IP     PORT(S)                                      AGE
istio-ingressgateway   LoadBalancer   172.21.109.129   130.211.10.121  80:31380/TCP,443:31390/TCP,31400:31400/TCP   17h

 

 

bookinfo-gateway.yaml

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
  http:
  - match:
    - uri:
        exact: /productpage
    - uri:
        prefix: /static
    - uri:
        exact: /login
    - uri:
        exact: /logout
    - uri:
        prefix: /api/v1/products
    route:
    - destination:
        host: productpage
        port:
          number: 9080

 

 

Official document to install Istio: https://istio.io/latest/docs/setup/install/

 

Installation Guides

Choose the guide that best suits your needs and platform.

istio.io

 

Getting started: https://istio.io/latest/docs/setup/getting-started/#download