ingress-nginx-helm/user-guide/monitoring/index.html

59 lines
33 KiB
HTML
Raw Normal View History

2021-08-06 19:42:24 +00:00
<!doctype html><html lang=en class=no-js> <head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><link href=https://kubernetes.github.io/ingress-nginx/user-guide/monitoring/ rel=canonical><link rel="shortcut icon" href=../../assets/images/favicon.png><meta name=generator content="mkdocs-1.1.2, mkdocs-material-6.2.4"><title>Prometheus and Grafana installation - NGINX Ingress Controller</title><link rel=stylesheet href=../../assets/stylesheets/main.15aa0b43.min.css><link rel=stylesheet href=../../assets/stylesheets/palette.75751829.min.css><meta name=theme-color content=#009485><link rel=preconnect href=https://fonts.gstatic.com crossorigin><link rel=stylesheet href="https://fonts.googleapis.com/css?family=Roboto:300,400,400i,700%7CRoboto+Mono&display=fallback"><style>body,input{font-family:"Roboto",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif}code,kbd,pre{font-family:"Roboto Mono",SFMono-Regular,Consolas,Menlo,monospace}</style><link rel=stylesheet href=../../extra.css><script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-118407822-1","kubernetes.github.io"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})}),document.addEventListener("DOMContentSwitch",function(){ga("send","pageview",document.location.pathname)})</script><script async src=https://www.google-analytics.com/analytics.js></script></head> <body dir=ltr data-md-color-scheme data-md-color-primary=teal data-md-color-accent=green> <input class=md-toggle data-md-toggle=drawer type=checkbox id=__drawer autocomplete=off> <input class=md-toggle data-md-toggle=search type=checkbox id=__search autocomplete=off> <label class=md-overlay for=__drawer></label> <div data-md-component=skip> <a href=#prometheus-and-grafana-installation class=md-skip> Skip to content </a> </div> <div data-md-component=announce> </div> <header class=md-header data-md-component=header> <nav class="md-header-nav md-grid" aria-label=Header> <a href=https://kubernetes.github.io/ingress-nginx title="NGINX Ingress Controller" class="md-header-nav__button md-logo" aria-label="NGINX Ingress Controller"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M12 8a3 3 0 003-3 3 3 0 00-3-3 3 3 0 00-3 3 3 3 0 003 3m0 3.54C9.64 9.35 6.5 8 3 8v11c3.5 0 6.64 1.35 9 3.54 2.36-2.19 5.5-3.54 9-3.54V8c-3.5 0-6.64 1.35-9 3.54z"/></svg> </a> <label class="md-header-nav__button md-icon" for=__drawer> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M3 6h18v2H3V6m0 5h18v2H3v-2m0 5h18v2H3v-2z"/></svg> </label> <div class=md-header-nav__title data-md-component=header-title> <div class=md-header-nav__ellipsis> <div class=md-header-nav__topic> <span class=md-ellipsis> NGINX Ingress Controller </span> </div> <div class=md-header-nav__topic> <span class=md-ellipsis> Prometheus and Grafana installation </span> </div> </div> </div> <label class="md-header-nav__button md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.516 6.516 0 019.5 16 6.5 6.5 0 013 9.5 6.5 6.5 0 019.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5z"/></svg> </label> <div class=md-search data-md-component=search role=dialog> <label class=md-search__overlay for=__search></label> <div class=md-search__inner role=search> <form class=md-search__form name=search> <input type=text class=md-search__input name=query aria-label=Search placeholder=Search autocapitalize=off autocorrect=off autocomplete=off spellcheck=false data-md-component=search-query data-md-state=active required> <label class="md-search__icon md-icon" for=__search> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0116 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-
2021-07-29 21:24:20 +00:00
--namespace ingress-nginx \
--set controller.metrics.enabled=true \
--set-string controller.podAnnotations.&quot;prometheus\.io/scrape&quot;=&quot;true&quot; \
--set-string controller.podAnnotations.&quot;prometheus\.io/port&quot;=&quot;10254&quot;
</code></pre></div></p> </li> <li>You can validate that the controller is configured for metrics by looking at the values of the installed release, like this ; <div class=highlight><pre><span></span><code>helm get values ingress-controller --namespace ingress-nginx
</code></pre></div></li> <li>You should be able to see the values shown below ; <div class=highlight><pre><span></span><code>..
controller:
metrics:
enabled: true
service:
annotations:
prometheus.io/port: &quot;10254&quot;
prometheus.io/scrape: &quot;true&quot;
..
2021-08-06 18:58:34 +00:00
</code></pre></div></li> <li> <p>If you are <strong>not using helm</strong>, you will have to edit your manifests like this:</p> <ul> <li> <p>Service manifest: <div class=highlight><pre><span></span><code>apiVersion: v1
kind: Service
metadata:
annotations:
prometheus.io/scrape: &quot;true&quot;
prometheus.io/port: &quot;10254&quot;
..
spec:
ports:
- name: prometheus
port: 10254
targetPort: prometheus
..
</code></pre></div></p> </li> <li> <p>DaemonSet manifest: <div class=highlight><pre><span></span><code>..
ports:
- name: prometheus
containerPort: 10254
..
2021-08-07 00:08:36 +00:00
</code></pre></div></p> </li> </ul> </li> </ul> <h2 id=deploy-and-configure-prometheus-server>Deploy and configure Prometheus Server<a class=headerlink href=#deploy-and-configure-prometheus-server title="Permanent link"></a></h2> <p>Note that the kustomize bases used in this tutorial are stored in the <a href=https://github.com/kubernetes/ingress-nginx/tree/main/deploy>deploy</a> folder of the GitHub repository <a href=https://github.com/kubernetes/ingress-nginx>kubernetes/ingress-nginx</a>.</p> <ul> <li> <p>The Prometheus server must be configured so that it can discover endpoints of services. If a Prometheus server is already running in the cluster and if it is configured in a way that it can find the ingress controller pods, no extra configuration is needed.</p> </li> <li> <p>If there is no existing Prometheus server running, the rest of this tutorial will guide you through the steps needed to deploy a properly configured Prometheus server.</p> </li> <li> <p>Running the following command deploys prometheus in Kubernetes:</p> </li> </ul> <div class=highlight><pre><span></span><code>kubectl apply --kustomize github.com/kubernetes/ingress-nginx/deploy/prometheus/
2021-07-29 21:24:20 +00:00
</code></pre></div> <h3 id=prometheus-dashboard>Prometheus Dashboard<a class=headerlink href=#prometheus-dashboard title="Permanent link"></a></h3> <ul> <li>Open Prometheus dashboard in a web browser:</li> </ul> <div class=highlight><pre><span></span><code><span class=go>kubectl get svc -n ingress-nginx</span>
2021-01-11 15:59:14 +00:00
<span class=go>NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE</span>
<span class=go>default-http-backend ClusterIP 10.103.59.201 &lt;none&gt; 80/TCP 3d</span>
<span class=go>ingress-nginx NodePort 10.97.44.72 &lt;none&gt; 80:30100/TCP,443:30154/TCP,10254:32049/TCP 5h</span>
<span class=go>prometheus-server NodePort 10.98.233.86 &lt;none&gt; 9090:32630/TCP 1m</span>
2021-07-29 21:24:20 +00:00
</code></pre></div> <ul> <li>Obtain the IP address of the nodes in the running cluster:</li> </ul> <div class=highlight><pre><span></span><code><span class=go>kubectl get nodes -o wide</span>
</code></pre></div> <ul> <li>In some cases where the node only have internal IP addresses we need to execute:</li> </ul> <div class=highlight><pre><span></span><code>kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\&quot;InternalIP\&quot;\)].address}
10.192.0.2 10.192.0.3 10.192.0.4
</code></pre></div> <ul> <li> <p>Open your browser and visit the following URL: <em>http://{node IP address}:{prometheus-svc-nodeport}</em> to load the Prometheus Dashboard.</p> </li> <li> <p>According to the above example, this URL will be http://10.192.0.3:32630</p> </li> </ul> <p><img alt="Prometheus Dashboard" src=../../images/prometheus-dashboard.png></p> <h3 id=grafana>Grafana<a class=headerlink href=#grafana title="Permanent link"></a></h3> <ul> <li>Install grafana using the below command <div class=highlight><pre><span></span><code>kubectl apply --kustomize github.com/kubernetes/ingress-nginx/deploy/grafana/
</code></pre></div></li> <li> <p>Look at the services <div class=highlight><pre><span></span><code>kubectl get svc -n ingress-nginx
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
default-http-backend ClusterIP 10.103.59.201 &lt;none&gt; 80/TCP 3d
ingress-nginx NodePort 10.97.44.72 &lt;none&gt; 80:30100/TCP,443:30154/TCP,10254:32049/TCP 5h
prometheus-server NodePort 10.98.233.86 &lt;none&gt; 9090:32630/TCP 10m
grafana NodePort 10.98.233.87 &lt;none&gt; 3000:31086/TCP 10m
2021-08-07 00:08:36 +00:00
</code></pre></div></p> </li> <li> <p>Open your browser and visit the following URL: <em>http://{node IP address}:{grafana-svc-nodeport}</em> to load the Grafana Dashboard. According to the above example, this URL will be http://10.192.0.3:31086</p> </li> </ul> <p>The username and password is <code>admin</code></p> <ul> <li> <p>After the login you can import the Grafana dashboard from <a href=https://github.com/kubernetes/ingress-nginx/tree/main/deploy/grafana/dashboards>official dashboards</a>, by following steps given below :</p> <ul> <li>Navigate to lefthand panel of grafana</li> <li>Hover on the gearwheel icon for Configuration and click "Data Sources"</li> <li>Click "Add data source"</li> <li>Select "Prometheus"</li> <li>Enter the details (note: I used http://CLUSTER_IP_PROMETHEUS_SVC:9090)</li> <li>Left menu (hover over +) -&gt; Dashboard</li> <li>Click "Import"</li> <li>Enter the copy pasted json from https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/grafana/dashboards/nginx.json</li> <li>Click Import JSON</li> <li>Select the Prometheus data source</li> <li>Click "Import"</li> </ul> </li> </ul> <p><img alt="Grafana Dashboard" src=../../images/grafana.png></p> <h2 id=caveats>Caveats<a class=headerlink href=#caveats title="Permanent link"></a></h2> <h3 id=wildcard-ingresses>Wildcard ingresses<a class=headerlink href=#wildcard-ingresses title="Permanent link"></a></h3> <ul> <li>By default request metrics are labeled with the hostname. When you have a wildcard domain ingress, then there will be no metrics for that ingress (to prevent the metrics from exploding in cardinality). To get metrics in this case you need to run the ingress controller with <code>--metrics-per-host=false</code> (you will lose labeling by hostname, but still have labeling by ingress).</li> </ul> <h2 id=grafana-dashboard-using-ingress-resource>Grafana dashboard using ingress resource<a class=headerlink href=#grafana-dashboard-using-ingress-resource title="Permanent link"></a></h2> <ul> <li>If you want to expose the dashboard for grafana using a ingress resource, then you can : <ul> <li>change the service type of the prometheus-server service and the grafana service to "ClusterIP" like this : <div class=highlight><pre><span></span><code>kubectl -n ingress-nginx edit svc grafana
2021-07-29 21:24:20 +00:00
</code></pre></div></li> <li>This will open the currently deployed service grafana in the default editor configured in your shell (vi/nvim/nano/other)</li> <li>scroll down to line 34 that looks like "type: NodePort"</li> <li>change it to look like "type: ClusterIP". Save and exit.</li> <li>create a ingress reource with backend as "grafana" and port as "3000"</li> </ul> </li> <li>Similarly, you can edit the service "prometheus-server" and add a ingress resource.</li> </ul> </article> </div> </div> </main> <footer class=md-footer> <div class=md-footer-nav> <nav class="md-footer-nav__inner md-grid" aria-label=Footer> <a href=../miscellaneous/ class="md-footer-nav__link md-footer-nav__link--prev" rel=prev> <div class="md-footer-nav__button md-icon"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg> </div> <div class=md-footer-nav__title> <div class=md-ellipsis> <span class=md-footer-nav__direction> Previous </span> Miscellaneous </div> </div> </a> <a href=../multiple-ingress/ class="md-footer-nav__link md-footer-nav__link--next" rel=next> <div class=md-footer-nav__title> <div class=md-ellipsis> <span class=md-footer-nav__direction> Next </span> Multiple Ingress controllers </div> </div> <div class="md-footer-nav__button md-icon"> <svg xmlns=http://www.w3.org/2000/svg viewbox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11H4z"/></svg> </div> </a> </nav> </div> <div class="md-footer-meta md-typeset"> <div class="md-footer-meta__inner md-grid"> <div class=md-footer-copyright> Made with <a href=https://squidfunk.github.io/mkdocs-material/ target=_blank rel=noopener> Material for MkDocs </a> </div> </div> </div> </footer> </div> <script src=../../assets/javascripts/vendor.93c04032.min.js></script> <script src=../../assets/javascripts/bundle.83e5331e.min.js></script><script id=__lang type=application/json>{"clipboard.copy": "Copy to clipboard", "clipboard.copied": "Copied to clipboard", "search.config.lang": "en", "search.config.pipeline": "trimmer, stopWordFilter", "search.config.separator": "[\\s\\-]+", "search.placeholder": "Search", "search.result.placeholder": "Type to start searching", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.term.missing": "Missing"}</script> <script>
2020-04-15 17:09:38 +00:00
app = initialize({
base: "../..",
2021-01-11 15:59:14 +00:00
features: ['navigation.tabs', 'navigation.tabs.sticky', 'navigation.instant', 'navigation.sections'],
2020-04-15 17:09:38 +00:00
search: Object.assign({
2021-01-11 15:59:14 +00:00
worker: "../../assets/javascripts/worker/search.8c7e0a7e.min.js"
2020-04-15 17:09:38 +00:00
}, typeof search !== "undefined" && search)
})
2021-01-11 15:59:14 +00:00
</script> </body> </html>