我已经设法与Istio取得联系。我已经测试了很多基础知识,并且拥有一个可以很好地与HTTP和gRPC一起使用的基本集群。我有一个服务,但是需要向另一个未在外部公开的服务发出内部请求。
举个例子:
我有一个网关和一个声明的VirtualService:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: my-ingress
spec:
hosts:
- "*"
gateways:
- my-gateway
http:
- match:
- port: 80
route:
- destination:
host: my-grpc-gateway.default.svc.cluster.local
corsPolicy:
allowOrigin:
- "*"
allowMethods:
- POST
- GET
- DELETE
- PUT
- OPTIONS
allowCredentials: false
allowHeaders:
- Authorization
maxAge: "24h"
- match:
- port: 30051
route:
- destination:
host: api.default.svc.cluster.local
port:
number: 8443
这是我的网关:
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:
name: my-gateway
spec:
selector:
istio: ingressgateway
servers:
- port:
name: http
number: 80
protocol: HTTP
tls:
mode: PASSTHROUGH
hosts:
- "*"
- port:
name: https
number: 443
protocol: HTTPS
tls:
mode: PASSTHROUGH
hosts:
- "*"
- port:
name: grpc
number: 30051
protocol: GRPC
tls:
mode: PASSTHROUGH
hosts:
- "*"
我的代理服务随gRPC服务器的坐标一起提供:
apiVersion: apps/v1
kind: Deployment
metadata:
name: rest-proxy
labels:
app: prox
spec:
replicas: 1
selector:
matchLabels:
app: rest-proxy
template:
metadata:
labels:
app: rest-proxy
spec:
containers:
- image: redacted/rest-proxy:latest
name: rest-proxy
ports:
- containerPort: 80
command: ["./rest-proxy"]
args: ["-host", "0.0.0.0", "-port", "80", "-apipath", "$(API_SERVICE_HOST):$(API_SERVICE_PORT)"]
imagePullSecrets:
- name: regcred
---
apiVersion: v1
kind: Service
metadata:
name: rest-proxy
labels:
app: rest-proxy
spec:
ports:
- name: http
port: 80
- name: grpc-port
port: 8444
selector:
app: rest-proxy
这是ServiceEntry资源发挥作用的地方吗?现在,我只想确保我的内部服务可以互相通信,最终我将创建一个负载平衡器,以处理从网关到API的代理(随着我的扩展)。
任何建议/指导都会有所帮助!
答案 0 :(得分:2)
经过更多的挖掘之后,我意识到我的代理服务已绑定到端口:API_SERVICE_PORT,该端口设置为8080。gRPC服务存在于8443,因此从未建立连接。
网格内的所有内部服务都应该自然地相互通信。只是需要明确规则才能进入网状网络的入口。
答案 1 :(得分:1)
虚拟服务是标准k8s服务之上的一层,使我们能够应用更多规则和策略。
服务条目主要用于将网状外部的服务添加到istio的内部服务注册表中,例如数据库,消息队列等(尽管我们也可以根据需要添加网状内部服务)
如果两个服务都在同一个网格中,则应该通过虚拟服务相互通信
如果一项服务在外部而一项在内部,则必须有一项服务在外部的服务条目。