<p>My ASP.NET Core web application uses basepath in startup like,</p>
<pre><code>app.UsePathBase(&quot;/app1&quot;);
</code></pre>
<p>So the application will run on basepath. For example if the application is running on localhost:5000, then the <strong>app1</strong> will be accessible on '<strong>localhost:5000/app1</strong>'.</p>
<p>So in nginx ingress or any ingress we can expose the entire container through service to outside of the kubernetes cluster.</p>
<p>My kubernetes deployment YAML file looks like below,</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app1-deployment
spec:
  selector:
    matchLabels:
      app: app1
  replicas: 1
  template:
    metadata:
      labels:
        app: app1
    spec:
      containers:
      - name: app1-container
        image: app1:latest
        ports:
        - containerPort: 5001
---
apiVersion: v1
kind: Service
metadata:
  name: app1-service
  labels:
    app: app1
spec:
  type: NodePort
  ports:
  - name: app1-port
    port: 5001
    targetPort: 5001
    protocol: TCP
  selector:
    app: app1
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app1-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
  - http:
      paths:
      - path: /app1(/|$)(.*)
        backend:
          serviceName: server-service
          servicePort: 5001
</code></pre>
<p>The above ingress will expose the entire container in '<strong>localhost/app1</strong>' URL. So the application will run on '/app1' virtual path. But the <strong>app1</strong> application will be accessible on '<strong>localhost/app1/app1</strong>'.</p>
<p>So I want to know if there is any way to route '<strong>localhost/app1</strong>' request to basepath in container application '<strong>localhost:5001/app1</strong>' in ingress.</p>

Sesha3
<p>If I understand correctly, now the app is accessible on <code>/app1/app1</code> and you would like it to be accessible on <code>/app1</code></p>
<p>To do this, don't use rewrite:</p>
<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: app1-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
spec:
  rules:
  - http:
      paths:
      - path: /app1
        backend:
          serviceName: server-service
          servicePort: 5001
</code></pre>
