首页 > 解决方案 > 如何使用 Istio Ingress 在 AKS 中公开服务?

问题描述

我曾经使用 Type: LoadBalancer 通过反向代理公开我的服务。没有 Istio,一切正常。但是,当我将 Istio 应用到集群时发生了错误。

我尝试使用 Istio Ingress 在 Kubernetes 中公开我的服务,但我认为在使用 Istio 路由服务时我误解了一些东西。

我在同一个命名空间中有 2 个部署(见下图):

1:应用程序(Bus-id)

2:应用程序的反向代理(Bus-Proxy):将HTTP翻译成gRPC

https://drive.google.com/file/d/1tby9_taJb9WMHi0ssO9Os7MQAWRMga6k/view?usp=sharing

版本:

我在Istio ( https://istio.io/docs/examples/bookinfo/ ) 中尝试了BookInfo示例,它成功了。

但是,我尝试了AKS中的投票示例(https://docs.microsoft.com/en-us/azure/aks/istio-scenario-routing),我无法使用外部负载均衡器的 IP 访问示例,它重新调整“超时” "

部署文件:

1.bus-id.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: bus-id
  namespace: smart-id
  labels:
    k8s-app: bus-id
spec:
  selector:
    matchLabels:
      k8s-app: bus-id
  template:
    metadata:
      name: bus-id
      labels:
        k8s-app: bus-id
    spec:
      containers:
        - name: bus-id
          image: mydockerhub/mydockerhub:bus-id
          ports:
            - containerPort: 50001
          env:

            - name: APP_NAME
              value: bus-id
---
apiVersion: v1
kind: Service
metadata:
  name: bus-id
  namespace: smart-id
  labels:
    service: bus-id
spec:
  ports:
    - name: http
      port: 50001
      targetPort: 50001
      protocol: TCP
  selector:
    k8s-app: bus-id

2. 总线代理.yaml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    k8s-app: bus-proxy
  name: bus-proxy
  namespace: smart-id
spec:
  selector:
    matchLabels:
      k8s-app: bus-proxy
  replicas: 1
  template:
    metadata:
      labels:
        k8s-app: bus-proxy
    spec:
      imagePullSecrets:
        - name: duynd
      containers:
        - image: mydockerhub/mydockerhub:bus-proxy
          name: bus-proxy
          ports:
            - containerPort: 40001
              name: http
          env:
            - name: APP_NAME
              value: bus-proxy
---
apiVersion: v1
kind: Service
metadata:
  name: bus-proxy
  namespace: smart-id
  labels:
    service: bus-proxy
spec:
  ports:
    - port: 8080
      targetPort: 40001
      protocol: TCP
  selector:
    k8s-app: bus-proxy

3.入口.yaml

apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: smartid-gateway
  namespace: smart-id
spec:
  selector:
    istio: ingressgateway # use istio default controller
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: smartid
  namespace: smart-id
spec:
  hosts:
    - "*"
  gateways:
    - smart-id/smartid-gateway
  http:
    - match:
        - uri:
            prefix: /api
      route:
        - destination:
            host: bus-proxy.smart-id.svc.cluster.local
            port:
              number: 8080

我希望它适用于 ingress-ip:ingress-port/api/my-function (方法 POST)。但是,它返回错误 500,bus-proxy的 POD 也打印日志(我认为请求成功到达bus-proxy,但可以通过bus-id)。

标签: azurekubernetesistio

解决方案


首先,如果您使用 Istio 在 AKS 中运行所有应用程序,我建议您按照 AKS在 Azure Kubernetes Service (AKS) 中安装和使用 Istio 中提供的步骤安装 Istio 。

现在,查看此处提供的 AKS 示例,您需要了解以下内容:

Istio 本身就有代理。因此,您需要选择使用哪个代理或同时使用两个代理,但您需要确保它支持两个代理。

如果您使用 Istio 的代理,那么您还需要为istio-injection您的应用程序的命名空间启用 ,就像示例一样:

kubectl label namespace voting istio-injection=enabled 

此标签指示 Istio 自动将 istio-proxy 作为 sidecar 注入此命名空间中的所有 pod。您应该在 ingress.yaml 中为您的虚拟服务使用正确的网关。


推荐阅读