我必须让现有的微服务运行。它们以 docker 图像的形式给出。它们通过配置的主机名和端口相互通信。我开始使用 Istio 来查看和配置每个微服务的呼出调用。现在我需要重写/重定向主机和从一个容器发出的请求的端口。我如何使用 Istio 做到这一点?
我将尝试举一个最小的例子。有两个服务,服务-a 和服务-b。
apiVersion: apps/v1
kind: Deployment
metadata:
name: service-b
spec:
selector:
matchLabels:
run: service-b
replicas: 1
template:
metadata:
labels:
run: service-b
spec:
containers:
- name: service-b
image: nginx
ports:
- containerPort: 80
name: web
---
apiVersion: v1
kind: Service
metadata:
name: service-b
labels:
run: service-b
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 80
name: service-b
selector:
run: service-b
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: service-a
spec:
selector:
matchLabels:
run: service-a
replicas: 1
template:
metadata:
labels:
run: service-a
spec:
containers:
- name: service-a
image: nginx
ports:
- containerPort: 80
name: web
---
apiVersion: v1
kind: Service
metadata:
name: service-a
labels:
run: service-a
spec:
ports:
- port: 8081
protocol: TCP
targetPort: 80
name: service-a
selector:
run: service-a
我可以 docker exec 进入 service-a 并成功执行:
root@service-a-d44f55d8c-8cp8m:/# curl -v service-b:8080
< HTTP/1.1 200 OK
< server: envoy
现在,为了模拟我的问题,我想通过使用另一个主机名和端口来访问 service-b。我想配置 Istio 以使该调用也可以工作:
root@service-a-d44f55d8c-8cp8m:/# curl -v service-x:7777
最好的问候,克里斯蒂安