서비스메쉬(Service Mesh) : sidecar pattern사용
서비스 메쉬(Service Mesh)란 서비스(Application) 간의 그물망과 같은 서로 통신으로 연결되어진 서비스 구성입니다.
안정적인 마이크로서비스 구성을 위해서는 아래와 같은 서비스메쉬 구성이 필요로합니다.
Service Discovery
Load Balancing
Dynamic Request Routing
Circuit Breacking
Retry and Timeout
TLS
Distributed Tracing
Metric 수집
Access Control
A/B Testing
기능 등을 지원한다.
서비스매쉬는 보통 sidecar 형태의 container로 구성됩니다.
ex) 하나의 Pod에는 nginx 서버 + istio_proxy(init container) 구성됨
Service Mesh & API Gateway 구성
API Gateway는 전체 서비스를 노출해주는 핵심역할을 하며, 하나의 Endpoint로 비즈니스 기능을 제공합니다.
반면 서비스메시는 여러 서비스간의 통신 관리를 해주는 역할을 합니다.
(서비스 검색, 트래픽, 회로차단기와 같이 연결을 하거나 끊거나 자유롭게 서로간의 통신설정을 할수 있습니다.)
아래는 API Gateway와 Service Mesh가 함께 공존하는구성 아키텍쳐
Istio란
Istio는 서비스 매쉬(Service Mesh)를 구현할 수 있는 오픈소스 솔루션이다.
Istio를 사용하면 서비스 코드 변경 없이
로드밸런싱,
서비스 간 인증,
모니터링 등을
적용하여 마이크로 서비스를 쉽게 관리할 수 있다.
마이크로 서비스 간의 모든 네트워크 통신을 담당할 수 있는 프록시인 Envoy를 사이드카 패턴으로 마이크로 서비스들에 배포한 다음, 프록시들의 설정값 저장 및 관리/감독을 수행하고, 프록시들에 설정값을 전달하는 컨트롤러 역할을 수행한다.
각각의 마이크로 서비스에 사이드카 패턴으로 배포된 Envoy 프록시를 데이타 플레인(Data Plane)이라고 하고,
데이타 플레인을 컨트롤 하는 부분은 컨트롤 플레인(Control Plane)이라고 한다.
Istiod 데몬
Istio1.4 버전까지는 파일럿(Pilot), 믹서(Mixer), 시타델(Citadel), 갤리(Galley)로 구성되었지만,
Istio1.5버전부터 4개의 모듈이 Istiod 라는 하나의 모듈로 통합되었다
Data plane
Envoy Proxy 세트로 구성되어 있다. Envoy는 사이드카 방식으로 각각의 마이크로서비스에 배포되어 서비스로 들어오고 나가는 모든 트래픽을 통제하게 된다. Envoy를 통해서 서비스를 호출할 때 호출하는 서비스의 IP주소는 파일럿(Pilot)에 저장된 엔드포인트 정보를 활용하게 된다.
Control plane
데이터 플레인(Data Plane)인 Envoy를 컨트롤하는 부분이다.
서비스 디스커버리(Service Discovery), 설정 관리(Configuration Management), 인증 관리(Certificate Management) 등을 수행한다.
Kubernetes vs Service Mesh
특징
트래픽 관리(Traffic Management)
Istio의 간편한 규칙(Rule) 설정과 트래픽 라우팅(Traffic Routing) 기능을 통해 서비스 간의 트래픽 흐름과 API 호출을 제어할 수 있다. 또한 서킷 브레이커(Circuit Breaker), 타임아웃(Timeout), 재시도(Retry) 기능과 같은 서비스 레벨의 속성 구성을 단순화하고, 백분율 기반으로 트래픽을 분할하여 A/B Test, Canary Rollout, 단계적(Staged) Rollout 과 같은 작업을 쉽게 설정할 수 있다.
트래픽에 대한 더 나은 가시성과 독창적인 장애 복구 기능을 통해 문제가 발생하기 전에 문제를 찾고, 서비스 호출을 더욱 안정적으로 만들고, 어떤 상황에서든 네트워크를 더욱 안정적으로 만들 수 있다(트래픽 관리 개념 가이드)
보안(Security)
Istio의 보안기능을 통해 개발자는 어플리케이션 레벨의 보안에 보다 더 집중할 수 있다. Istio는 기본적인 보안 통신 채널을 제공하며, 대규모 서비스 통신의 인증(Authentication), 권한부여(Authorization), 암호화(Encryption) 등을 관리한다. Istio를 사용하면 기본적으로 서비스 통신은 보호되기 때문에, 다양한 프로토콜이나 런타임에서 어플리케이션 변경을 거의 하지 않고 일관된 정책을 시행할 수 있다. Istio는 플랫폼에 독립적이지만 쿠버네티스 네트워크 정책과 함께 사용하면 파드(pod)간 혹은 서비스(Service)간 통신을 보호하는 기능 등의 다양한 이점이 있다(보안 개념 가이드)
관찰 가능성(Observability)
Istio의 강력한 트레이싱(Tracing), 모니터링(Monitoring), 로깅(Logging) 기능으로 서비스 매쉬에 배포된 서비스들에 대해 더욱 자세히 파악할 수 있다. Istio의 모니터링 기능을 통해 서비스 성능이 업스트림/다운스트림에 어떤 영향을 끼치는지 파악할 수 있다. 또한 맞춤형 대쉬보드를 통해 모든 서비스 성능 대한 가시성 확인 및 성능이 다른 프로세스들에 미치는 영향 등을 확인 할 수 있다.
Envoy Proxy
c++언어로 작성됐으며, CNCF 2017년에 가입된 오픈소스 프로젝트다.
Proxy는 중간 미들웨어 네트워크 아키텍처로써 보안, 인증, 정책등 다양한 기능을 추가할수 있다.
참고문서)
https://eng.lyft.com/announcing-envoy-c-l7-proxy-and-communication-bus-92520b6c8191
Listeners
어플리케이션을 연결하기 위한 port를 expose하는 역할
Routes
listener로 들어오는 트래픽을 핸들하기 위한 Rule을 설정하는곳이다.
보통 Match를 통해서 특정 cluster로 트래픽을 전달한다.
Clusters
특정 upstream 서비스로 직접 전달하기 위한 설정
기능
Service Discovery
Load Balancing
Traffic/Request Routing
Traffic Shadowing
Network Resilience
Http/2 AND GRPC
Observability with Metrics collection
Rate Limiting
Istioctl 설치
Kubernetes에서 istio을 설치하기 위해서는 istioctl를 설치하는게 좋다.
curl -L https://istio.io/downloadIstio sh -
Verify 체크 : Kubernetes cluster환경에서 Istio설치 확인을 위한 command
istioctl x precheck
✔ No issues found when checking the cluster. Istio is safe to install or upgrade!
To get started, check out https://istio.io/latest/docs/setup/getting-started/
Istio 설치
https://istio.io/latest/docs/setup/additional-setup/config-profiles/
위의 링크를 통해서 다양한 profile에 대한 설명을 확인할수 있습니다.
아래는 profile=default로 설정해서 진행합니다.
istioctl install --set profile=default -y
+ Istio core installed
+ Istiod installed
+ Ingress gateways installed
+ Egress gateways installed
+ Installation complete
# kuberctl로 다시 istio-system 네임스페이스로 설치가 됐는지 확인해보자
kubectl get pod -n istio-system
NAME READY STATUS RESTARTS AGE
istio-egressgateway-7f4864f59c-2fxvm 1/1 Running 0 19d
istio-ingressgateway-55d9fb9f-vdpt6 1/1 Running 0 19d
istiod-555d47cb65-4mj2c 1/1 Running 0 19d
# kubernetes cluster istio설치 확인 verify
istioctl verify-install
1 Istio control planes detected, checking --revision "default" only
✔ ClusterRole: istiod-istio-system.istio-system checked successfully
✔ ClusterRole: istio-reader-istio-system.istio-system checked successfully
✔ ClusterRoleBinding: istio-reader-istio-system.istio-system checked successfully
✔ ClusterRoleBinding: istiod-istio-system.istio-system checked successfully
✔ ServiceAccount: istio-reader-service-account.istio-system checked successfully
✔ Role: istiod-istio-system.istio-system checked successfully
✔ RoleBinding: istiod-istio-system.istio-system checked successfully
✔ ServiceAccount: istiod-service-account.istio-system checked successfully
✔ CustomResourceDefinition: wasmplugins.extensions.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: destinationrules.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: envoyfilters.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: gateways.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: serviceentries.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: sidecars.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: virtualservices.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: workloadentries.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: workloadgroups.networking.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: authorizationpolicies.security.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: peerauthentications.security.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: requestauthentications.security.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: telemetries.telemetry.istio.io.istio-system checked successfully
✔ CustomResourceDefinition: istiooperators.install.istio.io.istio-system checked successfully
✔ ClusterRole: istiod-clusterrole-istio-system.istio-system checked successfully
✔ ClusterRole: istiod-gateway-controller-istio-system.istio-system checked successfully
✔ ClusterRoleBinding: istiod-clusterrole-istio-system.istio-system checked successfully
✔ ClusterRoleBinding: istiod-gateway-controller-istio-system.istio-system checked successfully
✔ ConfigMap: istio.istio-system checked successfully
✔ Deployment: istiod.istio-system checked successfully
✔ ConfigMap: istio-sidecar-injector.istio-system checked successfully
✔ MutatingWebhookConfiguration: istio-sidecar-injector.istio-system checked successfully
✔ PodDisruptionBudget: istiod.istio-system checked successfully
✔ ClusterRole: istio-reader-clusterrole-istio-system.istio-system checked successfully
✔ ClusterRoleBinding: istio-reader-clusterrole-istio-system.istio-system checked successfully
✔ Role: istiod.istio-system checked successfully
✔ RoleBinding: istiod.istio-system checked successfully
✔ Service: istiod.istio-system checked successfully
✔ ServiceAccount: istiod.istio-system checked successfully
✔ EnvoyFilter: stats-filter-1.10.istio-system checked successfully
✔ EnvoyFilter: tcp-stats-filter-1.10.istio-system checked successfully
✔ EnvoyFilter: stats-filter-1.11.istio-system checked successfully
✔ EnvoyFilter: tcp-stats-filter-1.11.istio-system checked successfully
✔ EnvoyFilter: stats-filter-1.12.istio-system checked successfully
✔ EnvoyFilter: tcp-stats-filter-1.12.istio-system checked successfully
✔ ValidatingWebhookConfiguration: istio-validator-istio-system.istio-system checked successfully
✔ Deployment: istio-ingressgateway.istio-system checked successfully
✔ PodDisruptionBudget: istio-ingressgateway.istio-system checked successfully
✔ Role: istio-ingressgateway-sds.istio-system checked successfully
✔ RoleBinding: istio-ingressgateway-sds.istio-system checked successfully
✔ Service: istio-ingressgateway.istio-system checked successfully
✔ ServiceAccount: istio-ingressgateway-service-account.istio-system checked successfully
✔ Deployment: istio-egressgateway.istio-system checked successfully
✔ PodDisruptionBudget: istio-egressgateway.istio-system checked successfully
✔ Role: istio-egressgateway-sds.istio-system checked successfully
✔ RoleBinding: istio-egressgateway-sds.istio-system checked successfully
✔ Service: istio-egressgateway.istio-system checked successfully
✔ ServiceAccount: istio-egressgateway-service-account.istio-system checked successfully
Checked 14 custom resource definitions
Checked 3 Istio Deployments
✔ Istio is installed and verified successfully
Integrations tools with Istio
https://istio.io/latest/docs/ops/integrations/
위의 링크를 확인해보면 Istio와 함께 통합으로 설치해야 하는 Tools 리스트이다.
위의 tools 없으면 전반적인 네트웍에 대한흐름이나 metric을 정확히 파악하기 어렵다.
꼭 설치해서 확이해보자.
아래 툴 리스트에 대해서 작성해본다.
1. Tools
Jaeger
https://istio.io/latest/docs/ops/integrations/jaeger/
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/jaeger.yaml
Dashboard
istioctl dashboard jaeger
Grafana
https://istio.io/latest/docs/ops/integrations/grafana/
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/grafana.yaml
Dashboard
istioctl dashboard grafana
Prometheus
https://istio.io/latest/docs/ops/integrations/prometheus/
오픈소스 모니터링 시스템 & 타임 데이타베이스이다. 대부분의 CNCF 모니터링은 promotheus를 사용한다고 보면 된다.
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/prometheus.yaml
Dashboard
istioctl dashboard prometheus
Zipkin
jaeger와 비슷한 역할을 합니다.
설치
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/extras/zipkin.yaml
Kiali
istio를 위한 서비스메쉬 & 기능에 대한 관찰할수 잇는 서비스이다.
트레픽에 대한 모니터링, health체크등 전반적인 서비스를 쉽게 확인해줄수 잇는 서비스
내부적으로 metrics 와 Grafana를 통합하여 제공해주며, Jaeger을 통한 Tracing도 가능하여 전반적인 Istio 통합 관리 서비스이다.
Dependency
위의 설명대로 metrics를 위해서는 Prometheus를 설치해야하며, 기타 jaeger, grafana또한 설치해야 재대로 활용이 가능하다.
아래와같이 아무것도 설치하지 않은경우 경고 문구가 발생한다.
아래 이슈를 해결해보자..
참조) https://istio.io/latest/docs/ops/integrations/kiali/#installation
kubectl apply -f https://raw.githubusercontent.com/istio/istio/release-1.12/samples/addons/kiali.yaml
설치 확인
kubectl -n istio-system get svc kiali
user@userui-MacBook-Pro:~/Documents/Work/projects/LMS/server/services/runner-cli/test/kubernetes/resources$ kubectl -n istio-system get svc kiali
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kiali ClusterIP 172.20.180.72 <none> 20001/TCP,9090/TCP 6s
Dashboard
istioctl을 이용하여 dashboard로 직접 접근해보자
아래와 같이 실행하면, http://localhost:20001/kiali 로 접근할수있는 페이지로 이동해준다.
istioctl dashboard kiali
Istio-injection
Auto sidecar injection처리 내부 동작
namepsace안의 전체 pod을 sidecar proxy 를 설정하기 위해서는 istio-injection=enabled로 하면 적용된다.
보통 label 설정을 통한 네임스페이스 또는 각각의 pod에도 적용가능하다.
istio가 설치되면 kube-apiserver에 mutating webhook admission controller가 생성됩니다.
이 controller는 pod생성 event가 발생하면 sidecar로 init_istio sidecar 가 자동으로 추가해주는 역할을 합니다.
관련 리소스는 mutatingwebhookconfiguration입니다.
user$ kubectl get mutatingwebhookconfiguration
NAME WEBHOOKS AGE
admission-webhook-mutating-webhook-configuration 1 15d
cache-webhook-kubeflow 1 13d
cert-manager-webhook 1 311d
inferenceservice.serving.kubeflow.org 3 15d
istio-revision-tag-default 4 3d13h
istio-sidecar-injector 4 12d
katib-mutating-webhook-config 2 15d
katib.kubeflow.org 2 14d
pod-identity-webhook 1 564d
seldon-mutating-webhook-configuration-kubeflow 3 15d
sinkbindings.webhook.sources.knative.dev 1 14d
vpc-resource-mutating-webhook 1 465d
webhook.domainmapping.serving.knative.dev 1 12d
webhook.eventing.knative.dev 1 14d
webhook.istio.networking.internal.knative.dev 1 12d
webhook.serving.knative.dev 1 12d
Auto sidecar injection처리 방법
kubectl label namespace <namespace> istio-injection=enabled
kubectl get ns -L istio-injection
user$ kubectl get ns -L istio-injection
NAME STATUS AGE ISTIO-INJECTION
app Active 551d enabled
argo Active 24h
cert-manager Active 3d20h
default Active 564d enabled
sidecar injection using Mutating Admission Webhooks
istioctl kube-inject -f deployment.yaml
deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin
spec:
selector:
matchLabels:
app: httpbin
template:
metadata:
labels:
app: httpbin
spec:
containers:
- image: docker.io/kennethreitz/httpbin
name: httpbin
ports:
- containerPort: 80’
내부적 동작 방식 그림 설명
Istio Gateway & VirtualService
유저 -> istio ingress gateway를 통해서 -> gateway -> virtual service 통신 프로세스
Gateway
nginx 서비스를 통한 아래 테스트 Gateway설정입니다.
tls의 credentailName: nginx-tls는 cert-manager를 참고하여 자동생성 받으셔야 합니다. cert-manager는 저희 블로그 참고해주세요.
#Gateway
kind: Gateway
apiVersion: networking.istio.io/v1alpha3
metadata:
name: nginx
namespace: istio-system
spec:
servers:
- hosts:
- '*'
port:
name: http
number: 80
protocol: HTTP
tls:
httpsRedirect: true
- hosts:
- 'walter.kr' # <-- 나의 도메인
port:
name: https
number: 443
protocol: HTTPS
tls:
credentialName: nginx-tls # <-- 내가 만든 cert-manager certificate 인증서 이름
mode: SIMPLE
selector:
app: istio-ingressgateway
Virtual Services
destination의 host는 내부 cluster의 서비스 DNS주소입니다. (nginx서비스의 이름의 default 네임스페이스의 서비스주소입니다.)
gateways : 위에서 생성한 gateway이름을 넣어주세요.
#VirtualService
kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
name: nginx
namespace: istio-system
spec:
hosts:
- 'walter.kr' # <-- 내가 도메인
http:
- route:
- destination:
host: nginx.default.svc.cluster.local
gateways:
- nginx
참고
https://jimmysong.io/en/blog/why-do-you-need-istio-when-you-already-have-kubernetes/
'IT&Tech' 카테고리의 다른 글
API 인증프로세스 Istio Ingress Gateway, OAuth2-Proxy and Keycloak (0) | 2022.01.20 |
---|---|
Golang을 이용한 Graphql서버 구현 (6) | 2022.01.20 |
Kubernetes 소개 (2) | 2022.01.19 |
cert-manager를 이용한 ACME 무료인증 (0) | 2022.01.18 |
Kubeflow 1.4 최신버전 설치 (0) | 2022.01.18 |