• Kubernetes平台部署Grafana Loki Promtail系统


    部署结构图:
    在这里插入图片描述

    • Loki 是主服务,负责存储日志和处理查询
    • promtail 是代理,负责收集日志并将其发送给 loki
    • Grafana 用于 UI 展示

    只要在应用程序服务器上安装promtail来收集日志然后发送给Loki存储,就可以在Grafana UI界面通过添加Loki为数据源进行日志查询(如果Loki服务器性能不够,可以部署多个Loki进行存储及查询)。作为一个日志系统不光只有查询分析日志的能力,还能对日志进行监控和报警。

    一、创建独立的命名空间

    为日志系统创建一个独立的命令空间

    kubectl create ns logging
    
    • 1

    二、部署Grafana

    2.1 编写grafana部署的配置文件

    创建 grafana 目录,并在目录中创建 grafana-deploy.yaml 文件,内容如下:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: grafana
      labels:
        app: grafana
      namespace: logging
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: grafana
      template:
        metadata:
          labels:
            app: grafana
        spec:
          containers:
          - name: grafana
            image: grafana/grafana:8.4.7
            imagePullPolicy: IfNotPresent
            securityContext:
              runAsUser: 0
            env:
            - name: GF_AUTH_BASIC_ENABLED
              value: "true"
            - name: GF_AUTH_ANONYMOUS_ENABLED
              value: "false"
    #        resources:
    #          requests:
    #            cpu: 100m
    #            memory: 200Mi
    #          limits:
    #            cpu: '1'
    #            memory: 2Gi
            readinessProbe:
              httpGet:
                path: /login
                port: 3000
            volumeMounts:
            - name: storage
              mountPath: /var/lib/grafana
          volumes:
          - name: storage
            hostPath:
              path: /hostpath/grafana
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: grafana
      labels:
        app: grafana
      namespace: logging
    spec:
      type: NodePort
      ports:
      - port: 3000
        targetPort: 3000
        nodePort: 30200
      selector:
        app: grafana
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62

    上述配置修改注意点:
    (1)上述有两处namespace,此处需要使用步骤一中创建的命名空间,这里是logging
    在这里插入图片描述
    (2)挂载的目录需要在服务器上创建并且设置为足够的访问权限,比如这里:

    mkdir -p /hostpath/grafana
    chmod 777 -R /hostpath/grafana
    在这里插入图片描述

    (3)对外开发端口可以自行设置,这里比如 30200

    在这里插入图片描述

    2.2 部署grafana

    进入grafana目录,然后执行部署命令

    cd grafana
    kubectl apply -f grafana-deploy.yaml
    
    • 1
    • 2

    三、部署 Loki

    3.1 编写Loki部署的配置文件

    创建 loki文件夹,然后再 loki 文件夹中创建三个配置文件,分别是:loki-rbac.yaml、loki-configmap.yaml和loki-statefulset.yaml

    loki-rbac.yaml文件内容如下:

    apiVersion: v1
    kind: Namespace
    metadata:
      name: logging
    ---
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: loki
      namespace: logging
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: loki
      namespace: logging
    rules:
    - apiGroups: ["extensions"]
      resources: ["podsecuritypolicies"]
      verbs: ["use"]
      resourceNames: [loki]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: loki
      namespace: logging
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: loki
    subjects:
    - kind: ServiceAccount
      name: loki
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    上述配置修改注意点:
    (1)只需保证其中的namespace雨步骤一中设置的一致即可,比如都是logging时,此文件不需要修改

    在这里插入图片描述
    loki-configmap.yaml文件的内容如下:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: loki
      namespace: logging
      labels:
        app: loki
    data:
      loki.yaml: |
        auth_enabled: false
        ingester:
          chunk_idle_period: 3m
          chunk_block_size: 262144
          chunk_retain_period: 1m
          max_transfer_retries: 0
          lifecycler:
            ring:
              kvstore:
                store: inmemory
              replication_factor: 1
        limits_config:
          enforce_metric_name: false
          reject_old_samples: true
          reject_old_samples_max_age: 168h
        schema_config:
          configs:
          - from: "2022-05-15"
            store: boltdb-shipper
            object_store: filesystem
            schema: v11
            index:
              prefix: index_
              period: 24h
        server:
          http_listen_port: 3100
        storage_config:
          boltdb_shipper:
            active_index_directory: /data/loki/boltdb-shipper-active
            cache_location: /data/loki/boltdb-shipper-cache
            cache_ttl: 24h
            shared_store: filesystem
          filesystem:
            directory: /data/loki/chunks
        chunk_store_config:
          max_look_back_period: 0s
        table_manager:
          retention_deletes_enabled: true
          retention_period: 48h
        compactor:
          working_directory: /data/loki/boltdb-shipper-compactor
          shared_store: filesystem
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52

    上述配置修改注意点:
    (1)namespace同样需要和步骤一中的设置保持一致
    在这里插入图片描述
    loki-statefulset.yaml文件的内容如下:

    apiVersion: v1
    kind: Service
    metadata:
      name: loki
      namespace: logging
      labels:
        app: loki
    spec:
      type: NodePort
      ports:
        - port: 3100
          protocol: TCP
          name: http-metrics
          targetPort: http-metrics
          nodePort: 30201
      selector:
        app: loki
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: loki
      namespace: logging
      labels:
        app: loki
    spec:
      podManagementPolicy: OrderedReady
      replicas: 1
      selector:
        matchLabels:
          app: loki
      serviceName: loki
      updateStrategy:
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: loki
        spec:
          serviceAccountName: loki
          initContainers:
          - name: chmod-data
            image: busybox:1.28.4
            imagePullPolicy: IfNotPresent
            command: ["chmod","-R","777","/loki/data"]
            volumeMounts:
            - name: storage
              mountPath: /loki/data
          containers:
            - name: loki
              image: grafana/loki:2.3.0
              imagePullPolicy: IfNotPresent
              args:
                - -config.file=/etc/loki/loki.yaml
              volumeMounts:
                - name: config
                  mountPath: /etc/loki
                - name: storage
                  mountPath: /data
              ports:
                - name: http-metrics
                  containerPort: 3100
                  protocol: TCP
              livenessProbe:
                httpGet: 
                  path: /ready
                  port: http-metrics
                  scheme: HTTP
                initialDelaySeconds: 45
              readinessProbe:
                httpGet: 
                  path: /ready
                  port: http-metrics
                  scheme: HTTP
                initialDelaySeconds: 45
              securityContext:
                readOnlyRootFilesystem: true
          terminationGracePeriodSeconds: 4800
          volumes:
            - name: config
              configMap:
                name: loki
            - name: storage
              hostPath:
                path: /app/loki
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86

    上述配置修改注意点:
    (1)同样,namespace需要和步骤一中设置为一致
    (2)设置Loki对外开放的端口,比如这里设置为30201

    在这里插入图片描述

    3.2 部署 Loki

    在loki目录中执行如下命令进行部署

    cd loki
    kubectl apply -f .
    
    • 1
    • 2

    四、部署 promtail

    4.1 编写配置文件

    首先创建 promtail 文件夹,然后再文件夹中创建 promtail-rbac.yaml、promtail-configmap.yaml和promtail-daemonset.yaml三个文件

    promtail-rbac.yaml 文件内容如下,同样,这里不需要修改什么配置,只需要保证namespace和步骤一中创建的一致即可。

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: loki-promtail
      labels:
        app: promtail
      namespace: logging
    ---
    kind: ClusterRole
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      labels:
        app: promtail
      name: promtail-clusterrole
      namespace: logging
    rules:
    - apiGroups: [""]
      resources: ["nodes","nodes/proxy","services","endpoints","pods"]
      verbs: ["get", "watch", "list"]
    ---
    kind: ClusterRoleBinding
    apiVersion: rbac.authorization.k8s.io/v1
    metadata:
      name: promtail-clusterrolebinding
      labels:
        app: promtail
      namespace: logging
    subjects:
      - kind: ServiceAccount
        name: loki-promtail
        namespace: logging
    roleRef:
      kind: ClusterRole
      name: promtail-clusterrole
      apiGroup: rbac.authorization.k8s.io
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36

    promtail-configmap.yaml 文件内容如下,此文件同样只需要保证namespace与步骤一中一致即可,不需要做其他修改

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: loki-promtail
      namespace: logging
      labels:
        app: promtail
    data:
      promtail.yaml: |
        client:
          backoff_config:
            max_period: 5m 
            max_retries: 10
            min_period: 500ms
          batchsize: 1048576
          batchwait: 1s
          external_labels: {}
          timeout: 10s
        positions:
          filename: /run/promtail/positions.yaml
        server:
          http_listen_port: 3101
        target_config:
          sync_period: 10s
        scrape_configs:
        - job_name: kubernetes-pods-name
          pipeline_stages:
            - docker: {}
          kubernetes_sd_configs:
          - role: pod
          relabel_configs:
          - source_labels:
            - __meta_kubernetes_pod_label_name
            target_label: __service__
          - source_labels:
            - __meta_kubernetes_pod_node_name
            target_label: __host__
          - action: drop
            regex: ''
            source_labels:
            - __service__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            replacement: $1
            separator: /
            source_labels:
            - __meta_kubernetes_namespace
            - __service__
            target_label: job
          - action: replace
            source_labels:
            - __meta_kubernetes_namespace
            target_label: namespace
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_name
            target_label: pod
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_container_name
            target_label: container
          - replacement: /var/log/pods/*$1/*.log
            separator: /
            source_labels:
            - __meta_kubernetes_pod_uid
            - __meta_kubernetes_pod_container_name
            target_label: __path__
        - job_name: kubernetes-pods-app
          pipeline_stages:
            - docker: {}
          kubernetes_sd_configs:
          - role: pod
          relabel_configs:
          - action: drop
            regex: .+
            source_labels:
            - __meta_kubernetes_pod_label_name
          - source_labels:
            - __meta_kubernetes_pod_label_app
            target_label: __service__
          - source_labels:
            - __meta_kubernetes_pod_node_name
            target_label: __host__
          - action: drop
            regex: ''
            source_labels:
            - __service__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            replacement: $1
            separator: /
            source_labels:
            - __meta_kubernetes_namespace
            - __service__
            target_label: job
          - action: replace
            source_labels:
            - __meta_kubernetes_namespace
            target_label: namespace
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_name
            target_label: pod
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_container_name
            target_label: container
          - replacement: /var/log/pods/*$1/*.log
            separator: /
            source_labels:
            - __meta_kubernetes_pod_uid
            - __meta_kubernetes_pod_container_name
            target_label: __path__
        - job_name: kubernetes-pods-direct-controllers
          pipeline_stages:
            - docker: {}
          kubernetes_sd_configs:
          - role: pod
          relabel_configs:
          - action: drop
            regex: .+
            separator: ''
            source_labels:
            - __meta_kubernetes_pod_label_name
            - __meta_kubernetes_pod_label_app
          - action: drop
            regex: '[0-9a-z-.]+-[0-9a-f]{8,10}'
            source_labels:
            - __meta_kubernetes_pod_controller_name
          - source_labels:
            - __meta_kubernetes_pod_controller_name
            target_label: __service__
          - source_labels:
            - __meta_kubernetes_pod_node_name
            target_label: __host__
          - action: drop
            regex: ''
            source_labels:
            - __service__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            replacement: $1
            separator: /
            source_labels:
            - __meta_kubernetes_namespace
            - __service__
            target_label: job
          - action: replace
            source_labels:
            - __meta_kubernetes_namespace
            target_label: namespace
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_name
            target_label: pod
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_container_name
            target_label: container
          - replacement: /var/log/pods/*$1/*.log
            separator: /
            source_labels:
            - __meta_kubernetes_pod_uid
            - __meta_kubernetes_pod_container_name
            target_label: __path__
        - job_name: kubernetes-pods-indirect-controller
          pipeline_stages:
            - docker: {}
          kubernetes_sd_configs:
          - role: pod
          relabel_configs:
          - action: drop
            regex: .+
            separator: ''
            source_labels:
            - __meta_kubernetes_pod_label_name
            - __meta_kubernetes_pod_label_app
          - action: keep
            regex: '[0-9a-z-.]+-[0-9a-f]{8,10}'
            source_labels:
            - __meta_kubernetes_pod_controller_name
          - action: replace
            regex: '([0-9a-z-.]+)-[0-9a-f]{8,10}'
            source_labels:
            - __meta_kubernetes_pod_controller_name
            target_label: __service__
          - source_labels:
            - __meta_kubernetes_pod_node_name
            target_label: __host__
          - action: drop
            regex: ''
            source_labels:
            - __service__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            replacement: $1
            separator: /
            source_labels:
            - __meta_kubernetes_namespace
            - __service__
            target_label: job
          - action: replace
            source_labels:
            - __meta_kubernetes_namespace
            target_label: namespace
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_name
            target_label: pod
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_container_name
            target_label: container
          - replacement: /var/log/pods/*$1/*.log
            separator: /
            source_labels:
            - __meta_kubernetes_pod_uid
            - __meta_kubernetes_pod_container_name
            target_label: __path__
        - job_name: kubernetes-pods-static
          pipeline_stages:
            - docker: {}
          kubernetes_sd_configs:
          - role: pod
          relabel_configs:
          - action: drop
            regex: ''
            source_labels:
            - __meta_kubernetes_pod_annotation_kubernetes_io_config_mirror
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_label_component
            target_label: __service__
          - source_labels:
            - __meta_kubernetes_pod_node_name
            target_label: __host__
          - action: drop
            regex: ''
            source_labels:
            - __service__
          - action: labelmap
            regex: __meta_kubernetes_pod_label_(.+)
          - action: replace
            replacement: $1
            separator: /
            source_labels:
            - __meta_kubernetes_namespace
            - __service__
            target_label: job
          - action: replace
            source_labels:
            - __meta_kubernetes_namespace
            target_label: namespace
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_name
            target_label: pod
          - action: replace
            source_labels:
            - __meta_kubernetes_pod_container_name
            target_label: container
          - replacement: /var/log/pods/*$1/*.log
            separator: /
            source_labels:
            - __meta_kubernetes_pod_annotation_kubernetes_io_config_mirror
            - __meta_kubernetes_pod_container_name
            target_label: __path__
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272

    promtail-daemonset.yaml 配置文件的内容如下:

    apiVersion: apps/v1
    kind: DaemonSet
    metadata:
      name: loki-promtail
      namespace: logging
      labels:
        app: promtail
    spec:
      selector:
        matchLabels:
          app: promtail
      updateStrategy:
        rollingUpdate:
          maxUnavailable: 1
        type: RollingUpdate
      template:
        metadata:
          labels:
            app: promtail
        spec:
          serviceAccountName: loki-promtail
          containers:
            - name: promtail
              image: grafana/promtail:2.3.0
              imagePullPolicy: IfNotPresent
              args: 
              - -config.file=/etc/promtail/promtail.yaml
              - -client.url=http://192.168.16.40:30201/loki/api/v1/push
              env: 
              - name: HOSTNAME
                valueFrom: 
                  fieldRef: 
                    apiVersion: v1
                    fieldPath: spec.nodeName
              volumeMounts:
              - mountPath: /etc/promtail
                name: config
              - mountPath: /run/promtail
                name: run
              - mountPath: /var/lib/docker/containers
                name: docker
                readOnly: true
              - mountPath: /var/log/pods
                name: pods
                readOnly: true
              ports:
              - containerPort: 3101
                name: http-metrics
                protocol: TCP
              securityContext:
                readOnlyRootFilesystem: true
                runAsGroup: 0
                runAsUser: 0
              readinessProbe:
                failureThreshold: 5
                httpGet:
                  path: /ready
                  port: http-metrics
                  scheme: HTTP
                initialDelaySeconds: 10
                periodSeconds: 10
                successThreshold: 1
                timeoutSeconds: 1
          tolerations:
          - effect: NoSchedule
            key: node-role.kubernetes.io/master
            operator: Exists
          volumes:
            - name: config
              configMap:
                name: loki-promtail
            - name: run
              hostPath:
                path: /run/promtail
                type: ""
            - name: docker
              hostPath:
                path: /var/lib/docker/containers
            - name: pods
              hostPath:
                path: /var/log/pods
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81

    上述配置修改注意点:
    (1)同样namespace需要与步骤一中的保持一致
    (2)如下位置需要修改为步骤三中配置的 Loki 的地址
    在这里插入图片描述

    4.2 部署 Promtail

    进入 promtail 目录,然后执行部署命令即可

    cd promtail
    kubectl apply -f .
    
    • 1
    • 2

    五、检查部署结果

    5.1 Kubernetes后台检查Pod部署状态

    执行如下命令即可查看pod状态,均为running时表示部署OK

    [root@master ~]# kubectl get pod -n logging
    NAME                       READY   STATUS    RESTARTS   AGE
    grafana-66496d957f-ngq5g   1/1     Running   0          21h
    loki-0                     1/1     Running   0          24h
    loki-promtail-8vjd6        1/1     Running   0          20h
    loki-promtail-gmr5f        1/1     Running   0          20h
    loki-promtail-svwtn        1/1     Running   0          20h
    loki-promtail-tnvr9        1/1     Running   0          20h
    [root@master ~]#
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    5.2 浏览器打开grafana界面如下,表示OK

    比如 192.168.16.40:30200,如下表示部署OK
    在这里插入图片描述
    Loki数据源
    在这里插入图片描述

    参考链接:
    https://blog.csdn.net/redrose2100/article/details/126851964
    https://blog.csdn.net/tianmingqing0806/article/details/126766308

  • 相关阅读:
    校园防疫管理系统功能详解,请查看
    神经网络模型的训练过程,怎么训练神经网络模型
    Jmeter 性能测试如何设计混合场景
    SpringBoot3集成PostgreSQL
    【【萌新的Risc-V学习之再看读不懂的流水线设计-10】】
    vue项目部署,出现两个ip的原因
    【计算机视觉40例】案例38:驾驶员疲劳监测
    点云从入门到精通技术详解100篇-基于三维点云的并联机器人 抓取
    麻了,别再为难软件测试员了
    OpenGL(十九)——Qt OpenGL波动纹理(旗子的飘动效果)
  • 原文地址:https://blog.csdn.net/ichen820/article/details/134287977