簡體   English   中英

istio - 使用vs服務和gw而不是loadbalancer不工作

[英]istio - using vs service and gw instead loadbalancer not working

我有以下應用程序,我能夠在K8S成功運行,使用類型負載均衡器的服務,非常簡單的應用程序與兩個路由

  1. / - 你應該看到'你好申請'
  2. /api/books應提供json格式的/api/books列表

這是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"

應用了兩個yamls並在調用URL時:

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

我能夠按預期在瀏覽器中看到數據,並且只使用外部ip查看根應用程序中的數據

現在我想使用istio ,所以我按照指南使用https://istio.io/docs/setup/kubernetes/install/helm/通過helm成功安裝它,並驗證所有53 crd都在那里並且也是istio-system組件(例如istio-ingressgateway istio-pilot等所有8個部署都已啟動並運行)

我將上面的服務從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獲取此信息

嘗試訪問URL時b0751-1302075110.eu-central-1.elb.amazonaws.com

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

我收到了錯誤:

無法訪問此網站

ERR_CONNECTION_TIMED_OUT

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

我路徑的工作正常!

任何想法/提示可能是什么問題?

有沒有辦法跟蹤 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。

我能夠通過http:// $(minikube ip)的網址訪問應用程序:31380。

更改服務端口,部署是沒有意義的,因為這些是特定於應用程序的。

可能是這個問題指定了istio ingress網關打開的端口。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM