nginx ingress Jenkins path rewrite configuration not working

8/8/2018

I have deployed Jenkins on Kubernetes and am trying to configure the nginx ingress for it.

Assume I want it to be available at https://myip/jenkins

This is my initial ingress configuration:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: jenkins-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/add-base-url: "true"
spec:
  rules:
  - http:
      paths:
      - path: /jenkins
        backend:
          serviceName: jenkins
          servicePort: 8080

With this when I access https://myip/jenkins I am redirected to http://myip/login?from=%2F.

When accessing https://myip/jenkins/login?from=%2F it stays on that page but none of the static resources are found since they are looked for at https://myip/static...

-- codependent
jenkins
kubernetes
kubernetes-ingress
nginx

1 Answer

8/8/2018

This is how I solved it configuring the Jenkins image context path without the need to use the ingress rewrite annotations:

kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: jenkins
  name: jenkins
spec:
  replicas: 1
  selector:
    matchLabels:
      app: jenkins
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: jenkins
    spec:
      securityContext:
        fsGroup: 2000
        runAsUser: 1000
        runAsNonRoot: true
      volumes:
      - name: jenkins-storage
        persistentVolumeClaim:
          claimName: jenkins
      containers:
      - image: jenkins/jenkins:lts
        name: jenkins
        ports:
        - containerPort: 8080
          name: "http-server"
        - containerPort: 50000
          name: "jnlp"
        resources: {}
        env:
        - name: JENKINS_OPTS
          value: --prefix=/jenkins
        volumeMounts:
        - mountPath: "/var/jenkins_home"
          name: jenkins-storage
status: {}

Ingress:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: prfl-apps-devops-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/add-base-url: "true"
spec:
  rules:
  - http:
      paths:
      - path: /jenkins
        backend:
          serviceName: jenkins
          servicePort: 8080
-- codependent
Source: StackOverflow