在 Kubernetes 中配置 Loki 时出现“不允许顶级‘配置’”错误我

问题描述 投票:0回答:1

我正在尝试配置 Loki 以登录我的 Kubernetes 集群,但我不断收到以下错误消息:

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

这是我当前的 main.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
放在
config
下方的
values:
上方,但它不会改变任何内容。

kubernetes kubernetes-helm azure-aks grafana-loki
1个回答
0
投票

查看文档,这些设置似乎应该位于

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.podAnnotations
gateway.podAnnotations
等,但我没有看到顶级
podAnnotations
)。

© www.soinside.com 2019 - 2024. All rights reserved.