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

时间:2018-08-08 16:24:52

标签: nginx jenkins kubernetes kubernetes-ingress

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

假设我希望它在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时,它停留在该页面上,但是找不到静态资源,因为它们是在https://myip/static处寻找的。

2 个答案:

答案 0 :(得分:3)

这是我解决了配置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

答案 1 :(得分:0)

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

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

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

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

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