502 AGIC AppGW 中的网关错误和探针不健康

问题描述 投票:0回答:1

我的应用程序使用 Angular FE 和多个 Asp.net core Web api。我已将其部署在 AKS 中并配置了 Appgw AGIC。 我的 Ingress 控制器详细信息

Name:             ingress-appgw-deployment-xxxxxxxx-xxxx
Namespace:        kube-system
Priority:         0
Service Account:  ingress-appgw-sa
Node:             aks-agentpool-xxxxxxx-vmss000000/10.224.1.255
Start Time:       Fri, 01 Mar 2024 02:16:47 +0400
Labels:           app=ingress-appgw
                  kubernetes.azure.com/managedby=aks
                  pod-template-hash=6d4f68fc9f
Annotations:      checksum/config: 1e53b6ba909ce787812767da80976912cc41007f8a716c489edab91f215b2bd7
                  cluster-autoscaler.kubernetes.io/safe-to-evict: true
                  kubernetes.azure.com/metrics-scrape: true
                  prometheus.io/path: /metrics
                  prometheus.io/port: 8123
                  prometheus.io/scrape: true
                  resource-id:
                    /subscriptions/ea88e1ed-fec0-472f-87f5-a00e6a608f19/resourceGroups/AZ-BELSIO-SOFTWARES-RG/providers/Microsoft.ContainerService/managedClus...
Status:           Running
IP:               10.224.x.xx
IPs:
  IP:           10.224.x.xx
Controlled By:  ReplicaSet/ingress-appgw-deployment-6d4f68fc9f
Containers:
  ingress-appgw-container:
    Container ID:   containerd://de72b0a2d86ffd7e11113b0ee38a374b509b212d56eac166391d28d4ae81849c
    Image:          mcr.microsoft.com/azure-application-gateway/kubernetes-ingress:1.7.2
    Image ID:       mcr.microsoft.com/azure-application-gateway/kubernetes-ingress@sha256:eeb1d42ebfb872478d9b0b16f6936ea938d6e5eed4a59cde332b8757556a5e1f
    Port:           <none>
    Host Port:      <none>
    State:          Running
      Started:      Fri, 01 Mar 2024 02:18:47 +0400
    Last State:     Terminated
      Reason:       Error
      Exit Code:    255
      Started:      Fri, 01 Mar 2024 02:17:55 +0400
      Finished:     Fri, 01 Mar 2024 02:17:56 +0400
    Ready:          True
    Restart Count:  4
    Limits:
      cpu:     700m
      memory:  600Mi
    Requests:
      cpu:      100m
      memory:   20Mi
    Liveness:   http-get http://:8123/health/alive delay=15s timeout=1s period=20s #success=1 #failure=3
    Readiness:  http-get http://:8123/health/ready delay=5s timeout=1s period=10s #success=1 #failure=3
    Environment Variables from:
      ingress-appgw-cm  ConfigMap  Optional: false
    Environment:
      AGIC_POD_NAMESPACE:             kube-system (v1:metadata.namespace)
      KUBERNETES_PORT_443_TCP_ADDR:   belsio-dns-yvu9cnmb.hcp.uaenorth.azmk8s.io
      KUBERNETES_PORT:                tcp://myapp-dns-yvu9cnmb.hcp.uaenorth.azmk8s.io:443
      KUBERNETES_PORT_443_TCP:        tcp://myapp-dns-yvu9cnmb.hcp.uaenorth.azmk8s.io:443
      KUBERNETES_SERVICE_HOST:        myapp-dns-yvu9cnmb.hcp.uaenorth.azmk8s.io
      AZURE_CLOUD_PROVIDER_LOCATION:  /etc/kubernetes/azure.json
      AGIC_POD_NAME:                  ingress-appgw-deployment-6d4f68fc9f-xtlmk (v1:metadata.name)
    Mounts:
      /etc/kubernetes/azure.json from cloud-provider-config (ro)
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-9kcms (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  cloud-provider-config:
    Type:          HostPath (bare host directory volume)
    Path:          /etc/kubernetes/azure.json
    HostPathType:  File
  kube-api-access-9kcms:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 CriticalAddonsOnly op=Exists
                             node.kubernetes.io/memory-pressure:NoSchedule op=Exists
                             node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:                      <none>

我的入口配置

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: myapp
  namespace: default
  annotations:
    kubernetes.io/ingress.class: azure/application-gateway
spec:
  tls:
  - hosts:
    - app.example.com
  rules:
  - host: app.example.com
    http:
        paths:
          - path: /
            pathType: Exact
            backend:
              service:
                name: angular
                port:
                  number: 80
          - path: /api1
            pathType: Prefix
            backend:
              service:
                name: api1
                port:
                  number: 80
          - path: /api2
            pathType: Prefix
            backend:
              service:
                name: api2
                port:
                  number: 80

预期:域根路径将路由到 Angular App,/api1 和 /api2 路由到 api。我能够使用相同的入口配置在 minikube 中使用 nginx IC 实现这一点。

问题:Angular 可以访问,但无法访问 API。我通过分配 public 来检查 API,它可以访问,但不能通过入口访问。在运行状况检查中,Angular pod 运行状况良好,但 api pod 运行状况不佳,并显示以下消息。

“在后端服务器的 HTTP 响应中收到无效状态代码:404。根据运行状况探针配置,200-399 是可接受的状态代码。修改探针配置或解决后端问题。要了解更多信息,请访问 - https://又名.ms/StatusCodeMismatch。"

请帮助我解决此问题,并建议您认为可能对我有帮助的其他配置。

提前谢谢您。

azure kubernetes ingress-controller
1个回答
0
投票

问题出在 .NET 代码中的路由,并通过为 Swagger UI 添加根前缀解决了问题。

CodeMaze 的博客提供了帮助。

https://code-maze.com/aspnetcore-modify-a-base-uri-of-swagger/

© www.soinside.com 2019 - 2024. All rights reserved.