<p>I am trying to deploy Jenkins on Kubernetes. I have deployed it with ClusterIP along with Nginx Ingress Controller on AKS.</p>
<p>When I access the IP of the Ingress-Controller, the Jenkins login URL (http://<em>ExternalIP</em>/login?from=%2F) comes up. However the UI of the Jenkins page isn't coming up and there is a some sort of redirection happening and keeps growing (http://<em>ExternalIP</em>/login?from=%2F%3Ffrom%3D%252F%253Ffrom%253D%25252F%25253F). I am very new to Ingress controller and annotations. I am not able to figure on what's causing this redirection.</p>
<p>Below are my configuration files. Can anyone please help on what's going wrong ?</p>
<p><strong>ClusterIP-Service.yml</strong></p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: jenkins-nodeport-svc
  namespace: jenkins
  labels:
    env: poc
    app: myapp_jenkins
spec:
  ports:
  - name: &quot;http&quot;
    port: 80
    targetPort: 8080
  type: ClusterIP
  selector:
      app: myapp_jenkins
</code></pre>
<p><strong>Ingress.yml</strong></p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jenkins-ingress
  namespace: jenkins
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /$2
    nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTP&quot;
    nginx.ingress.kubernetes.io/cors-allow-credentials: &quot;true&quot;
    nginx.ingress.kubernetes.io/cors-allow-headers: Authorization, origin, accept
    nginx.ingress.kubernetes.io/cors-allow-methods: GET, OPTIONS
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;

spec:
  rules:
  - http:
      paths:
       - backend:
          serviceName: jenkins-nodeport-svc
          servicePort: 80
         path: /(.*)
</code></pre>

rb16
<p>There's something in your ingress:</p>
<pre><code>path: /(.*)
</code></pre>
<p>is a regular expression with a single capturing group that match everything. For example with following url: <code>http://ExternalIP/login?from=myurl</code> your capturing group <code>$1</code> (the first and only one) would match <code>login?from/myurl</code>.</p>
<p>Now the problem is that <code>nginx.ingress.kubernetes.io/rewrite-target: /$2</code> annotation is rewriting your url with a non existing capturing group.</p>
<p>You don't need rewriting, you just need to plain forward every request to the service.<br />
<a href="https://kubernetes.github.io/ingress-nginx/examples/rewrite/#rewrite-target" rel="nofollow noreferrer">Here you can find Rewrite Examples</a> if you interested on it.</p>
<p>But in your case you can set:</p>
<pre><code>apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jenkins-ingress
  namespace: jenkins
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: &quot;false&quot;
    nginx.ingress.kubernetes.io/backend-protocol: &quot;HTTP&quot;
    nginx.ingress.kubernetes.io/cors-allow-credentials: &quot;true&quot;
    nginx.ingress.kubernetes.io/cors-allow-headers: Authorization, origin, accept
    nginx.ingress.kubernetes.io/cors-allow-methods: GET, OPTIONS
    nginx.ingress.kubernetes.io/enable-cors: &quot;true&quot;

spec:
  rules:
  - http:
      paths:
       - backend:
          serviceName: jenkins-nodeport-svc
          servicePort: 80
         path: /
</code></pre>
<p>and you're good to go.</p>
