Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx ingress Jenkins path rewrite configuration not working

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...

like image 666
codependent Avatar asked Aug 08 '18 16:08

codependent


1 Answers

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
like image 114
codependent Avatar answered Oct 04 '22 21:10

codependent