Azure Kubernetes服务-给出502的Http路由

时间:2018-09-14 10:11:21

标签: azure nginx kubernetes kubernetes-ingress azure-kubernetes

我们试图在AKS中托管我们的API,但是无论使用哪种入口选项,我们都遇到同样的问题。我们在配置了Http应用程序路由的AKS上运行最新版本的kubernetes(1.11.2)。根据信息中心显示,所有服务和Pod都正常,并且DNS区域/ healthz返回200,因此可以正常工作。

所有api服务都是使用最新版本的dotnet core构建的,其/ route配置为返回状态码200。

以下是服务和部署:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: accounts-api
spec:
  replicas: 3
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1 
  template:
    metadata:
      labels:
        app: accounts-api
    spec:
      containers:
      - name: accounts-api
        # image: mycompany.azurecr.io/accounts.api:#{Build.BuildId}#
        image: mycompany.azurecr.io/accounts.api:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: programs-api
spec:
  replicas: 3
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: programs-api
    spec:
      containers:
      - name: programs-api
        # image: mycompany.azurecr.io/programs.api:#{Build.BuildId}#
        image: mycompany.azurecr.io/programs.api:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: teams-api
spec:
  replicas: 3
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: teams-api
    spec:
      containers:
      - name: teams-api
        # image: mycompany.azurecr.io/teams.api:#{Build.BuildId}#
        image: mycompany.azurecr.io/teams.api:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: payments-api
spec:
  replicas: 3
  minReadySeconds: 10
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1
  template:
    metadata:
      labels:
        app: payments-api
    spec:
      containers:
      - name: payments-api
        # image: mycompany.azurecr.io/payments.api:#{Build.BuildId}#
        image: mycompany.azurecr.io/payments.api:latest
        imagePullPolicy: Always
        ports:
        - containerPort: 8080

---

apiVersion: v1
kind: Service
metadata:
  name: accounts-api-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: accounts-api
  type: ClusterIP

--- 

apiVersion: v1
kind: Service
metadata:
  name: programs-api-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: programs-api
  type: ClusterIP

--- 

apiVersion: v1
kind: Service
metadata:
  name: teams-api-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: teams-api
  type: ClusterIP

--- 

apiVersion: v1
kind: Service
metadata:
  name: payments-api-service
spec:
  ports:
  - port: 80
    protocol: TCP
    targetPort: 8080
  selector:
    app: payments-api
  type: ClusterIP

--- 

首先,我们尝试使用基于路径的扇出,如下所示:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-api-ingress
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
  - host: mycompany-api.d6b1cf1ede294842b0ed.westeurope.aksapp.io
    http:
      paths:
      - path: /accounts-api
        backend:
          serviceName: accounts-api-service
          servicePort: 80
      - path: /programs-api
        backend:
          serviceName: programs-api-service
          servicePort: 80
      - path: /teams-api
        backend:
          serviceName: teams-api-service
          servicePort: 80
      - path: /workouts-api
        backend:
          serviceName: payments-api-service
          servicePort: 80

---

但是我们在每个路径上都遇到了502个错误的网关。然后,我们尝试汇总入口并为每个服务分配主机:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: my-api-ingress
  annotations:
    kubernetes.io/ingress.class: addon-http-application-routing
spec:
  rules:
  - host: accounts-api.d6b1cf1ede294842b0ed.westeurope.aksapp.io
    http:
      paths:
      - path: /
        backend:
          serviceName: accounts-api-service
          servicePort: 80
  - host: programs-api.d6b1cf1ede294842b0ed.westeurope.aksapp.io
    http:
      paths:
      - path: /
        backend:
          serviceName: programs-api-service
          servicePort: 80
  - host: teams-api.d6b1cf1ede294842b0ed.westeurope.aksapp.io
    http:
      paths:
      - path: /
        backend:
          serviceName: teams-api-service
          servicePort: 80
  - host: payments-api.d6b1cf1ede494842b0ed.westeurope.aksapp.io
    http:
      paths:
      - path: /
        backend:
          serviceName: payments-api-service
          servicePort: 80

---

Azure DNS区域为每个服务添加了正确的txt和A记录,但我们仍然达到502。

从谷歌搜索中可以看出,入口到服务的连接似乎很麻烦,但是据我们所知,部署脚本看起来还不错。理想情况下,我们希望使用基于路径的扇出选项,那么问题可能出在哪里呢?基本路径配置?

0 个答案:

没有答案