ב-Kf יש כמה סוגים של יומנים. במסמך הזה מתוארים היומנים האלה ומוסבר איך לגשת אליהם.
יומני אפליקציות
כל היומנים שנכתבים לפלט רגיל stdout ולשגיאה רגילה stderr מועלים אל Cloud Logging ונשמרים בשם היומן user-container.
פותחים את Cloud Logging ומריצים את השאילתה הבאה:
resource.type="k8s_container" log_name="projects/YOUR_PROJECT_ID/logs/user-container" resource.labels.project_id=YOUR_PROJECT_ID resource.labels.location=GCP_COMPUTE_ZONE (e.g. us-central1-a) resource.labels.cluster_name=YOUR_CLUSTER_NAME resource.labels.namespace_name=YOUR_KF_SPACE_NAME resource.labels.pod_name:YOUR_KF_APP_NAME
אמורים לראות את כל יומני האפליקציות שנכתבו בstdout ובשגיאה רגילה stderr.
יומני גישה לאפליקציות
Kf מספקת יומני גישה באמצעות החדרת sidecar של Istio. יומני הגישה מאוחסנים בשם היומן server-accesslog-stackdriver.
פותחים את Cloud Logging ומריצים את השאילתה הבאה:
resource.type="k8s_container" log_name="projects/YOUR_PROJECT_ID/logs/server-accesslog-stackdriver" resource.labels.project_id=YOUR_PROJECT_ID resource.labels.location=GCP_COMPUTE_ZONE (e.g. us-central1-a) resource.labels.cluster_name=YOUR_CLUSTER_NAME resource.labels.namespace_name=YOUR_KF_SPACE_NAME resource.labels.pod_name:YOUR_KF_APP_NAME
יוצגו יומני הגישה של האפליקציה. יומן גישה לדוגמה:
{
"insertId": "166tsrsg273q5mf",
"httpRequest": {
"requestMethod": "GET",
"requestUrl": "http://test-app-38n6dgwh9kx7h-c72edc13nkcm.***. ***.nip.io/",
"requestSize": "738",
"status": 200,
"responseSize": "3353",
"remoteIp": "10.128.0.54:0",
"serverIp": "10.48.0.18:8080",
"latency": "0.000723777s",
"protocol": "http"
},
"resource": {
"type": "k8s_container",
"labels": {
"container_name": "user-container",
"project_id": ***,
"namespace_name": ***,
"pod_name": "test-app-85888b9796-bqg7b",
"location": "us-central1-a",
"cluster_name": ***
}
},
"timestamp": "2020-11-19T20:09:21.721815Z",
"severity": "INFO",
"labels": {
"source_canonical_service": "istio-ingressgateway",
"source_principal": "spiffe://***.svc.id.goog/ns/istio-system/sa/istio-ingressgateway-service-account",
"request_id": "0e3bac08-ab68-408f-9b14-0aec671845bf",
"source_app": "istio-ingressgateway",
"response_flag": "-",
"route_name": "default",
"upstream_cluster": "inbound|80|http-user-port|test-app.***.svc.cluster.local",
"destination_name": "test-app-85888b9796-bqg7b",
"destination_canonical_revision": "latest",
"destination_principal": "spiffe://***.svc.id.goog/ns/***/sa/sa-test-app",
"connection_id": "82261",
"destination_workload": "test-app",
"destination_namespace": ***,
"destination_canonical_service": "test-app",
"upstream_host": "127.0.0.1:8080",
"log_sampled": "false",
"mesh_uid": "proj-228179605852",
"source_namespace": "istio-system",
"requested_server_name": "outbound_.80_._.test-app.***.svc.cluster.local",
"source_canonical_revision": "asm-173-6",
"x-envoy-original-dst-host": "",
"destination_service_host": "test-app.***.svc.cluster.local",
"source_name": "istio-ingressgateway-5469f77856-4n2pw",
"source_workload": "istio-ingressgateway",
"x-envoy-original-path": "",
"service_authentication_policy": "MUTUAL_TLS",
"protocol": "http"
},
"logName": "projects/*/logs/server-accesslog-stackdriver",
"receiveTimestamp": "2020-11-19T20:09:24.627065813Z"
}
יומני ביקורת
יומני ביקורת מספקים רשומה כרונולוגית של קריאות שבוצעו לשרת ה-API של Kubernetes. רשומות ביומן הביקורת של Kubernetes שימושיות לחקירת בקשות חשודות ל-API, לאיסוף נתונים סטטיסטיים או ליצירת התראות למעקב אחרי קריאות לא רצויות ל-API.
פותחים את Cloud Logging ומריצים את השאילתה הבאה:
resource.type="k8s_container" log_name="projects/YOUR_PROJECT_ID/logs/cloudaudit.googleapis.com%2Factivity" resource.labels.project_id=YOUR_PROJECT_ID resource.labels.location=GCP_COMPUTE_ZONE (e.g. us-central1-a) resource.labels.cluster_name=YOUR_CLUSTER_NAME protoPayload.request.metadata.name=YOUR_APP_NAME protoPayload.methodName:"deployments."
אמור להופיע מעקב אחר קריאות לשרת Kubernetes API.
הגדרת בקרת גישה ליומנים
כדי לתת למפתחים ולחברים אחרים בצוות גישה ליומנים, צריך לפעול לפי ההוראות האלה. התפקיד roles/logging.viewer מספק גישה לקריאה בלבד של יומנים.
שימוש ב-Logs Router
אפשר גם להשתמש ב-Logs Router כדי לנתב את היומנים ליעדים נתמכים.