入口不将流量转发到 pod

Ingress not forwarding traffic to pod

Ingress 没有将流量转发到 pods。 应用程序部署在 Azure 内部网络上。 我可以使用 pod Ip 和端口成功访问应用程序,但是在尝试 Ingress IP/Host 时我收到 404 not found。我在 Ingress 日志中没有看到任何错误。 下面是我的配置文件。 如果我遗漏了什么或如何解决问题,请帮助我。

Deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: aks-helloworld-one
spec:
  replicas: 1
  selector:
    matchLabels:
      app: aks-helloworld-one
  template:
    metadata:
      labels:
        app: aks-helloworld-one
    spec:
      containers:
      - name: aks-helloworld-one
        image: <image>
        ports:
            - containerPort: 8290
              protocol: "TCP"
        env:
        - name: env1
          valueFrom:
              secretKeyRef:
                name: configs
                key: env1
        volumeMounts:
         - mountPath: "mnt/secrets-store"
           name: secrets-mount
      volumes:      
        - name: secrets-mount
          csi:
            driver: secrets-store.csi.k8s.io
            readOnly: true
            volumeAttributes:
              secretProviderClass: "azure-keyvault"
      imagePullSecrets:
        - name: acr-secret
---
apiVersion: v1
kind: Service
metadata:
  name: aks-helloworld-one
spec:
  type: ClusterIP
  ports:
  - name: http
    protocol: TCP
    port: 8080
    targetPort: 8290
  selector:
    app: aks-helloworld-one

Ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  namespace: ingress-basic
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: aks-helloworld
            port:
              number: 80
  

您在入口定义下提到了错误的服务名称。根据服务定义,服务名称应为 aks-helloworld-one。

更正您在 ingress.yaml 中的服务名称和服务端口。

spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            # wrong: name: aks-helloworld
            name: aks-helloworld-one  
            port:
              # wrong: number: 80
              number: 8080

实际上,您可以使用以下命令来确认入口是否有任何端点。

kubectl describe ingress hello-world-ingress -n ingress-basic