istio - 使用 vs 服务和 gw 而不是负载均衡器不工作

istio - using vs service and gw instead loadbalancer not working

我有以下应用程序,我能够 运行 在 K8S 中成功使用负载均衡器类型的服务,非常简单的应用程序有两条路线

  1. / - 你应该看到“你好应用程序”
  2. /api/books 应提供 json 格式的图书列表

这是service

apiVersion: v1
kind: Service
metadata:
  name: go-ms
  labels:
    app: go-ms
    tier: service
spec:
  type: LoadBalancer
  ports:
    - port: 8080
  selector:
    app: go-ms

这是部署


apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: go-ms
  labels:
    app: go-ms

spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: go-ms
        tier: service

    spec:
      containers:
        - name: go-ms
          image: rayndockder/http:0.0.2
          ports:
            - containerPort: 8080
          env:
            - name: PORT
              value: "8080"
          resources:
            requests:
              memory: "64Mi"
              cpu: "125m"
            limits:
              memory: "128Mi"
              cpu: "250m"

在应用两个 yaml 之后和调用 URL:

http://b0751-1302075110.eu-central-1.elb.amazonaws.com/api/books

我能够按预期在浏览器中看到数据,并且仅使用外部 ip 也能看到根应用程序的数据

现在我想用istio,所以我按照教程通过helm安装成功 使用 https://istio.io/docs/setup/kubernetes/install/helm/ 并验证所有 53 crd 是否都存在 istio-system 组件(例如 istio-ingressgateway istio-pilot 等所有 8 个部署都已启动并且 运行ning)

我已将上面的服务从 LoadBalancer 更改为 NodePort

并根据 istio 文档

创建以下 istio 配置
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: http-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 8080
        name: http
        protocol: HTTP
      hosts:
        - "*"
---

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: virtualservice
spec:
  hosts:
    - "*"
  gateways:
    - http-gateway
  http:
  - match:
      - uri:
          prefix: "/"
      - uri:
          exact: "/api/books"
    route:
      - destination:
          port:
            number: 8080
          host: go-ms

此外我还添加了以下内容

kubectl label namespace books istio-injection=enabled 部署应用程序的位置,

现在要获取外部 Ip,我使用了命令

kubectl get svc -n istio-system -l istio=ingressgateway

并在 external-ip

中获取此内容

b0751-1302075110.eu-central-1.elb.amazonaws.com 当试图访问 URL

http://b0751-1302075110.eu-central-1.elb.amazonaws.com/api/books

我收到错误:

无法访问此站点

ERR_CONNECTION_TIMED_OUT

如果我 运行 docker rayndockder/http:0.0.2 通过 docker run -it -p 8080:8080 httpv2

我的路径工作正常!

任何 idea/hint 可能是什么问题?

有没有办法跟踪 istio 配置以查看是否缺少某些内容,或者我们是否与端口或网络策略有某种串通?

顺便说一句,部署和服务可以在每个集群上 运行 进行测试,有人可以帮助...

如果我 全部更改为 80 端口(在所有 yaml 文件和应用程序以及 docker 中)我能够获取数据用于根路径,但不用于 "api/books"

我在 kubernetes 和 istio 的本地 minikube 设置中将网关端口从 8080 修改为 80,这让你的配置很累。这是我使用的命令:

kubectl apply -f - <<EOF
apiVersion: v1
kind: Service
metadata:
  name: go-ms
  labels:
    app: go-ms
    tier: service
spec:
  ports:
    - port: 8080
  selector:
    app: go-ms
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: go-ms
  labels:
    app: go-ms

spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: go-ms
        tier: service

    spec:
      containers:
        - name: go-ms
          image: rayndockder/http:0.0.2
          ports:
            - containerPort: 8080
          env:
            - name: PORT
              value: "8080"
          resources:
            requests:
              memory: "64Mi"
              cpu: "125m"
            limits:
              memory: "128Mi"
              cpu: "250m"
---
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: http-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: go-ms-virtualservice
spec:
  hosts:
     - "*"
  gateways:
    - http-gateway
  http:
  - match:
      - uri:
          prefix: /
      - uri:
          exact: /api/books
    route:
      - destination:
          port:
            number: 8080
          host: go-ms
EOF

之所以将网关端口改为80,是因为istio ingress网关默认开启了80、443等几个端口。在我的例子中,由于 minikube 没有外部负载均衡器,我使用的节点端口在我的例子中是 31380。

我能够通过 url 的 http://$(minikube ip):31380 访问应用程序。

更改服务和部署的端口没有意义,因为它们是特定于应用程序的。

可能是问题指定了istio入口网关打开的端口。