Spring boot 在同一kubernetes集群中,从一个pod向另一个pod调用RESTAPI
在我的k8s集群中,我有两个podA和podB。两者都在同一个k8s集群中。pod B上的Microservice是一个spring boot rest api。pod A上的微服务在其应用程序中具有pod B的ip和端口。yaml。现在,每当重新创建podB时,ip都会发生变化,这迫使我们在podA的application.yml中更改ip。请建议一个更好的方法 我的限制是:我不能更改podA的代码。这就是服务的用途。参加博士后服务:Spring boot 在同一kubernetes集群中,从一个pod向另一个pod调用RESTAPI,spring-boot,docker,kubernetes,Spring Boot,Docker,Kubernetes,在我的k8s集群中,我有两个podA和podB。两者都在同一个k8s集群中。pod B上的Microservice是一个spring boot rest api。pod A上的微服务在其应用程序中具有pod B的ip和端口。yaml。现在,每当重新创建podB时,ip都会发生变化,这迫使我们在podA的application.yml中更改ip。请建议一个更好的方法 我的限制是:我不能更改podA的代码。这就是服务的用途。参加博士后服务: kind: Service apiVersion: v1
kind: Service
apiVersion: v1
metadata:
name: postgres-service
spec:
type: ClusterIP
selector:
app: postgres
ports:
- protocol: TCP
port: 5432
targetPort: 5432
您可以在其他pod中使用postgres服务,而不必参考pod的ip地址。您还有一个优势,k8s也在为您进行负载平衡。A将为访问POD提供一致的DNS名称。应用程序永远不应该直接寻址Pod,除非您有一个特定的原因,我可以想到定制负载平衡
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376
然后,您将有一个一致的DNS名称来访问与选择器匹配的任何POD:
my-service.default.svc.cluster.local