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



我已经在 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 中查找的......

这就是我在配置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'

上述解决方案无法直接工作,因为 Jenkins 控制器 Pod 将在健康检查(如果有(上失败。 使用 ingress.yaml 检查下面的 deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
namespace: devops-tools
spec:
replicas: 1
selector:
matchLabels:
app: jenkins-server
template:
metadata:
labels:
app: jenkins-server
spec:
securityContext:
fsGroup: 1000 
runAsUser: 1000
serviceAccountName: jenkins-admin
containers:
- name: jenkins
image: jenkins/jenkins:lts
resources:
limits:
memory: "6Gi"
cpu: "1000m"
requests:
memory: "500Mi"
cpu: "500m"
env:
- name: JENKINS_OPTS
value: "--prefix=/jenkins --httpListenAddress=0.0.0.0"
ports:
- name: httpport
containerPort: 8080
- name: jnlpport
containerPort: 50000
livenessProbe:
httpGet:
path: "/jenkins/login"
port: 8080
initialDelaySeconds: 90
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 5
readinessProbe:
httpGet:
path: "/jenkins/login"
port: 8080
initialDelaySeconds: 60
periodSeconds: 10
timeoutSeconds: 5
failureThreshold: 3
volumeMounts:
- name: jenkins-data
mountPath: /var/jenkins_home         
volumes:
- name: jenkins-data
persistentVolumeClaim:
claimName: jenkins-pv-claim

ingress.yaml 如下">

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
nginx.ingress.kubernetes.io/add-base-url: "true"
name: jenkins
namespace: devops-tools
spec:
ingressClassName: nginx
rules:
- host:  example.com
http:
paths:
- pathType: Prefix
path: /jenkins
backend:
service:
name: jenkins-service
port:
number: 8080

通过应用上述更改,您将能够在 http://example.com/jenkins 上访问您的 Jenkins

相关内容

  • 没有找到相关文章

最新更新