kubernetes nginx 入口控制器 aws 应用程序负载均衡器 404 错误

kubernetes nginx ingress controller aws application load balancer 404 error

但是当我在浏览器中点击它时,它显示 404 页面未找到。请告诉我问题出在哪里

nginx-deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: nginx
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx
        ports:
        - containerPort: 80

nginx-service.yaml

apiVersion: v1
kind: Service
metadata:
  name: nginx-service
  labels:
    app: nginx
    svc: test-nginx
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 8080
      targetPort: 80
NAME                                 TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
ingress-nginx-controller             LoadBalancer   10.100.21.122    <pending>     80:30237/TCP,443:30080/TCP   14h
ingress-nginx-controller-admission   ClusterIP      10.100.248.124   <none>        443/TCP                      14h
kubernetes                           ClusterIP      10.96.0.1        <none>        443/TCP                      14h
nginx-service                        ClusterIP      10.107.238.84    <none>        8080/TCP                     14h

nginx-ingress.yaml 文件

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: my-app-ingress
spec:
  rules:
  - host: ingress-lb-2018265909.us-east-2.elb.amazonaws.com
    http:
      paths:
      - pathType: Prefix
        path: /
        backend:
          service:
            name: nginx-service
            port:
              number: 8080

谢谢大家,我得到了答案。我需要设置 metalLB 以在裸机服务器中设置入口

待处理的 LoadBalancer 服务的外部 IP 可能是您的问题。检查日志以查看是否到达 Nginx Controller Pod.