<p>In a scenario where I set the context path of the Tomcat server by changing the <code>server.xml</code> file like this:</p>

<pre><code>&lt;Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"&gt;

    &lt;Context path="${catalinaContextPath}" docBase="${catalina.home}/atlassian-jira" reloadable="false" useHttpOnly="true"&gt;
        &lt;Resource name="UserTransaction" auth="Container" type="javax.transaction.UserTransaction"
            factory="org.objectweb.jotm.UserTransactionFactory" jotm.timeout="60"/&gt;
        &lt;Manager pathname=""/&gt;
        &lt;JarScanner scanManifest="false"/&gt;
        &lt;Valve className="org.apache.catalina.valves.StuckThreadDetectionValve" threshold="120" /&gt;
    &lt;/Context&gt;

&lt;/Host&gt;
</code></pre>

<p>If <code>catalinaContextPath</code> is set to <code>/my/new/context</code> The server will start up in the Pod with the URL: <code>localhost:8080/my/new/context</code>. How do I change the service so that it sends all traffic arriving on service port 80 to container path <code>&lt;pod_ip&gt;:8080/my/new/context</code></p>

<p>This is my current service: </p>

<pre><code>apiVersion: v1
kind: Service
metadata:
namespace: jira
name: jira
spec:
selector:
    app: jira
    component: jira
ports:
- protocol: TCP
  name: serverport
  port: 80
  targetPort: 8080
</code></pre>

<p>My use case is, I am deploying this <a href="https://hub.docker.com/r/dchevell/jira-software" rel="nofollow noreferrer">this JIRA docker image</a> in a Pod and I set the context path using the environment variable <code>CATALINA_CONTEXT_PATH</code> as specified in <a href="https://hub.docker.com/r/dchevell/jira-software" rel="nofollow noreferrer">this documentation</a>. <strong>When I try to access it, it results in a 404. I assume this is because traffic is being redirected to <code>&lt;pod_ip&gt;:8080</code> and nothing is running on <code>&lt;pod_ip&gt;:8080</code> since tomcat has started up on <code>&lt;pod_ip&gt;:8080/my/new/context</code></strong></p>

<p>EDIT: 
This is the <code>ingress.yaml</code> I am using:</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: {{ .Values.global.app }}
  name: jira-ingress
  annotations: 
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - host: myhost
    http:
      paths:
      - path: /dev/jira(/|$)(.*)
        backend:
          serviceName: jira
          servicePort: 80
      - path: /prod/jira(/|$)(.*)
        backend:
          serviceName: jira
          servicePort: 80
</code></pre>

<p>Whenever I visit <code>myhost/dev/jira</code> I need it to go to my JIRA instance.</p>

user9492428
<p>Since your application <em>"real"</em> root is <em><code>/my/new/context</code></em>, you can rewrite every incoming request matching the <em><code>/dev/jira</code></em> URI using <a href="https://kubernetes.github.io/ingress-nginx/user-guide/nginx-configuration/annotations/#rewrite" rel="nofollow noreferrer">Nginx's <code>AppRoot</code></a>:</p>

<blockquote>
  <p>If the Application Root is exposed in a different path and needs to be redirected, set the annotation nginx.ingress.kubernetes.io/app-root to redirect requests for /.</p>
</blockquote>

<p>If you're using this approach, there is no need to use capture groups with <code>rewrite-target</code>.</p>

<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  namespace: {{ .Values.global.app }}
  name: jira-ingress
  annotations: 
    kubernetes.io/ingress.class: "nginx"
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/app-root: /my/new/context
spec:
  rules:
  - host: myhost
    http:
      paths:
      - path: /dev/jira(/|$)(.*)
        backend:
          serviceName: jira
          servicePort: 80
      - path: /prod/jira(/|$)(.*)
        backend:
          serviceName: jira
          servicePort: 80
</code></pre>
