kubernetes 集群中的 Nginx 控制器未将 curl 请求转发到服务

kubernetes 集群中的 Nginx 控制器未将 curl 请求转发到服务

我的 Ingress 控制器没有将请求转发给服务,我该如何修复?我可以看到我的 Ingress 缺少地址,但我不知道原因。

我在 Linux 服务器上运行一个 Kubernetes 集群,该集群由 1 个主服务器和 2 个工作服务器组成。我有一个 HAProxy,它将我的请求转发到 Nginx 控制器。我的完整设置位于企业代理后面。此企业代理中启用了 DNS 条目。请求将到达 nginx 控制器,但不会转发到服务。我按照许多教程中的描述安装了入口控制器,文件位于https://github.com/nginxinc/kubernetes-ingress

我是 Stack Overflow 的新手,所以如果我需要提供更具体的信息,请告诉我。我希望有人能帮我解决我的问题,提前谢谢您 :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:

Nginx Controller Deamonset 的 Yaml 文件

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: nginx-ingress
  namespace: nginx-ingress
spec:
  selector:
    matchLabels:
      app: nginx-ingress
  template:
    metadata:
      labels:
        app: nginx-ingress
     #annotations:
       #prometheus.io/scrape: "true"
       #prometheus.io/port: "9113"
    spec:
      serviceAccountName: nginx-ingress
      containers:
      - image: nginx/nginx-ingress:edge
        imagePullPolicy: Always
        name: nginx-ingress
        ports:
        - name: http
          containerPort: 80
          hostPort: 80
        - name: https
          containerPort: 443
          hostPort: 443
        - name: readiness-port
          containerPort: 8081
       #- name: prometheus
         #containerPort: 9113
        readinessProbe:
         httpGet:
           path: /nginx-ready
           port: readiness-port
         periodSeconds: 1
        securityContext:
          allowPrivilegeEscalation: true
          runAsUser: 101 #nginx
          capabilities:
            drop:
            - ALL
            add:
            - NET_BIND_SERVICE
        env:
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        args:
          - -nginx-configmaps=$(POD_NAMESPACE)/nginx-config
          - -default-server-tls-secret=$(POD_NAMESPACE)/default-server-secret
         #- -v=3 # Enables extensive logging. Useful for troubleshooting.
         #- -report-ingress-status
         #- -external-service=nginx-ingress
         #- -enable-prometheus-metrics
         #- -global-configuration=$(POD_NAMESPACE)/nginx-configuration

从集群外部使用 Curl 并从控制器 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)

所有端点

kubectl get endpoints --all-namespaces
NAMESPACE              NAME                                                 ENDPOINTS                                                              AGE
default                app-service                                          10.244.2.4:3000                                                        3d3h
default                kubernetes                                           10.48.25.144:6443                                                      45d
elastic                elastic-webhook-server                               10.244.1.92:9443                                                       17d
kube-system            default-http-backend                                 <none>                                                                 9d
kube-system            kube-dns                                             10.244.0.4:53,10.244.0.5:53,10.244.0.4:53 + 3 more...                  45d
kube-system            prometheus-kube-prometheus-coredns                   10.244.0.4:9153,10.244.0.5:9153                                        21d
kube-system            prometheus-kube-prometheus-kube-controller-manager   10.48.25.144:10252                                                     21d
kube-system            prometheus-kube-prometheus-kube-etcd                 10.48.25.144:2379                                                      21d
kube-system            prometheus-kube-prometheus-kube-proxy                10.48.25.144:10249,10.48.25.145:10249,10.48.25.90:10249                21d
kube-system            prometheus-kube-prometheus-kube-scheduler            10.48.25.144:10251                                                     21d
kube-system            prometheus-kube-prometheus-kubelet                   10.48.25.144:10250,10.48.25.145:10250,10.48.25.90:10250 + 6 more...    24d
kube-system            prometheus-prometheus-oper-kubelet                   10.48.25.144:10250,10.48.25.145:10250,10.48.25.144:10255 + 3 more...   24d
kubernetes-dashboard   dashboard-metrics-scraper                            10.244.0.6:8000                                                        25d
kubernetes-dashboard   kubernetes-dashboard                                 10.244.0.7:8443                                                        25d
monitoring             alertmanager-operated                                10.244.1.83:9094,10.244.1.83:9094,10.244.1.83:9093                     21d
monitoring             graphana1-grafana                                    10.244.1.85:3000,10.244.1.89:3000                                      44d
monitoring             prometheus-grafana                                   10.244.1.95:3000                                                       21d
monitoring             prometheus-kube-prometheus-alertmanager              10.244.1.83:9093                                                       21d
monitoring             prometheus-kube-prometheus-operator                  10.244.1.93:8443                                                       21d
monitoring             prometheus-kube-prometheus-prometheus                10.244.1.94:9090                                                       21d
monitoring             prometheus-kube-state-metrics                        10.244.1.88:8080                                                       21d
monitoring             prometheus-operated                                  10.244.1.94:9090                                                       21d
monitoring             prometheus-prometheus-node-exporter                  10.48.25.144:9100,10.48.25.145:9100,10.48.25.90:9100                   21d

相关内容