Nginx 控制器入口不工作,地址丢失
Ingress with Nginx Controller not working, Address missing
我有一个 Kubernetes 集群 运行 在一个 1 master,2 worker setup ob linux 服务器上。我有一个 HAProxy 将我的请求转发给 Nginx 控制器。我的完整设置位于公司代理之后。在此公司代理中启用了 DNS 条目。
请求将到达 nginx 控制器,但不会转发到服务。
我安装了入口控制器,正如许多教程所描述的那样,文件在 https://github.com/kubernetes/ingress-nginx .
我是堆栈溢出的新手,所以如果我需要提供更具体的信息,请告诉我。我希望有人能帮助我解决我的问题,提前谢谢你:D
我的 Ingress 缺少地址:
Name: app-ingress
Namespace: default
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
test.kubetest.lff.bybn.de
/abc app-service:80 (10.244.2.4:3000)
Annotations: kubernetes.io/ingress.class: nginx
Events: <none>
Deployment、Service、Ingress、IngressClass、ConfigMap的Yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: app
name: app-blue
spec:
replicas: 1
selector:
matchLabels:
run: app
version: 0.0.1
template:
metadata:
labels:
run: app
version: 0.0.1
spec:
containers:
- name: app
image: errm/versions:0.0.1
ports:
- containerPort: 3000
----
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
run: app
version: 0.0.1
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: test.kubetest.lff.bybn.de
http:
paths:
- path: /abc
backend:
serviceName: app-service
servicePort: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: nginx
# annotations:
# ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: nginx.org/ingress-controller
---
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-config
namespace: nginx-ingress
data:
来自集群外部的卷曲和来自控制器 Pod 的日志
curl test.kubetest.lff.bybn.de/abc
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 93 0 93 0 0 1 0 --:--:-- 0:00:50 --:--:-- 26<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>
E0131 19:44:11.949261 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:45:06.894791 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:45:48.532075 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
10.48.25.57 - - [31/Jan/2021:19:46:35 +0000] "GET /abc HTTP/1.1" 499 0 "-" "curl/7.73.0" "-"
E0131 19:46:37.902444 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:47:15.346193 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:47:48.536636 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:48:21.890770 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
查看 Ingress 定义,我发现它遗漏了入口 class。要么你定义了一个 IngressClass 注释为默认 class 使用,要么这可能是你的 Ingress 目前不工作的原因。
Ingress Class 基本上是一个类别,它指定谁需要服务和管理 Ingress,这是必要的,因为在集群中您可以有多个 Ingress 控制器,每个控制器都有其规则和配置.
根据 Kubernetes 版本,ingress class 可以在 ingress(v1.18 之前)上使用注释定义,例如:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
...
或者使用整个资源,然后按照文档中所示将其引用到 Ingress (https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class)
即使在新版本的 Kubernetes 中,旧的注解可能仍受支持,具体取决于控制器。
如果您不确定应该使用哪个入口 class,那应该由控制器定义,您可能在安装它时决定了一个,或者您使用了默认的(大多数时候是nginx)
我有一个 Kubernetes 集群 运行 在一个 1 master,2 worker setup ob linux 服务器上。我有一个 HAProxy 将我的请求转发给 Nginx 控制器。我的完整设置位于公司代理之后。在此公司代理中启用了 DNS 条目。 请求将到达 nginx 控制器,但不会转发到服务。 我安装了入口控制器,正如许多教程所描述的那样,文件在 https://github.com/kubernetes/ingress-nginx .
我是堆栈溢出的新手,所以如果我需要提供更具体的信息,请告诉我。我希望有人能帮助我解决我的问题,提前谢谢你:D
我的 Ingress 缺少地址:
Name: app-ingress
Namespace: default
Address:
Default backend: default-http-backend:80 (<none>)
Rules:
Host Path Backends
---- ---- --------
test.kubetest.lff.bybn.de
/abc app-service:80 (10.244.2.4:3000)
Annotations: kubernetes.io/ingress.class: nginx
Events: <none>
Deployment、Service、Ingress、IngressClass、ConfigMap的Yaml文件
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
run: app
name: app-blue
spec:
replicas: 1
selector:
matchLabels:
run: app
version: 0.0.1
template:
metadata:
labels:
run: app
version: 0.0.1
spec:
containers:
- name: app
image: errm/versions:0.0.1
ports:
- containerPort: 3000
----
apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
selector:
run: app
version: 0.0.1
ports:
- name: http
port: 80
protocol: TCP
targetPort: 3000
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: app-ingress
namespace: default
annotations:
kubernetes.io/ingress.class: nginx
spec:
rules:
- host: test.kubetest.lff.bybn.de
http:
paths:
- path: /abc
backend:
serviceName: app-service
servicePort: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: nginx
# annotations:
# ingressclass.kubernetes.io/is-default-class: "true"
spec:
controller: nginx.org/ingress-controller
---
kind: ConfigMap
apiVersion: v1
metadata:
name: nginx-config
namespace: nginx-ingress
data:
来自集群外部的卷曲和来自控制器 Pod 的日志
curl test.kubetest.lff.bybn.de/abc
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 93 0 93 0 0 1 0 --:--:-- 0:00:50 --:--:-- 26<html><body><h1>504 Gateway Time-out</h1>
The server didn't respond in time.
</body></html>
E0131 19:44:11.949261 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:45:06.894791 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:45:48.532075 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
10.48.25.57 - - [31/Jan/2021:19:46:35 +0000] "GET /abc HTTP/1.1" 499 0 "-" "curl/7.73.0" "-"
E0131 19:46:37.902444 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:47:15.346193 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:47:48.536636 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
E0131 19:48:21.890770 1 reflector.go:138] /home/runner/work/kubernetes-ingress/kubernetes-ingress/internal/k8s/controller.go:574: Failed to watch *v1.Policy: failed to list *v1.Policy: the server could not find the requested resource (get policies.k8s.nginx.org)
查看 Ingress 定义,我发现它遗漏了入口 class。要么你定义了一个 IngressClass 注释为默认 class 使用,要么这可能是你的 Ingress 目前不工作的原因。
Ingress Class 基本上是一个类别,它指定谁需要服务和管理 Ingress,这是必要的,因为在集群中您可以有多个 Ingress 控制器,每个控制器都有其规则和配置.
根据 Kubernetes 版本,ingress class 可以在 ingress(v1.18 之前)上使用注释定义,例如:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: example-ingress
annotations:
kubernetes.io/ingress.class: nginx
spec:
...
或者使用整个资源,然后按照文档中所示将其引用到 Ingress (https://kubernetes.io/docs/concepts/services-networking/ingress/#ingress-class)
即使在新版本的 Kubernetes 中,旧的注解可能仍受支持,具体取决于控制器。
如果您不确定应该使用哪个入口 class,那应该由控制器定义,您可能在安装它时决定了一个,或者您使用了默认的(大多数时候是nginx)