Juliatzin
Juliatzin

Reputation: 19695

Grafana is generating links with Base URL : http://localhost:3000 instead of using my url

I deployed grafana 7 with Kubernetes, here is my deployment:

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

It is working well, but each time it generates an URL, it does it with base url : http://localhost:3000 instead of using https://grafana.company.com

Where can I configure that ? I couldn't find a env var that handle it.

Upvotes: 4

Views: 8301

Answers (2)

Eljah
Eljah

Reputation: 5155

I have fount it can be done through using the env variable inside the grafana pod. This set up is a tricky one, misuse of the url format of the GF_SERVER_ROOT_URL to your.url with no quotes, "your.url" without https:// or http:// and even "http://your.url" with no / at the end may cause problems.

grafana:
  env:
    GF_SERVER_ROOT_URL: "http://your.url/"
  notifiers:
    notifiers.yaml:
      notifiers:
      - name: telegram
        type: telegram
        uid: telegram
        is_default: true
        settings:
          bottoken: "yourbottoken"
          chatid: "-yourchatid"

and then use uid: "telegram" in the provisioned dashboards

Upvotes: 1

Jan Garaj
Jan Garaj

Reputation: 28656

Configure the root_url option of [server] in your Grafana config file or env variable GF_SERVER_ROOT_URL to https://grafana.company.com/.

Upvotes: 6

Related Questions