在Kubernetes中配置Loki时出现“Top level 'config' is not allowed”错误

4sup72z8  于 2023-04-20  发布在  Kubernetes
关注(0)|答案(1)|浏览(154)

我试图在Kubernetes集群中配置Loki以进行日志记录,但我一直收到以下错误消息:

Top level 'config' is not allowed. Most common configuration sections are exposed under the `loki` section. If you need to override the whole config, provide the configuration as a string that can contain template expressions under `loki.config`. Alternatively, you can provide the configuration as an external secret

这是我当前的主.yaml文件

---
- name: Add grafana helm repo
  kubernetes.core.helm_repository:
    name: grafana
    repo_url: "{{loki_repo_url}}"
  check_mode: no
  tags: loki

- name: "Create namespace {{ loki_namespace }}"
  kubernetes.core.k8s:
    state: present
    kubeconfig: "{{ kube_config }}"
    api_version: v1
    apply: yes
    definition:
      kind: Namespace
      metadata:
        name:  "{{ loki_namespace }}"
        annotations:
          scheduler.alpha.kubernetes.io/node-selector: agentpool=system
  tags: loki

- name: "Create caddy sidecar config {{ loki_namespace }}"
  kubernetes.core.k8s:
    kubeconfig: "{{kube_config}}"
    namespace: "{{ loki_namespace }}"
    state: present
    definition:
      apiVersion: v1
      kind: Secret
      metadata:
        name:   caddy-config
      type: Opaque
      stringData:
        Caddyfile : |
          {
           admin off
          }
          :{{ loki_sidecar_port }} {
                  reverse_proxy localhost:{{ loki_port }}
                  header -Server
                  basicauth {
                          {{ loki_user }} {{ loki_password }}
                  }
                  log {
                    format json
                    output stdout
                  }
          }
  tags: loki

- name: "Deploy loki chart version {{loki_chart_version}} on cluster: {{cluster_name}}"
  kubernetes.core.helm:
    atomic: yes
    name: loki
    chart_ref: grafana/loki
    chart_version: "{{loki_chart_version}}"
    release_namespace: "{{loki_namespace}}"
    create_namespace: yes
    kubeconfig: "{{kube_config}}"
    update_repo_cache: no
    wait: yes
    wait_timeout: 5m
    force: no
    state: present
    values:
      # Mandatory label due to Kyverno policy
      podAnnotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "{{ loki_port | string }}"

      terminationGracePeriodSeconds: 300
      service:
        port: "{{ loki_port }}"

      config:
        server:
          http_listen_port: "{{ loki_port }}"
        schema_config:
          configs:
            - from: 2021-09-01
              store: boltdb-shipper
              object_store: azure
              schema: v11
              index:
                prefix: index_
                period: 24h
        storage_config:
          boltdb_shipper:
            shared_store: azure
            active_index_directory: /data/loki/boltdb-shipper-active
            cache_location: /data/loki/boltdb-shipper-cache
            cache_ttl: 24h
          azure:
            container_name: "{{ az_container_name }}"
            account_name: "{{ az_account_name }}"
            account_key: "{{ az_access_key }}"
            request_timeout: 5m
          filesystem:
            directory: /data/loki/chunks
        
        chunk_store_config:
          max_look_back_period: 4464h
        table_manager:
          retention_deletes_enabled: true
          retention_period: 4464h
      extraContainers:
        - name: caddy-sidecar
          image: "docker.io/library/caddy:{{ caddy_version }}"
          args:
            - "caddy"
            - "run"
            - "-config=/etc/caddy/Caddyfile"
            - "-watch"
          ports:
            - name: http-proxy
              containerPort: "{{ loki_sidecar_port }}"
              protocol: TCP
          volumeMounts:
            - name: caddy-config
              mountPath: /etc/caddy
      extraVolumes:
        - name: caddy-config
          secret:
            secretName: caddy-config
      extraPorts:
      ## Additional ports to the loki services. Useful to expose extra container ports.
        - port: "{{ loki_sidecar_port }}"
          protocol: TCP
          name: http-proxy
          targetPort: http-proxy
  tags: loki
  
- name: "Create ingress: {{ loki_namespace }}"
  tags: loki
  kubernetes.core.k8s:
    kubeconfig: "{{kube_config}}"
    namespace: "{{ loki_namespace }}"
    state: present
    definition:
      apiVersion: networking.k8s.io/v1
      kind: Ingress
      #ingressClassName: application-gateway
      metadata:
        name: ingress-loki
        annotations:
          # use the shared ingress-nginx
          cert-manager.io/cluster-issuer: letsencrypt-prod
          kubernetes.io/ingress.class: azure/application-gateway
          appgw.ingress.kubernetes.io/ssl-redirect: "true"
          appgw.ingress.kubernetes.io/health-probe-status-codes: "200-399, 401"
      spec:
        rules:
          - host: "loki.{{ base_domain }}"
            http:
              paths:
                - path: /
                  pathType: Prefix
                  backend:
                    service:
                      name: loki
                      port:
                        number: "{{ loki_sidecar_port }}"
        tls:
          - hosts:
              - "loki.{{ base_domain }}"
            secretName: loki-ingress-cert
...

我不确定我在这里做错了什么。谁能帮助我理解错误消息并修复此配置文件?
我试着把loki放在values:下面的config上面,但它没有改变任何东西。

jyztefdp

jyztefdp1#

看看the documentation,这些设置似乎应该在loki.server下,而不是config.server

- name: "Deploy loki chart version {{loki_chart_version}} on cluster: {{cluster_name}}"
  kubernetes.core.helm:
    atomic: yes
    name: loki
    chart_ref: grafana/loki
    chart_version: "{{loki_chart_version}}"
    release_namespace: "{{loki_namespace}}"
    create_namespace: yes
    kubeconfig: "{{kube_config}}"
    update_repo_cache: no
    wait: yes
    wait_timeout: 5m
    force: no
    state: present
    values:
      # Mandatory label due to Kyverno policy
      podAnnotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "{{ loki_port | string }}"

      terminationGracePeriodSeconds: 300
      service:
        port: "{{ loki_port }}"

      loki:
        server:
          http_listen_port: "{{ loki_port }}"
        schema_config:
          configs:
            - from: 2021-09-01
              store: boltdb-shipper
              object_store: azure
              schema: v11
              index:
                prefix: index_
                period: 24h
        ...

看起来其他几个值也可能拼写错误(例如,有loki.podAnnotationsgateway.podAnnotations等,但我没有看到顶级的podAnnotations)。

相关问题