Istio,无法从microservice-1调用microservice-2

时间:2019-10-17 05:54:28

标签: node.js kubernetes istio

我在minikube上安装了istio并部署了示例应用程序。

一切正常,除了我无法在微服务之间获得请求。

产品服务正在监听:9080 /产品路线。

我尝试过的网址:

  • “产品:9080 /产品”
  • “博客产品:9080 /产品”

但是他们都不行。

await axios.get('products:9080/products')
await axios.get('blog-products:9080/products')

如果我运行此命令,它将起作用,但是当我尝试在microservice-1中运行该URL时,它将不起作用。

kubectl exec -it $(kubectl get pod -l app=products -o jsonpath='{.items[0].metadata.name}') -c products -- curl products:9080/products

blog.yaml用于服务定义

#blog.yaml
##################################################################################################
# Products service
##################################################################################################
apiVersion: v1
kind: Service
metadata:
  name: products
  labels:
    app: products
    service: products
spec:
  ports:
    - port: 9080
      name: http
  selector:
    app: products
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: blog-products
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: products-v1
  labels:
    app: products
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: products
      version: v1
  template:
    metadata:
      labels:
        app: products
        version: v1
    spec:
      serviceAccountName: blog-products
      containers:
        - name: products
          image: s1nc4p/blogproducts
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9080
---
##################################################################################################
# home services
##################################################################################################
apiVersion: v1
kind: Service
metadata:
  name: home
  labels:
    app: home
    service: home
spec:
  ports:
    - port: 9080
      name: http
  selector:
    app: home
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: blog-home
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: home-v1
  labels:
    app: home
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: home
      version: v1
  template:
    metadata:
      labels:
        app: home
        version: v1
    spec:
      serviceAccountName: blog-home
      containers:
        - name: home
          image: s1nc4p/bloghome:v4
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9080

blog.gateway.yaml

#blog.gateway.yaml
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
  name: blog-gateway
spec:
  selector:
    istio: ingressgateway
  servers:
    - port:
        number: 80
        name: http
        protocol: HTTP
      hosts:
        - "*"
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: blog
spec:
  hosts:
    - "*"
  gateways:
    - blog-gateway
  http:
    - match:
        - uri:
            prefix: /
      route:
        - destination:
            host: home
            port:
              number: 9080

0 个答案:

没有答案