<p>I have deployed prometheus server(2.13.1) on kubernetes(1.17.3), I am able to access it on <code>http://my.prom.com:9090</code></p>

<p>But i want to access it on <code>http://my.prom.com:9090/prometheus</code> so i added following ingress rules but its not 
working</p>

<p><strong>First Try:</strong></p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/app-root: /prometheus
  name: approot
  namespace: default
spec:
  rules:
  - host: my.prom.com
    http:
      paths:
      - backend:
          serviceName: prometheus-svc
          servicePort: 9090
        path: /
</code></pre>

<p>This results in 404 error</p>

<p><strong>Second Try:</strong></p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /$2
  name: rewrite
  namespace: default
spec:
  rules:
  - host: my.prom.com
    http:
      paths:
      - backend:
          serviceName: prometheus-svc
          servicePort: 9090
        path: /prometheus(/|$)(.*)
</code></pre>

<p>Now when i access URL <code>http://my.prom.com:9090/prometheus</code> in browser it get changed to <code>http://my.prom.com:9090/graph</code> and show 404 error</p>

ImranRazaKhan
<p>Prometheus is not aware of what you are trying to achieve and that's why it's redirecting to unknown destination. </p>

<p>You have to tell prometheus to accept traffic on the new path as can be seen <a href="https://www.robustperception.io/external-urls-and-path-prefixes" rel="noreferrer">here</a> and <a href="http://elatov.github.io/2020/02/nginx-ingress-with-alertmanager-and-prometheus/" rel="noreferrer">here</a>.</p>

<p>Highlight to the second link, you have to include <code>- "--web.route-prefix=/"</code> and <code>- "--web.external-url=http://my.prom.com:9090/prometheus"</code> in your prometheus deployment.</p>

<blockquote>
  <p>Then I had to modify the  <strong>prometheus</strong>  deployment to accept traffic
  on the new  <em>path</em>  (<strong>/prom</strong>). This was covered in the  <a href="https://prometheus.io/docs/guides/basic-auth/#nginx-configuration" rel="noreferrer">Securing
  Prometheus API and UI Endpoints Using Basic
  Auth</a>
  documentation:</p>
</blockquote>

<p>In your env it should look like this:</p>

<pre><code>&gt; grep web deploy.yaml 
            - "--web.enable-lifecycle"
            - "--web.route-prefix=/"
            - "--web.external-url=http://my.prom.com:9090/prometheus"
</code></pre>
