Kubernetes 'nginx ingress' 找不到服务
Kubernetes 'nginx ingress' unable to find service
我已经完成了一个示例应用程序,用于在 Kubernetes 上部署 Jenkins 并使用 Ingress 公开它。当我通过 NodePort 访问 jenkins pod 时它正在工作但是当我尝试通过 Ingress / Nginx 设置访问它时我得到 404
我做了 google 并尝试了一些解决方法,但 none 到目前为止都有效。以下是文件的详细信息
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose -f ../docker-compose.yml -f ../docker-compose.utils.yml -f
../docker-compose.demosite.yml convert
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: ci
name: ci
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: ci
spec:
containers:
- image: jenkins/jenkins:lts
name: almsmart-ci
ports:
- containerPort: 8080
env:
- name: JENKINS_USER
value: admin
- name: JENKINS_PASS
value: admin
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
- name: JENKINS_OPTS
value: --prefix=/ci
imagePullPolicy: Always
resources: {}
restartPolicy: Always
status: {}
---
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose -f ../docker-compose.yml -f ../docker-compose.utils.yml -f
../docker-compose.demosite.yml convert
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: ci
name: ci
spec:
type : NodePort
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
io.kompose.service: ci
status:
loadBalancer: {}
这是我的入口定义
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/cors-allow-headers: Authorization, origin, accept
nginx.ingress.kubernetes.io/cors-allow-methods: GET, OPTIONS
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /ci
backend:
serviceName: ci
servicePort: 8080
当我检查 nginx 控制器中的日志时,我看到以下内容
I0222 19:59:45.826062 6 controller.go:172] Configuration changes detected, backend reload required.
I0222 19:59:45.831627 6 event.go:221] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"almsmart-ingress", UID:"444858e5-36d9-11e9-9e29-080027811fa3", APIVersion:"extensions/v1beta1", ResourceVersion:"198832", FieldPath:""}): type: 'Normal' reason: 'DELETE' Ingress default/almsmart-ingress
I0222 19:59:46.063220 6 controller.go:190] Backend successfully reloaded.
[22/Feb/2019:19:59:46 +0000]TCP200000.000
W0222 20:00:00.870990 6 endpoints.go:76] Error obtaining Endpoints for Service "default/ci": no object matching key "default/ci" in local store
W0222 20:00:00.871023 6 controller.go:842] Service "default/ci" does not have any active Endpoint.
I0222 20:00:00.871103 6 controller.go:172] Configuration changes detected, backend reload required.
I0222 20:00:00.872556 6 event.go:221] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"almsmart-ingress", UID:"6fc5272c-36dc-11e9-9e29-080027811fa3", APIVersion:"extensions/v1beta1", ResourceVersion:"198872", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/almsmart-ingress
I0222 20:00:01.060291 6 controller.go:190] Backend successfully reloaded.
[22/Feb/2019:20:00:01 +0000]TCP200000.000
W0222 20:00:04.205398 6 controller.go:842] Service "default/ci" does not have any active Endpoint.
[22/Feb/2019:20:00:09 +0000]TCP200000.000
10.244.0.0 - [10.244.0.0] - - [22/Feb/2019:20:00:36 +0000] "GET /ci/ HTTP/1.1" 404 274 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0" 498 0.101 [default-ci-8080] 10.244.1.97:8080 315 0.104 404 b5b849647749e2b626f00c011c15bc4e
10.244.0.0 - [10.244.0.0] - - [22/Feb/2019:20:00:46 +0000] "GET /ci HTTP/1.1" 404 274 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0" 497 0.003 [default-ci-8080] 10.244.1.97:8080 315 0.004 404 ac8fbe2faa37413f5e533ed3c8d98a7d
10.244.0.0 - [10.244.0.0] - - [22/Feb/2019:20:00:49 +0000] "GET /ci/ HTTP/1.1" 404 274 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0" 498 0.003 [default-ci-8080] 10.244.1.97:8080 315 0.004 404 865cb82af7f570f2144ef27fdea850c9
I0222 20:00:54.871828 6 status.go:388] updating Ingress default/almsmart-ingress status from [] to [{ }]
I0222 20:00:54.877693 6 event.go:221] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"almsmart-ingress", UID:"6fc5272c-36dc-11e9-9e29-080027811fa3", APIVersion:"extensions/v1beta1", ResourceVersion:"198974", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress default/almsmart-ingress
当我尝试时
kubectl get endpoints, I get the following
NAME ENDPOINTS AGE
ci 10.244.1.97:8080 31m
默认的 404 页面可用,所以我假设 Ingress Controller 工作正常但不确定为什么它找不到服务。我只有默认命名空间中的所有对象并且可以工作,但仍然无法使用 nginx ingress 访问它。
+1 这个问得很好的问题。
我觉得你的设置没问题。一个问题是,您为 Jenkins 配置了 --prefix=/ci
,但为入口配置了 nginx.ingress.kubernetes.io/rewrite-target: /
。这将导致重写您的路线:xxx/ci => xxx/
。我认为 404 是由您的 Jenkins 返回的。
您可以尝试将您的重写规则修改为 nginx.ingress.kubernetes.io/rewrite-target: /ci
,看看是否适合您。
我已经完成了一个示例应用程序,用于在 Kubernetes 上部署 Jenkins 并使用 Ingress 公开它。当我通过 NodePort 访问 jenkins pod 时它正在工作但是当我尝试通过 Ingress / Nginx 设置访问它时我得到 404
我做了 google 并尝试了一些解决方法,但 none 到目前为止都有效。以下是文件的详细信息
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose -f ../docker-compose.yml -f ../docker-compose.utils.yml -f
../docker-compose.demosite.yml convert
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: ci
name: ci
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
creationTimestamp: null
labels:
io.kompose.service: ci
spec:
containers:
- image: jenkins/jenkins:lts
name: almsmart-ci
ports:
- containerPort: 8080
env:
- name: JENKINS_USER
value: admin
- name: JENKINS_PASS
value: admin
- name: JAVA_OPTS
value: -Djenkins.install.runSetupWizard=false
- name: JENKINS_OPTS
value: --prefix=/ci
imagePullPolicy: Always
resources: {}
restartPolicy: Always
status: {}
---
apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose -f ../docker-compose.yml -f ../docker-compose.utils.yml -f
../docker-compose.demosite.yml convert
kompose.version: 1.17.0 (a74acad)
creationTimestamp: null
labels:
io.kompose.service: ci
name: ci
spec:
type : NodePort
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
io.kompose.service: ci
status:
loadBalancer: {}
这是我的入口定义
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: demo-ingress
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
nginx.ingress.kubernetes.io/cors-allow-credentials: "true"
nginx.ingress.kubernetes.io/cors-allow-headers: Authorization, origin, accept
nginx.ingress.kubernetes.io/cors-allow-methods: GET, OPTIONS
nginx.ingress.kubernetes.io/enable-cors: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "false"
spec:
rules:
- http:
paths:
- path: /ci
backend:
serviceName: ci
servicePort: 8080
当我检查 nginx 控制器中的日志时,我看到以下内容
I0222 19:59:45.826062 6 controller.go:172] Configuration changes detected, backend reload required.
I0222 19:59:45.831627 6 event.go:221] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"almsmart-ingress", UID:"444858e5-36d9-11e9-9e29-080027811fa3", APIVersion:"extensions/v1beta1", ResourceVersion:"198832", FieldPath:""}): type: 'Normal' reason: 'DELETE' Ingress default/almsmart-ingress
I0222 19:59:46.063220 6 controller.go:190] Backend successfully reloaded.
[22/Feb/2019:19:59:46 +0000]TCP200000.000
W0222 20:00:00.870990 6 endpoints.go:76] Error obtaining Endpoints for Service "default/ci": no object matching key "default/ci" in local store
W0222 20:00:00.871023 6 controller.go:842] Service "default/ci" does not have any active Endpoint.
I0222 20:00:00.871103 6 controller.go:172] Configuration changes detected, backend reload required.
I0222 20:00:00.872556 6 event.go:221] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"almsmart-ingress", UID:"6fc5272c-36dc-11e9-9e29-080027811fa3", APIVersion:"extensions/v1beta1", ResourceVersion:"198872", FieldPath:""}): type: 'Normal' reason: 'CREATE' Ingress default/almsmart-ingress
I0222 20:00:01.060291 6 controller.go:190] Backend successfully reloaded.
[22/Feb/2019:20:00:01 +0000]TCP200000.000
W0222 20:00:04.205398 6 controller.go:842] Service "default/ci" does not have any active Endpoint.
[22/Feb/2019:20:00:09 +0000]TCP200000.000
10.244.0.0 - [10.244.0.0] - - [22/Feb/2019:20:00:36 +0000] "GET /ci/ HTTP/1.1" 404 274 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0" 498 0.101 [default-ci-8080] 10.244.1.97:8080 315 0.104 404 b5b849647749e2b626f00c011c15bc4e
10.244.0.0 - [10.244.0.0] - - [22/Feb/2019:20:00:46 +0000] "GET /ci HTTP/1.1" 404 274 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0" 497 0.003 [default-ci-8080] 10.244.1.97:8080 315 0.004 404 ac8fbe2faa37413f5e533ed3c8d98a7d
10.244.0.0 - [10.244.0.0] - - [22/Feb/2019:20:00:49 +0000] "GET /ci/ HTTP/1.1" 404 274 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0" 498 0.003 [default-ci-8080] 10.244.1.97:8080 315 0.004 404 865cb82af7f570f2144ef27fdea850c9
I0222 20:00:54.871828 6 status.go:388] updating Ingress default/almsmart-ingress status from [] to [{ }]
I0222 20:00:54.877693 6 event.go:221] Event(v1.ObjectReference{Kind:"Ingress", Namespace:"default", Name:"almsmart-ingress", UID:"6fc5272c-36dc-11e9-9e29-080027811fa3", APIVersion:"extensions/v1beta1", ResourceVersion:"198974", FieldPath:""}): type: 'Normal' reason: 'UPDATE' Ingress default/almsmart-ingress
当我尝试时
kubectl get endpoints, I get the following
NAME ENDPOINTS AGE
ci 10.244.1.97:8080 31m
默认的 404 页面可用,所以我假设 Ingress Controller 工作正常但不确定为什么它找不到服务。我只有默认命名空间中的所有对象并且可以工作,但仍然无法使用 nginx ingress 访问它。
+1 这个问得很好的问题。
我觉得你的设置没问题。一个问题是,您为 Jenkins 配置了 --prefix=/ci
,但为入口配置了 nginx.ingress.kubernetes.io/rewrite-target: /
。这将导致重写您的路线:xxx/ci => xxx/
。我认为 404 是由您的 Jenkins 返回的。
您可以尝试将您的重写规则修改为 nginx.ingress.kubernetes.io/rewrite-target: /ci
,看看是否适合您。