이 페이지에서는 사용자 애플리케이션의 커스텀 로그와 측정항목이 Cloud Logging 및 Cloud Monitoring으로 전송되도록 VMware용 Anthos 클러스터(GKE On-Prem)의 사용자 클러스터를 구성하는 방법을 설명합니다.
사용자 애플리케이션의 Logging 및 Monitoring 사용 설정
Logging 및 Monitoring의 구성은 stackdriver
라는 Stackdriver 객체에 보관됩니다.
수정할
stackdriver
객체를 엽니다.kubectl --kubeconfig=USER_CLUSTER_KUBECONFIG --namespace kube-system edit stackdriver stackdriver
USER_CLUSTER_KUBECONFIG를 사용자 클러스터 kubeconfig 파일 경로로 바꿉니다.
spec
에서enableStackdriverForApplications
를true
로 설정합니다.apiVersion: addons.gke.io/v1alpha1 kind: Stackdriver metadata: name: stackdriver namespace: kube-system spec: projectID: ... clusterName: ... clusterLocation: ... proxyConfigSecretName: ... enableStackdriverForApplications: true enableVPC: ... optimizedMetrics: true
수정된 파일을 닫습니다.
워크로드 주석 달기
애플리케이션에서 커스텀 측정항목 수집을 사용 설정하려면 prometheus.io/scrape: "true"
주석을 애플리케이션의 서비스 또는 포드 매니페스트에 추가하거나 포드에 전달되도록 동일한 주석을 배포 또는 DaemonSet 매니페스트의 spec.template
섹션에 추가합니다.
측정항목 가비지 컬렉션을 방지하려면 측정항목 스크랩 간격을 1분으로 설정하는 것이 좋습니다.
예시 애플리케이션 실행
이 섹션에서는 커스텀 로그를 작성하고 커스텀 측정항목을 노출하는 애플리케이션을 만듭니다.
다음 서비스 및 배포 매니페스트를
my-app.yaml
파일에 저장합니다. 서비스에는prometheus.io/scrape: "true"
주석이 있습니다.kind: Service apiVersion: v1 metadata: name: "monitoring-example" namespace: "default" annotations: prometheus.io/scrape: "true" spec: selector: app: "monitoring-example" ports: - name: http port: 9090 --- apiVersion: apps/v1 kind: Deployment metadata: name: "monitoring-example" namespace: "default" labels: app: "monitoring-example" spec: replicas: 1 selector: matchLabels: app: "monitoring-example" template: metadata: labels: app: "monitoring-example" spec: containers: - image: gcr.io/google-samples/prometheus-dummy-exporter:latest name: prometheus-example-exporter imagePullPolicy: Always command: - /bin/sh - -c - ./prometheus-dummy-exporter --metric-name=example_monitoring_up --metric-value=1 --port=9090 resources: requests: cpu: 100m
배포와 서비스를 만듭니다.
kubectl --kubeconfig USER_CLUSTER_KUBECONFIG apply -f my-app.yaml
애플리케이션 로그 보기
Console
Google Cloud 콘솔의 로그 탐색기로 이동합니다.
리소스를 클릭합니다. ALL_RESOURCE_TYPES에서
Kubernetes Container
를 선택합니다.CLUSTER_NAME에서 사용자 클러스터의 이름을 선택합니다.
NAMESPACE_NAME에서
default
를 선택합니다.추가를 클릭한 후 쿼리 실행을 클릭합니다.
쿼리 결과에서
monitoring-example
배포의 로그 항목을 볼 수 있습니다. 예를 들면 다음과 같습니다.{ "textPayload": "2020/11/14 01:24:24 Starting to listen on :9090\n", "insertId": "1oa4vhg3qfxidt", "resource": { "type": "k8s_container", "labels": { "pod_name": "monitoring-example-7685d96496-xqfsf", "cluster_name": ..., "namespace_name": "default", "project_id": ..., "location": "us-west1", "container_name": "prometheus-example-exporter" } }, "timestamp": "2020-11-14T01:24:24.358600252Z", "labels": { "k8s-pod/pod-template-hash": "7685d96496", "k8s-pod/app": "monitoring-example" }, "logName": "projects/.../logs/stdout", "receiveTimestamp": "2020-11-14T01:24:39.562864735Z" }
gcloud
다음 명령어를 실행합니다.
gcloud logging read 'resource.labels.project_id="PROJECT_ID" AND \ resource.type="k8s_container" AND resource.labels.namespace_name="default"'
PROJECT_ID를 로깅 모니터링 프로젝트의 ID로 바꿉니다.
출력에서
monitoring-example
배포의 로그 항목을 볼 수 있습니다. 예를 들면 다음과 같습니다.insertId: 1oa4vhg3qfxidt labels: k8s-pod/app: monitoring-example k8s- pod/pod-template-hash: 7685d96496 logName: projects/.../logs/stdout receiveTimestamp: '2020-11-14T01:24:39.562864735Z' resource: labels: cluster_name: ... container_name: prometheus-example-exporter location: us-west1 namespace_name: default pod_name: monitoring-example-7685d96496-xqfsf project_id: ... type: k8s_container textPayload: | 2020/11/14 01:24:24 Starting to listen on :9090 timestamp: '2020-11-14T01:24:24.358600252Z'
Google Cloud 콘솔에서 애플리케이션 측정항목 보기
예시 애플리케이션은 example_monitoring_up
이라는 커스텀 측정항목을 노출합니다.
Google Cloud 콘솔에서 해당 측정항목의 값을 볼 수 있습니다.
Google Cloud 콘솔의 측정항목 탐색기로 이동합니다.
리소스 유형에서
Kubernetes Pod
또는Kubernetes Container
를 선택합니다.측정항목에서
external.googleapis.com/prometheus/example_monitoring_up
을 선택합니다.차트에서
example_monitoring_up
의 반복되는 값이 1인 것을 알 수 있습니다.