<p>To use alert by E-mail in Grafana, we have to set SMTP settings in grafana.ini.</p>
<p>On Ubuntu, we can easily run the grafana-prometheus-k8s stack by command
<code>microk8s enable prometheus</code>
However, how can we feed grafana.ini to grafana running in a k8s pod?</p>

Meng-Yuan Huang
<p>We can modify grafana k8s deployment manifest by <strong>volumeMounts</strong> to feed grafana.ini on our host to grafana running in a pod.</p>
<p>First, prepare your grafana.ini with SMTP settings. E.g.</p>
<pre><code>[smtp]
enabled = true
host = smtp.gmail.com:465
# Please change user and password to your ones.
user = foo@bar.com
password = your-password
</code></pre>
<p>Then, you can place this file on your host. E.g. <code>/home/mydir/grafana.ini</code></p>
<p>Modify the loaded grafana k8s deployment manifest:</p>
<pre><code>kubectl edit deployments.apps -n monitoring grafana
</code></pre>
<p>Add a new mount to <strong>volumeMounts</strong> (not the one in <code>kubectl.kubernetes.io/last-applied-configuration</code>):</p>
<pre><code>        volumeMounts:
        - mountPath: /etc/grafana/grafana.ini
          name: mydir
          subPath: grafana.ini
</code></pre>
<p>Add a new <strong>hostPath</strong> to <strong>volumes</strong>:</p>
<pre><code>      volumes:
      - hostPath:
          path: /home/mydir
          type: &quot;&quot;
        name: mydir
</code></pre>
<p>Finally, restart the deployment:</p>
<pre><code>kubectl rollout restart -n monitoring deployment grafana
</code></pre>
<p>Run this command and use a web browser on your host to navigate to http://localhost:8080 to grafana web app:</p>
<pre><code>kubectl port-forward -n monitoring svc/grafana 8080:3000
</code></pre>
<p>Then, you can navigate to Alerting / Notification channels / Add channel to add an Email notification channel and test it!</p>
