<p>I'm using the docker image (grafana/grafana:7.4.3). I see there is no curl as part of it.
The grafana API mentioned is a HTTP API and all the example requests and responses use curl. If the maintainers decided to remove curl, may I know what alternative is there so as to perform the request/response from inside the container ?</p>
<p>I understand that we need to deploy, run the image then expose the port and use the curl commands from the host.</p>
<h3>Use case:</h3>
<p>All our monitoring systems have a dashboard. Currently we're saving each of the dashboards into a git repo and manually uploading it to the grafana through the import functionality from UI.</p>
<p>Need to automate the k8s deployment script such that it picks the dashboard.json from the git repo and then imports it to grafana UI.</p>
<h3>What we are doing now</h3>
<ol>
<li>Pulling grafana image as part of the k8s.</li>
<li>Before the image is successfully pulled, I'm adding a command in the spec (given below). Please ignore the admin:admin combo for username and password I'm using. It'll be changed before the deployment from Dev to QA/Stage.</li>
<li>Once the <strong>BEARER_TOKEN</strong> is exported to env, I'm fetching dashboards from a volume mounted. These dashboards are in the JSON format in line with the HTTP API import curl command.</li>
</ol>
<p>Keeping in view my scenario, can anyone suggest ideas which can by pass the need/usage of curl ?</p>
<pre><code>- apiVersion: apps/v1
  kind: Deployment
  metadata:
    labels:
        app: dashboard
    name: dashboard
    namespace: monitoring
    spec:
      template:
        spec:
          containers:
            - name: grafana
              image: 'docker.io/grafana/grafana:7.3.6'
              imagePullPolicy: Always
              env:
                - name: GF_AUTH_BASIC_ENABLED
                  value: &quot;true&quot;
                - name: GF_AUTH_ANONYMOUS_ENABLED
                  value: &quot;true&quot;
                - name: GF_SERVER_ROOT_URL
                  value: &quot;%(protocol)s://%(domain)s:%(http_port)s/grafana/&quot;
              command: [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;apk --no-cache add curl jq &amp;&amp; curl -X POST -H \&quot;Content-Type: application/json\&quot; -d '{\&quot;name\&quot;:\&quot;apikeycurl\&quot;, \&quot;role\&quot;: \&quot;Admin\&quot;}' http://admin:admin@localhost:3000/api/auth/keys -o /tmp/file.json &amp;&amp; export BEARER_TOKEN=$(jq .key /tmp/file.json | grep -o '\&quot;.*\&quot;' | sed 's/\&quot;//g')&quot;]
              args:
                - &quot;apk --no-cache add curl jq&quot;
                - &quot;curl -X POST \
                  -H \&quot;Content-Type: application/json\&quot; 
                  -d '{\&quot;name\&quot;:\&quot;apikeycurl\&quot;, \&quot;role\&quot;: \&quot;Admin\&quot;}' http://admin:admin@localhost:3000/api/auth/keys 
                  -o /tmp/file.json&quot;
                - &quot;export BEARER_TOKEN=$(jq .key /tmp/file.json | grep -o '\&quot;.*\&quot;' | sed 's/\&quot;//g')&quot;
                - &quot;curl -X POST \
                  --insecure -H \&quot;Authorization: Bearer \&quot;$BEARER_TOKEN\&quot; \&quot; \
                  -H \&quot;Content-Type: application/json\&quot; \
                  --show-error \
                  --data-binary @/Users/coder/Work/grafana/dashboards/service-dashboard.json \
                  -i http://localhost:3000/api/dashboards/db&quot;
              terminationMessagePath: /dev/termination-log-grafana
              terminationMessagePolicy: File
              volumeMounts:
                - mountPath: /etc/grafana/provisioning/datasources/
                  name: datasource-volume
                - mountPath: /etc/grafana/provisioning/dashboards/
                  name: dashboard-volume
                - name: secret-volume
                  mountPath: /etc/secret-volume
              securityContext:
                allowPrivilegeEscalation: false
                runAsUser: 0
          restartPolicy: Always
          schedulerName: default-scheduler
          securityContext: {}
          terminationGracePeriodSeconds: 30
          volumes:
            - name: grafana-persistent-storage
              emptyDir: {}
            - configMap:
                defaultMode: 420
                name: grafana-datasource-cm
              name: datasource-volume
            - configMap:
                defaultMode: 420
                name: grafana-dashboard-cm
              name: dashboard-volume
            - name: secret-volume
              secret:
                secretName: grafana-api-key-secret
    status: {}
</code></pre>

user1683894
<p>If you want to use curl you can simply add curl to the grafana image - just write a new Dockerfile that uses <code>grafana/grafana</code> as the base image and installs curl. Build the image, tag it, and upload it to your own container registry e.g. <code>my-container-repo.com/user1683894/grafana:7.3.6</code>. This can be easily be automated for every new grafana version. Or you could put a pre-compiled version of curl someplace accessible like a volume mount.</p>
<p>However, I don't think that using curl is the right approach here. Grafana has a built-in <a href="https://grafana.com/docs/grafana/latest/administration/provisioning/#dashboards" rel="nofollow noreferrer">provisioning mechanism</a> for configuration and dashboards. So a cleaner solution would be to use an <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" rel="nofollow noreferrer">init container</a> to get the latest dashboards from the git repo, and save the files to where grafana expects to find them.</p>
