首页 > 解决方案 > Grafana 正在使用基本 URL 生成链接:http://localhost:3000 而不是使用我的 url

问题描述

我用 Kubernetes 部署了 grafana 7,这是我的部署:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-core
  namespace: monitoring
  labels:
    app: grafana
    component: core
spec:
  selector:
    matchLabels:
      app: grafana

  replicas: 1
  template:
    metadata:
      labels:
        app: grafana
        component: core
    spec:
      initContainers:
      - name: init-chown-data
        image: grafana/grafana:7.0.3
        imagePullPolicy: IfNotPresent
        securityContext:
          runAsUser: 0
        command: ["chown", "-R", "472:472", "/var/lib/grafana"]
        volumeMounts:
        - name: grafana-persistent-storage
          mountPath: /var/lib/grafana
      containers:
      - image: grafana/grafana:7.0.3
        name: grafana-core
        imagePullPolicy: IfNotPresent
        securityContext:
          runAsUser: 472
        # env:
        envFrom:
          - secretRef:
              name: grafana-env
        env:
          # The following env variables set up basic auth twith the default admin user and admin password.
          - name: GF_INSTALL_PLUGINS
            value: grafana-clock-panel,grafana-simple-json-datasource,camptocamp-prometheus-alertmanager-datasource
          - name: GF_AUTH_BASIC_ENABLED
            value: "true"
          - name: GF_SECURITY_ADMIN_USER
            valueFrom:
              secretKeyRef:
                name: grafana
                key: admin-username
          - name: GF_SECURITY_ADMIN_PASSWORD
            valueFrom:
              secretKeyRef:
                name: grafana
                key: admin-password
          - name: GF_AUTH_ANONYMOUS_ENABLED
            value: "false"
        readinessProbe:
          httpGet:
            path: /login
            port: 3000
          initialDelaySeconds: 30
          timeoutSeconds: 1
        volumeMounts:
        - name: grafana-persistent-storage
          mountPath: /var/lib/grafana
        - name: grafana-datasources
          mountPath: /etc/grafana/provisioning/datasources
      volumes:
      - name: grafana-persistent-storage
        persistentVolumeClaim:
          claimName: grafana-storage
      - name: grafana-datasources
        configMap:
          name: grafana-datasources
      nodeSelector:
        kops.k8s.io/instancegroup: monitoring-nodes

它运行良好,但每次生成 URL 时,都会使用基本 url:http://localhost:3000 而不是使用https://grafana.company.com

我在哪里可以配置?我找不到处理它的环境变量。

标签: grafana

解决方案


将 Grafana 配置文件或环境变量中的root_url选项配置为.[server]GF_SERVER_ROOT_URLhttps://grafana.company.com/


推荐阅读