正在使用Loki的版本是v2.9.4,并将Minio配置为索引和块的存储后端。

loki以statefulset方式部署。

Minio部署方式参考:http://t.csdnimg.cn/DQvp3

以下是具体配置。

​
apiVersion: v1
kind: ConfigMap
metadata:
  namespace:  loki
  labels:
    app.kubernetes.io/name: loki
  name: loki-local-config
data:
  local-config.yaml: |-
    auth_enabled: true
    server:
      http_listen_port: 3100
      http_listen_address: 0.0.0.0
      grpc_listen_port: 9095
      grpc_listen_address: 0.0.0.0
    memberlist:
      join_members:
        - "loki-0.loki-headless.loki.svc.cluster.local"
        - "loki-1.loki-headless.loki.svc.cluster.local"
        - "loki-2.loki-headless.loki.svc.cluster.local"
      dead_node_reclaim_time: 30s
      gossip_to_dead_nodes_time: 15s
      left_ingesters_timeout: 30s
      bind_addr: ['0.0.0.0']
      bind_port: 7946

    ingester:
      lifecycler:
        address: 127.0.0.1
        ring:
          kvstore:
            store: memberlist
          replication_factor: 1  # 配置复制因子为1,即每个节点只存储一份数据。
        final_sleep: 0s    # 配置最终休眠时间为0秒,即关闭时立即停止。
      chunk_idle_period: 5m #在没有更新之前chunk在内存中的时间

    storage_config:
      aws:
        endpoint: http://10.10.10.129:9000
        bucketnames: loki   #存储桶名称
        access_key_id: M9io457BM6LxxW7Qypa
        secret_access_key: 23bEme6IxM7GnQgYxxxaPbdi6dgCfXv8PmL7W6w
        s3forcepathstyle: true
       
      boltdb_shipper:
        active_index_directory: /tmp/loki/boltdb-shipper-active
        cache_location: /tmp/loki/boltdb-shipper-cache
        cache_ttl: 24h         # Can be increased for faster performance over longer query periods, uses more disk space
        shared_store: s3

      filesystem:
        directory: /tmp/loki/
    schema_config:
      configs:
        - from: 2020-07-01
          store: boltdb-shipper
          object_store: 
          schema: v11
          index:
            prefix: index_
            period: 24h
          chunks:
            prefix: chunk_    #chunks表的前缀
            period: 24h    #chunks每张表的时间范围7天
    limits_config:
      ingestion_rate_mb: 32 #每个用户每秒的采样率限制
      ingestion_burst_size_mb: 64
      max_label_names_per_series: 3000 #每个流中的最大label个数default:30
      max_global_streams_per_user: 100000
      enforce_metric_name: false
      reject_old_samples: true        
      reject_old_samples_max_age: 168h

    chunk_store_config:
      max_look_back_period: 168h #最大可查询历史日期7天

    #表的保留期7天
    table_manager:
      retention_deletes_enabled: true #超过retention_period时间历史数据可以删除
      retention_period: 168h
    compactor:
      working_directory: /tmp/loki/loki-compactor
      shared_store: aws     

​

svc的配置如下:

apiVersion: v1
kind: Service
metadata:
  name: loki-headless
  namespace: loki
  annotations:
spec:
  selector:
    #app: loki
    app.kubernetes.io/name: loki
  sessionAffinity: None
  type: NodePort
  externalTrafficPolicy: Cluster
  clusterIP: 10.68.3.20
  ports:
  - name: loki
    nodePort: 33100
    port: 3100
    protocol: TCP
    targetPort: 3100

statefulset配置如下:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: loki
  namespace: loki
  labels:
    app.kubernetes.io/name: loki
spec:
  replicas: 3
  serviceName:  loki-headless
  selector:
    matchLabels:
      app.kubernetes.io/name: loki
  template:
    metadata:
      labels:
        app.kubernetes.io/name: loki
    spec:
      affinity: {}
      containers:
      - name: loki
        image: harbor.hgj.net/grafana/loki:2.9.4
        args:
          - "-config.file=/etc/loki/local-config.yaml"
          - "-target=all,table-manager"
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 3100
          name: http-3100
          protocol: TCP
        - containerPort: 9095
          name: grpc-9095
          protocol: TCP
        - containerPort: 7946
          name: tcp-7946
          protocol: TCP
        resources:
          limits:
            cpu: "2"
            memory: 4Gi
          requests:
            cpu: "1"
            memory: "1Gi"
        volumeMounts:
        - name: loki-config
          mountPath: /etc/loki/
          readOnly: true
        livenessProbe:
          failureThreshold: 3
          initialDelaySeconds: 120
          periodSeconds: 30
          successThreshold: 1
          tcpSocket:
            port: 3100
          timeoutSeconds: 5
        securityContext:
          capabilities:
            add: []
            drop:
            - ALL
          readOnlyRootFilesystem: false
          #runAsNonRoot: true
          runAsUser: 0
      securityContext:
        fsGroup: 100
      volumes:
      - name: loki-config
        configMap:
          name: loki-local-config  

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐