<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kiran Mova</title>
    <description>The latest articles on DEV Community by Kiran Mova (@kiranmova).</description>
    <link>https://dev.to/kiranmova</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F274303%2Fd8329479-8621-4b26-90fd-f15d1f6ed5bc.jpg</url>
      <title>DEV Community: Kiran Mova</title>
      <link>https://dev.to/kiranmova</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kiranmova"/>
    <language>en</language>
    <item>
      <title>Accessing Grafana via SSH Tunneling</title>
      <dc:creator>Kiran Mova</dc:creator>
      <pubDate>Sat, 09 May 2020 13:31:17 +0000</pubDate>
      <link>https://dev.to/kiranmova/accessing-grafana-via-ssh-tunneling-5gi9</link>
      <guid>https://dev.to/kiranmova/accessing-grafana-via-ssh-tunneling-5gi9</guid>
      <description>&lt;p&gt;Here is a quick guide "how-to" for configuring Prometheus and Grafana on Kubernetes Cluster that is behind firewalls and accessing the Grafana UI from a remote machine (your laptop at home) using SSH tunneling. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setup Helm 3
&lt;/h2&gt;

&lt;p&gt;You can use Helm 2 as well or skip this step if you already have helm installed. &lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Install Helm 3
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 2: Add Stable Charts
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;helm repo add stable https://kubernetes-charts.storage.googleapis.com/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Setup Prometheus and Grafana using Prometheus Operator
&lt;/h2&gt;

&lt;p&gt;This is the easiest way to setup Prometheus and Grafana, and have the Grafana configured to use Prometheus as a data source. &lt;/p&gt;

&lt;h4&gt;
  
  
  Step 3: Install Prometheus Operator
&lt;/h4&gt;

&lt;p&gt;In my case, the Kubernetes cluster is behind a firewall. I am configuring the Granfana to be accessible via NodePort, as I need to access the Grafana UI using ssh tunnel.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl create namespace prometheus-operator
helm install prometheus-operator stable/prometheus-operator -n prometheus-operator --set prometheusOperator.createCustomResource=false,grafana.service.type=NodePort
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 4: Verify
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get pods -n prometheus-operator
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above commands should show that all promtheus operator, prometheus, node exporter and grafana pods are running.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                                                     READY   STATUS    RESTARTS   AGE
alertmanager-prometheus-operator-alertmanager-0          2/2     Running   0          30m
prometheus-operator-grafana-cf6954699-5rcgl              2/2     Running   0          30m
prometheus-operator-kube-state-metrics-5fdcd78bc-sckjv   1/1     Running   0          30m
prometheus-operator-operator-5dd8f8f568-52qk8            2/2     Running   0          30m
prometheus-operator-prometheus-node-exporter-p8pm8       1/1     Running   0          30m
prometheus-operator-prometheus-node-exporter-trlhp       1/1     Running   0          30m
prometheus-operator-prometheus-node-exporter-wsm4n       1/1     Running   0          30m
prometheus-prometheus-operator-prometheus-0              3/3     Running   1          30m
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;kubectl get svc -n prometheus-operator
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Note that Grafana alone is running on NodePort&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NAME                                           TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
alertmanager-operated                          ClusterIP   None            &amp;lt;none&amp;gt;        9093/TCP,9094/TCP,9094/UDP   31m
prometheus-operated                            ClusterIP   None            &amp;lt;none&amp;gt;        9090/TCP                     30m
prometheus-operator-alertmanager               ClusterIP   10.102.104.48   &amp;lt;none&amp;gt;        9093/TCP                     31m
prometheus-operator-grafana                    NodePort    10.96.160.172   &amp;lt;none&amp;gt;        80:31409/TCP                 31m
prometheus-operator-kube-state-metrics         ClusterIP   10.105.92.154   &amp;lt;none&amp;gt;        8080/TCP                     31m
prometheus-operator-operator                   ClusterIP   10.99.15.245    &amp;lt;none&amp;gt;        8080/TCP,443/TCP             31m
prometheus-operator-prometheus                 ClusterIP   10.109.75.138   &amp;lt;none&amp;gt;        9090/TCP                     31m
prometheus-operator-prometheus-node-exporter   ClusterIP   10.98.128.115   &amp;lt;none&amp;gt;        9100/TCP                     31m
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Configure SSH Tunnesl to access Grafana UI
&lt;/h2&gt;

&lt;p&gt;You can skip this step, if you direct access to the Kubernetes Worker node IP from your machines. &lt;/p&gt;

&lt;h4&gt;
  
  
  Windows using PuTTY
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Get the Kubernetes Worker Node IP and the Grafana Node Port. &lt;/li&gt;
&lt;li&gt;Get the SSH server using which, Kubernetes Worker Node IP is accessible. Say this is Landing IP. &lt;/li&gt;
&lt;li&gt;Configure the PuTTY as follows:

&lt;ul&gt;
&lt;li&gt;Create a new Session with Landing IP, Landing Port&lt;/li&gt;
&lt;li&gt;Create a Connection -&amp;gt; SSH -&amp;gt; Tunnels
&lt;/li&gt;
&lt;li&gt;Source Port = Grafana NodePort&lt;/li&gt;
&lt;li&gt;Destination = Kubernetes Worker Node IP:Grafana Node Port&lt;/li&gt;
&lt;li&gt;Open the PuTTY session. Enter SSH user name and passowrd for the Landing IP. &lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;Now you can access Grafana UI at the following URL. Default login and password ( admin/prom-operator )
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  http://localhost:&amp;lt;Grafana-Node-Port&amp;gt;/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  Linux using SSH
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Get the Kubernetes Worker Node IP and the Grafana Node Port. &lt;/li&gt;
&lt;li&gt;Get the SSH server using which, Kubernetes Worker Node IP is accessible. Say this is Landing IP. &lt;/li&gt;
&lt;li&gt;Open SSH tunnel using the following command.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  ssh -NL &amp;lt;Grafana-Node-Port&amp;gt;:&amp;lt;k8s-worker-node-IP&amp;gt;:&amp;lt;Grafana-Node-Port&amp;gt; &amp;lt;landing-machine-user&amp;gt;@&amp;lt;landing-machine-ip&amp;gt; -p &amp;lt;landing-machine-ssh-port&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now you can access Grafana UI at &lt;code&gt;http://localhost:&amp;lt;Grafana-Node-Port&amp;gt;/&lt;/code&gt;. Default login and password ( admin/prom-operator )&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Verify Granafa Dashboard
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Login to Granfa UI &lt;/li&gt;
&lt;li&gt;Click on Settings -&amp;gt; Data Source. You must see a Default Prometheus data source for &lt;code&gt;http://prometheus-operator-prometheus:9090/&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on Dashboards -&amp;gt; Manage Dashboards. You must see a list of dashboards. Click on any of them like: &lt;code&gt;kubernetes-compute-resources-cluster&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You must see some colors like:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cg0sDdq3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/kmova/bootstrap/blob/master/prometheus_operator/grafana_prom_operator.png%3Fraw%3Dtrue" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cg0sDdq3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://github.com/kmova/bootstrap/blob/master/prometheus_operator/grafana_prom_operator.png%3Fraw%3Dtrue" alt="Grafana"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  References:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://helm.sh/docs/intro/install/"&gt;https://helm.sh/docs/intro/install/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/helm/charts/issues/19452"&gt;https://github.com/helm/charts/issues/19452&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.linode.com/docs/networking/ssh/using-ssh-on-windows/#ssh-tunneling-port-forwarding"&gt;https://www.linode.com/docs/networking/ssh/using-ssh-on-windows/#ssh-tunneling-port-forwarding&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/helm/charts/tree/master/stable/prometheus-operator"&gt;https://github.com/helm/charts/tree/master/stable/prometheus-operator&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/helm/charts/tree/master/stable/grafana#configuration"&gt;https://github.com/helm/charts/tree/master/stable/grafana#configuration&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>prometheus</category>
      <category>grafana</category>
      <category>kubernetes</category>
      <category>remote</category>
    </item>
  </channel>
</rss>
