</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 ; <divclass=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 ; <divclass=highlight><pre><span></span><code>..
</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: <divclass=highlight><pre><span></span><code>apiVersion: v1
</code></pre></div></p></li></ul></li></ul><h2id=deploy-and-configure-prometheus-server>Deploy and configure Prometheus Server<aclass=headerlinkhref=#deploy-and-configure-prometheus-servertitle="Permanent link"> ¶</a></h2><p>Note that the kustomize bases used in this tutorial are stored in the <ahref=https://github.com/kubernetes/ingress-nginx/tree/main/deploy>deploy</a> folder of the GitHub repository <ahref=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><divclass=highlight><pre><span></span><code>kubectl apply --kustomize github.com/kubernetes/ingress-nginx/deploy/prometheus/
</code></pre></div><h3id=prometheus-dashboard>Prometheus Dashboard<aclass=headerlinkhref=#prometheus-dashboardtitle="Permanent link"> ¶</a></h3><ul><li>Open Prometheus dashboard in a web browser:</li></ul><divclass=highlight><pre><span></span><code><spanclass=go>kubectl get svc -n ingress-nginx</span>
</code></pre></div><ul><li>Obtain the IP address of the nodes in the running cluster:</li></ul><divclass=highlight><pre><span></span><code><spanclass=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><divclass=highlight><pre><span></span><code>kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[*].status.addresses[?\(@.type==\"InternalIP\"\)].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><imgalt="Prometheus Dashboard"src=../../images/prometheus-dashboard.png></p><h3id=grafana>Grafana<aclass=headerlinkhref=#grafanatitle="Permanent link"> ¶</a></h3><ul><li>Install grafana using the below command <divclass=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 <divclass=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 <none> 80/TCP 3d
</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 <ahref=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 +) -> 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><imgalt="Grafana Dashboard"src=../../images/grafana.png></p><h2id=caveats>Caveats<aclass=headerlinkhref=#caveatstitle="Permanent link"> ¶</a></h2><h3id=wildcard-ingresses>Wildcard ingresses<aclass=headerlinkhref=#wildcard-ingressestitle="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><h2id=grafana-dashboard-using-ingress-resource>Grafana dashboard using ingress resource<aclass=headerlinkhref=#grafana-dashboard-using-ingress-resourcetitle="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 : <divclass=highlight><pre><span></span><code>kubectl -n ingress-nginx edit svc grafana
</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><footerclass=md-footer><divclass=md-footer-nav><navclass="md-footer-nav__inner md-grid"aria-label=Footer><ahref=../miscellaneous/class="md-footer-nav__link md-footer-nav__link--prev"rel=prev><divclass="md-footer-nav__button md-icon"><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11h12z"/></svg></div><divclass=md-footer-nav__title><divclass=md-ellipsis><spanclass=md-footer-nav__direction> Previous </span> Miscellaneous </div></div></a><ahref=../multiple-ingress/class="md-footer-nav__link md-footer-nav__link--next"rel=next><divclass=md-footer-nav__title><divclass=md-ellipsis><spanclass=md-footer-nav__direction> Next </span> Multiple Ingress controllers </div></div><divclass="md-footer-nav__button md-icon"><svgxmlns=http://www.w3.org/2000/svgviewbox="0 0 24 24"><pathd="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><divclass="md-footer-meta md-typeset"><divclass="md-footer-meta__inner md-grid"><divclass=md-footer-copyright> Made with <ahref=https://squidfunk.github.io/mkdocs-material/target=_blankrel=noopener> Material for MkDocs </a></div></div></div></footer></div><scriptsrc=../../assets/javascripts/vendor.93c04032.min.js></script><scriptsrc=../../assets/javascripts/bundle.83e5331e.min.js></script><scriptid=__langtype=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>