Adding a new user to Grafana, using provisioning?

I am deploying Grafana with Kubernetes, and have code to stand up the site and provision initial dashboards. I want it to also create a few users for me, after Grafana is stood up.

I see I can do this with a curl command like this:

curl -v --netrc-file <(cat <<< "machine my-grafana.com login admin password admin”) -k -XPOST -H "Content-Type: application/json" -d '{ "name":"User", "email":"user@graf.com", "login":"user", "password":"userpassword"}' https://my-grafana.com:/api/admin/users;

I initially tried to call the curl command from deployment.yaml, but it kept failing. I got errors that it could not fild file or directory, that username or password were incorrect, and SSL_ERROR_SYSCAL at various times.

I then tried creating a Kubernetes job for this, something that looks like the below:

apiVersion: batch/v1
kind: Job
metadata:
  name: grafana-add-user-job
spec:
  template:
    spec:
      restartPolicy: OnFailure
      containers:
      - name: grafana-add-user-job
        image: my-image:1.0
        args: []
        command:
          - /bin/bash
          - -c
          - >-
            curl -v --netrc-file <(cat <<< "machine my-grafana.com login admin password admin”) -k -XPOST -H "Content-Type: application/json" -d '{ "name":"User", "email":"user@graf.com", "login":"user", "password":"userpassword"}' https://my-grafana.com:/api/admin/users;
        env:
          - name: GRAFANA_ENV
            value: my-grafana.com
          - name: GF_SECURITY_ADMIN_PASSWORD
            valueFrom:
              secretKeyRef:
                name: grafana-admin-credentials
                key: password
  backoffLimit: 2

Again this curl command works locally, but inside of the job it is getting connection denied. It is not clear if the container has proper networking in order to reach grafana or if it needs to be reached by some other path.

Is there something I’m missing with this job … or is there some easier way to provision users?

This topic was automatically closed after 365 days. New replies are no longer allowed.