Questa pagina descrive come configurare un server di log centrale per i dispositivi appliance isolati da internet di Google Distributed Cloud (GDC) tramite l'organizzazione del data center isolato da internet di Google Distributed Cloud.
Per creare una posizione di logging centrale, l'appliance GDC deve avere i seguenti componenti nell'organizzazione del data center GDC:
- progetto unico
- bucket per i log di controllo
- bucket per i log operativi
Crea un progetto
I seguenti passaggi devono essere eseguiti nell'organizzazione del data center GDC in cui verranno esportati i log.
Imposta
KUBECONFIG
sull'API Org Management:export KUBECONFIG=ORG_MANAGEMENT_API_KUBECONFIG_PATH
Per ottenere le autorizzazioni necessarie per esportare i log, chiedi all'amministratore IAM dell'organizzazione di concederti il ruolo ClusterRole Project Creator (
ClusterRole project-creator
). Per saperne di più su questi ruoli, consulta Preparare le autorizzazioni IAM.Applica la risorsa personalizzata del progetto per creare un progetto univoco per l'appliance GDC da cui verranno esportati i log:
kubectl apply -f - <<EOF apiVersion: resourcemanager.gdc.goog/v1 kind: Project metadata: namespace: platform name: APPLIANCE_PROJECT_NAME labels: object.gdc.goog/tenant-category: user EOF
Verifica se il nuovo progetto è disponibile nell'appliance GDC:
kubectl get namespace APPLIANCE_PROJECT_NAME
Collega il nuovo progetto a un account di fatturazione. Per monitorare i costi delle risorse del progetto, devi avere un account di fatturazione associato collegato al progetto.
Per ottenere le autorizzazioni necessarie per esportare i log, chiedi all'amministratore IAM dell'organizzazione di concederti il ruolo Amministratore IAM progetto (
project-iam-admin
) nello spazio dei nomiAPPLIANCE_PROJECT_NAME
.
Crea un bucket
I seguenti passaggi devono essere eseguiti dall'amministratore della piattaforma (PA) nell'organizzazione del data center GDC in cui verranno esportati i log.
Imposta
KUBECONFIG
sull'API Org Management:export KUBECONFIG=ORG_MANAGEMENT_API_KUBECONFIG_PATH
Per ottenere le autorizzazioni necessarie per esportare i log, chiedi all'amministratore IAM dell'organizzazione di concederti il ruolo Amministratore bucket progetto (
project-bucket-admin
) nello spazio dei nomiAPPLIANCE_PROJECT_NAME
.Applica la risorsa personalizzata del bucket per creare un bucket:
apiVersion: object.gdc.goog/v1 kind: Bucket metadata: name: BUCKET_NAME namespace: APPLIANCE_PROJECT_NAME labels: object.gdc.goog/bucket-type: normal object.gdc.goog/encryption-version: v2 object.gdc.goog/tenant-category: user spec: description: Bucket for storing appliance xyz audit logs location: zone1 storageClass: Standard
Dopo aver creato il bucket, esegui questo comando per confermare e controllare i dettagli del bucket:
kubectl describe buckets BUCKET_NAME -n APPLIANCE_PROJECT_NAME
Crea un
ProjectServiceAccount
per accedere agli oggetti nel bucket.kubectl apply -f - <<EOF --- apiVersion: resourcemanager.gdc.goog/v1 kind: ProjectServiceAccount metadata: name: BUCKET_NAME-read-write-sa namespace: APPLIANCE_PROJECT_NAME spec: {} EOF
Verifica che
ProjectServiceAccount
sia propagato:kubectl get projectserviceaccount BUCKET_NAME-read-write-sa -n APPLIANCE_PROJECT_NAME -o json | jq '.status'
Assicurati che all'
ServiceAccount
siano state aggiunte le autorizzazioniread
ewrite
per il bucket.kubectl apply -f - <<EOF --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: BUCKET_NAME-read-write-role namespace: APPLIANCE_PROJECT_NAME rules: - apiGroups: - object.gdc.goog resourceNames: - BUCKET_NAME resources: - buckets verbs: - read-object - write-object --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: BUCKET_NAME-read-write-rolebinding namespace: APPLIANCE_PROJECT_NAME roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: BUCKET_NAME-read-write-role subjects: - kind: ServiceAccount name: BUCKET_NAME-read-write-sa namespace: APPLIANCE_PROJECT_NAME EOF
Ottieni il secret che contiene le credenziali di accesso per il bucket:
kubectl get secret -n APPLIANCE_PROJECT_NAME -o json| jq --arg jq_src BUCKET_NAME-read-write-sa '.items[].metadata|select(.annotations."object.gdc.goog/subject"==$jq_src)|.name'
L'output deve essere simile all'esempio seguente, in cui viene visualizzato il nome segreto del bucket:
"object-storage-key-sysstd-sa-olxv4dnwrwul4bshu37ikebgovrnvl773owaw3arx225rfi56swa"
Esporta il valore in una variabile:
export BUCKET_RW_SECRET_NAME=BUCKET_RW_SECRET_NAME
Ottieni l'ID chiave per l'accesso al bucket:
kubectl get secret $BUCKET_RW_SECRET_NAME -n appliance-xyz -o json | jq -r '.data."access-key-id"' | base64 -di
L'output deve essere simile all'esempio seguente:
PCEW2HU47Y8ACUWQO4SK
Ottieni la chiave di accesso segreta per il bucket:
kubectl get secret $BUCKET_RW_SECRET_NAME -n appliance-xyz -o json | jq -r '.data."secret-access-key"' | base64 -di
L'output deve essere simile all'esempio seguente:
TzGdAbgp4h2i5UeiYa9k09rNPFQ2tkYADs67+65E
Ottieni l'endpoint del bucket:
kubectl get bucket BUCKET_NAME -n APPLIANCE_PROJECT_NAME -o json | jq '.status.endpoint'
L'output deve essere simile all'esempio seguente:
https://objectstorage.org-1.zone1.google.gdch.test
Ottieni il nome completo del bucket:
kubectl get bucket BUCKET_NAME -n APPLIANCE_PROJECT_NAME -o json | jq '.status.fullyQualifiedName'
L'output deve essere simile all'esempio seguente:
aaaoa9a-logs-bucket
Trasferire dati da GDC
Segui la procedura descritta in Esportare i log in un bucket remoto per trasferire i log dall'appliance GDC al bucket creato in precedenza nel data center isolato di GDC utilizzando l'endpoint del bucket, il nome di dominio completo, l'ID chiave di accesso e la chiave di accesso segreta.
Configurare Loki e Grafana nel data center Google Distributed Cloud con air gap
I seguenti passaggi devono essere eseguiti dall'operatore dell'infrastruttura (IO) nell'organizzazione del data center air-gap GDC in cui sono stati esportati i log.
Ottenere ruoli IAM
Per ottenere le autorizzazioni necessarie per esportare i log, chiedi all'amministratore IAM dell'organizzazione di concederti il ruolo Amministratore ripristino log (logs-restore-admin
) nello spazio dei nomi obs-system
nel cluster di infrastruttura e i ruoli Visualizzatore origine dati (datasource-viewer
) e Editor origine dati (datasource-editor
) nello spazio dei nomi obs-system
nel management plane.
Configurare Loki
Imposta
KUBECONFIG
sul cluster dell'infrastruttura dell'organizzazione:export KUBECONFIG=ORG_INFRA_CLUSTER_KUBECONFIG_PATH
Ottieni l'ID chiave di accesso e la chiave di accesso segreta per il bucket dei log dell'appliance dal PA e crea un secret che contenga le credenziali nello spazio dei nomi
obs-system
:kubectl create secret generic -n obs-system APPLIANCE_LOGS_BUCKET_SECRET_NAME --from-literal=access-key-id=APPLIANCE_LOGS_BUCKET_ACCESS_KEY_ID --from-literal=secret-access-key=APPLIANCE_LOGS_BUCKET_SECRET_ACCESS_KEY
Ottieni l'endpoint e il nome completo del bucket dei log dell'appliance dal PA e crea un Loki
configmap
:kubectl apply -f - <<EOF --- apiVersion: v1 kind: ConfigMap metadata: name: CONFIGMAP_NAME namespace: obs-system data: loki.yaml: |- auth_enabled: true common: ring: kvstore: store: inmemory compactor: working_directory: /data/loki/compactor compaction_interval: 10m retention_enabled: true retention_delete_delay: 2h retention_delete_worker_count: 150 delete_request_store: s3 ingester: chunk_target_size: 1572864 chunk_encoding: snappy max_chunk_age: 2h chunk_idle_period: 90m chunk_retain_period: 30s autoforget_unhealthy: true lifecycler: ring: kvstore: store: inmemory replication_factor: 1 heartbeat_timeout: 10m wal: enabled: false limits_config: discover_service_name: [] retention_period: 48h reject_old_samples: false ingestion_rate_mb: 256 ingestion_burst_size_mb: 256 max_streams_per_user: 20000 max_global_streams_per_user: 20000 max_line_size: 0 per_stream_rate_limit: 256MB per_stream_rate_limit_burst: 256MB shard_streams: enabled: false desired_rate: 3MB schema_config: configs: - from: "2020-10-24" index: period: 24h prefix: index_ object_store: s3 schema: v13 store: tsdb server: http_listen_port: 3100 grpc_server_max_recv_msg_size: 104857600 grpc_server_max_send_msg_size: 104857600 graceful_shutdown_timeout: 60s analytics: reporting_enabled: false storage_config: tsdb_shipper: active_index_directory: /tsdb/index cache_location: /tsdb/index-cache cache_ttl: 24h aws: endpoint: APPLIANCE_LOGS_BUCKET_ENDPOINT bucketnames: APPLIANCE_LOGS_BUCKET_FULLY_QUALIFIED_NAME access_key_id: ${S3_ACCESS_KEY_ID} secret_access_key: ${S3_SECRET_ACCESS_KEY} s3forcepathstyle: true --- EOF
Crea un
statefulset
e un servizio Loki:kubectl apply -f - <<EOF --- apiVersion: apps/v1 kind: StatefulSet metadata: labels: app: STATEFULSET_NAME name: STATEFULSET_NAME namespace: obs-system spec: persistentVolumeClaimRetentionPolicy: whenDeleted: Retain whenScaled: Retain podManagementPolicy: OrderedReady replicas: 1 revisionHistoryLimit: 10 selector: matchLabels: app: STATEFULSET_NAME serviceName: STATEFULSET_NAME template: metadata: labels: app: STATEFULSET_NAME istio.io/rev: default spec: affinity: nodeAffinity: preferredDuringSchedulingIgnoredDuringExecution: - preference: matchExpressions: - key: node-role.kubernetes.io/control-plane operator: DoesNotExist - key: node-role.kubernetes.io/master operator: DoesNotExist weight: 1 podAntiAffinity: preferredDuringSchedulingIgnoredDuringExecution: - podAffinityTerm: labelSelector: matchExpressions: - key: app operator: In values: - STATEFULSET_NAME topologyKey: kubernetes.io/hostname weight: 100 containers: - args: - -config.file=/etc/loki/loki.yaml - -config.expand-env=true - -target=all env: - name: S3_ACCESS_KEY_ID valueFrom: secretKeyRef: key: access-key-ID name: APPLIANCE_LOGS_BUCKET_SECRET_NAME optional: false - name: S3_SECRET_ACCESS_KEY valueFrom: secretKeyRef: key: secret-access-key name: APPLIANCE_LOGS_BUCKET_SECRET_NAME optional: false image: gcr.io/private-cloud-staging/loki:v3.0.1-gke.1 imagePullPolicy: Always livenessProbe: failureThreshold: 3 httpGet: path: /ready port: loki-server scheme: HTTP initialDelaySeconds: 330 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 1 name: STATEFULSET_NAME ports: - containerPort: 3100 name: loki-server protocol: TCP - containerPort: 7946 name: gossip-ring protocol: TCP readinessProbe: failureThreshold: 3 httpGet: path: /ready port: loki-server scheme: HTTP initialDelaySeconds: 45 periodSeconds: 10 successThreshold: 1 timeoutSeconds: 1 resources: limits: ephemeral-storage: 2000Mi memory: 8000Mi requests: cpu: 300m ephemeral-storage: 2000Mi memory: 1000Mi securityContext: readOnlyRootFilesystem: true terminationMessagePath: /dev/termination-log terminationMessagePolicy: File volumeMounts: - mountPath: /etc/loki name: config - mountPath: /data name: loki-storage - mountPath: /tsdb name: loki-tsdb-storage - mountPath: /tmp name: temp - mountPath: /tmp/loki/rules-temp name: tmprulepath - mountPath: /etc/ssl/certs name: trust-bundle readOnly: true dnsPolicy: ClusterFirst restartPolicy: Always schedulerName: default-scheduler securityContext: fsGroup: 10001 runAsGroup: 10001 runAsUser: 10001 terminationGracePeriodSeconds: 4800 volumes: - emptyDir: {} name: temp - emptyDir: {} name: tmprulepath - configMap: defaultMode: 420 name: trust-store-root-ext optional: true name: trust-bundle - configMap: defaultMode: 420 name: CONFIGMAP_NAME name: config updateStrategy: type: RollingUpdate volumeClaimTemplates: - apiVersion: v1 kind: PersistentVolumeClaim metadata: creationTimestamp: null name: loki-storage spec: accessModes: - ReadWriteOnce resources: requests: storage: 5Gi storageClassName: standard-rwo volumeMode: Filesystem - apiVersion: v1 kind: PersistentVolumeClaim metadata: creationTimestamp: null name: loki-tsdb-storage spec: accessModes: - ReadWriteOnce resources: requests: storage: 5Gi storageClassName: standard-rwo volumeMode: Filesystem --- apiVersion: v1 kind: Service metadata: name: STATEFULSET_NAME namespace: obs-system spec: internalTrafficPolicy: Cluster ipFamilies: - IPv4 ipFamilyPolicy: SingleStack ports: - name: loki-server port: 3100 protocol: TCP targetPort: loki-server selector: app: STATEFULSET_NAME sessionAffinity: None type: ClusterIP --- EOF
Configurare Grafana DataSource
Imposta
KUBECONFIG
sull'API Org Management:export KUBECONFIG=ORG_MANAGEMENT_API_KUBECONFIG_PATH
Crea
DataSources
per i log di infrastruttura e piattaforma:kubectl apply -f - <<EOF --- apiVersion: monitoring.private.gdc.goog/v1alpha1 kind: Datasource metadata: name: INFRA_DATASOURCE_NAME namespace: APPLIANCE_PROJECT_NAME-obs-system spec: datasource: access: proxy isDefault: false jsonData: httpHeaderName1: X-Scope-OrgID name: UI_FRIENDLY_NAME orgId: 1 readOnly: true secureJsonData: httpHeaderValue1: infra-obs type: loki uid: INFRA_DATASOURCE_NAME url: http://STATEFULSET_NAME.obs-system.svc:3100 version: 1 withCredentials: false --- apiVersion: monitoring.private.gdc.goog/v1alpha1 kind: Datasource metadata: name: PLATFORM_DATASOURCE_NAME namespace: APPLIANCE_PROJECT_NAME-obs-system spec: datasource: access: proxy isDefault: false jsonData: httpHeaderName1: X-Scope-OrgID name: UI_FRIENDLY_NAME orgId: 1 readOnly: true secureJsonData: httpHeaderValue1: platform-obs type: loki uid: PLATFORM_DATASOURCE_NAME url: http://STATEFULSET_NAME.obs-system.svc:3100 version: 1 withCredentials: false --- EOF
Visualizzare i log in Grafana del data center Google Distributed Cloud con air gap
I log esportati nel bucket del data center isolato di Google Distributed Cloud possono essere visualizzati nell'istanza Grafana del progetto appliance GDC.