Telemetry API로 액세스 로그 구성하기
Telemetry API로 액세스 로그 구성하기 (Configure access logs with Telemetry API)
이 작업은 Telemetry API를 사용해서 액세스 로그를 보내도록 Envoy 프록시를 구성하는 방법을 보여드려요. Istio에서 Telemetry API는 이미 일급(first-class) API로 자리 잡았어요.
출처: Istio 문서
본문
Telemetry API는 이미 꽤 오랫동안 Istio의 일급 API로 자리 잡고 있어요. 예전에는 사용자가 Istio 구성의 MeshConfig 섹션에서 텔레메트리를 구성해야 했어요.
시작하기 전에 (Before you begin)
- 설치 가이드의 지침을 따라 Istio를 설정하세요.
[!note]
demo구성 프로필을 설치하면 egress 게이트웨이와 액세스 로깅이 활성화돼요.
- 요청을 보낼 테스트 소스로 사용할 curl 샘플 앱을 배포하세요. 자동 사이드카 주입이 활성화되어 있으면 다음 명령으로 샘플 앱을 배포하세요.
$ kubectl apply -f @samples/curl/curl.yaml@
그렇지 않으면 curl 애플리케이션을 배포하기 전에 다음 명령으로 사이드카를 수동으로 주입하세요.
$ kubectl apply -f <(istioctl kube-inject -f @samples/curl/curl.yaml@)
[!note]
curl이 설치된 어떤 파드라도 테스트 소스로 사용할 수 있어요.
SOURCE_POD환경 변수를 소스 파드의 이름으로 설정하세요.
$ export SOURCE_POD=$(kubectl get pod -l app=curl -o jsonpath={.items..metadata.name})
- httpbin 샘플을 시작하세요. 자동 사이드카 주입이 활성화되어 있으면
httpbin서비스를 배포하세요.
$ kubectl apply -f @samples/httpbin/httpbin.yaml@
그렇지 않으면 httpbin 애플리케이션을 배포하기 전에 사이드카를 수동으로 주입해야 해요.
$ kubectl apply -f <(istioctl kube-inject -f @samples/httpbin/httpbin.yaml@)
설치 (Installation)
이 예시에서는 로그를 Grafana Loki로 보낼 거예요. Loki가 설치되어 있는지 확인하세요.
$ istioctl install -f @samples/open-telemetry/loki/iop.yaml@ --skip-confirmation
$ kubectl apply -f @samples/addons/loki.yaml@ -n istio-system
$ kubectl apply -f @samples/open-telemetry/loki/otel.yaml@ -n istio-system
Telemetry API 시작하기 (Get started with Telemetry API)
- 액세스 로깅 활성화하기
$ cat <<EOF | kubectl apply -n istio-system -f -
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
name: mesh-logging-default
spec:
accessLogging:
- providers:
- name: otel
EOF
위 예시는 내장 envoy 액세스 로그 프로바이더를 사용하며, 기본 설정 외에 아무것도 구성하지 않아요.
2. 특정 워크로드의 액세스 로그 비활성화하기
다음 구성으로 curl 서비스의 액세스 로그를 비활성화할 수 있어요.
$ cat <<EOF | kubectl apply -n default -f -
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
name: disable-curl-logging
namespace: default
spec:
selector:
matchLabels:
app: curl
accessLogging:
- providers:
- name: otel
disabled: true
EOF
- 워크로드 모드로 액세스 로그 필터링하기
다음 구성으로
httpbin서비스의 인바운드 액세스 로그를 비활성화할 수 있어요.
$ cat <<EOF | kubectl apply -n default -f -
apiVersion: telemetry.istio.io/v1
kind: Telemetry
metadata:
name: disable-httpbin-logging
spec:
selector:
matchLabels:
app: httpbin
accessLogging:
- providers:
- name: otel
match:
mode: SERVER
disabled: true
EOF
- CEL 표현식으로 액세스 로그 필터링하기 다음 구성은 응답 코드가 500 이상일 때만 액세스 로그를 표시해요.
$ cat <<EOF | kubectl apply -n default -f -
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: filter-curl-logging
spec:
selector:
matchLabels:
app: curl
accessLogging:
- providers:
- name: otel
filter:
expression: response.code >= 500
EOF
[!note] 연결이 실패하면
response.code속성이 없어요. 그런 경우에는 CEL 표현식!has(response.code) || response.code >= 500을 사용해야 해요.
- 기본 필터 액세스 로그를 CEL 표현식으로 설정하기
다음 구성은 응답 코드가 400 이상이거나 요청이 BlackHoleCluster 또는 PassthroughCluster로 갔을 때만 액세스 로그를 표시해요.
참고:
xds.cluster_name은 Istio 릴리스 1.16.2 이상에서만 사용할 수 있어요.
$ cat <<EOF | kubectl apply -f -
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: default-exception-logging
namespace: istio-system
spec:
accessLogging:
- providers:
- name: otel
filter:
expression: "response.code >= 400 || xds.cluster_name == 'BlackHoleCluster' || xds.cluster_name == 'PassthroughCluster' "
EOF
- CEL 표현식으로 헬스 체크 액세스 로그 필터링하기
다음 구성은 Amazon Route 53 Health Check Service가 생성하지 않은 로그일 때만 액세스 로그를 표시해요.
참고:
request.useragent는 HTTP 트래픽에만 해당돼요. TCP 트래픽을 깨뜨리지 않으려면 필드 존재 여부를 확인해야 해요. 자세한 내용은 CEL Type Checking을 참고하세요.
$ cat <<EOF | kubectl apply -f -
apiVersion: telemetry.istio.io/v1alpha1
kind: Telemetry
metadata:
name: filter-health-check-logging
spec:
accessLogging:
- providers:
- name: otel
filter:
expression: "!has(request.useragent) || !(request.useragent.startsWith(\"Amazon-Route53-Health-Check-Service\"))"
EOF
자세한 내용은 값에 표현식 사용하기 문서를 참고하세요.
OpenTelemetry 프로바이더 사용하기 (Work with OpenTelemetry provider)
Istio는 OpenTelemetry 프로토콜로 액세스 로그를 보내는 것을 지원해요. 여기에 설명된 대로 사용하면 돼요.
정리 (Cleanup)
- 모든 Telemetry API를 제거하세요.
$ kubectl delete telemetry --all -A
loki를 제거하세요.
$ kubectl delete -f @samples/addons/loki.yaml@ -n istio-system
$ kubectl delete -f @samples/open-telemetry/loki/otel.yaml@ -n istio-system
- 클러스터에서 Istio를 제거하세요.
$ istioctl uninstall --purge --skip-confirmation
더 알아보기 (Learn more)
- Telemetry API의 전체 설정과 옵션은 Telemetry API 개요를 참고하세요.
- CEL 표현식 사용법은 "값에 표현식 사용하기" 문서를 참고하세요.