nginx ingress Jenkins 路径重写配置不起作用

nginx ingress Jenkins path rewrite configuration not working

我已经在 Kubernetes 上部署了 Jenkins,并且正在尝试为其配置 nginx ingress。

假设我希望它在 https://myip/jenkins

可用

这是我的初始入口配置:

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

有了这个,当我访问 https://myip/jenkins 时,我被重定向到 http://myip/login?from=%2F

当访问 https://myip/jenkins/login?from=%2F 时,它停留在该页面上,但找到 none 的静态资源,因为它们是在 https://myip/static...

中查找的

这就是我在无需使用入口重写注释的情况下配置 Jenkins 图像上下文路径的解决方法:

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: {}

入口:

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

我正在使用 JenkinsCI Helm 图表 (jenkinsci/jenkins),@codependent 的回答让我走上了正确的轨道。

可以在 helm 安装或 helm 升级期间设置基本 uri:

helm install jenkins jenkinsci/jenkins --set controller.jenkinsUriPrefix='/jenkins'

或者,如果您已经安装了 Jenkins:

helm upgrade jenkins jenkinsci/jenkins --set controller.jenkinsUriPrefix='/jenkins'