[英]Communication Between Pods in Different Cluster in K8s using yaml
Can some one provide References/Basic Idea how communication is done between pods in different clusters.有人可以提供参考资料/基本想法如何在不同集群中的 Pod 之间进行通信。 Suppose Cluster A has Pod A and Cluster B has Pod B. So how we can ensure Pod A can communicate with Pod B using yaml?
假设集群 A 有 Pod A,集群 B 有 Pod B。那么我们如何确保 Pod A 可以使用 yaml 与 Pod B 通信? -Thanks in Advance
-提前致谢
Posting this answer as a community wiki for the better visibility and to add some additional resources as the solution was posted in the comments by user @David Maze:将此答案作为社区 wiki 发布以获得更好的可见性并添加一些额外的资源,因为该解决方案已发布在用户 @David Maze 的评论中:
If the pods are in different clusters, they can't directly communicate with each other (without using NodePort or LoadBalancer services, or otherwise making the destination service accessible from outside its own cluster).
如果 pod 位于不同的集群中,则它们无法直接相互通信(不使用 NodePort 或 LoadBalancer 服务,或以其他方式使目标服务可从其自己的集群外部访问)。
With the most common setups the way to communicate Pod1
from Cluster1
with Pod2
with Cluster2
would be to use:最常见的设置,以通信的方式
Pod1
从Cluster1
与Pod2
与Cluster2
是使用:
Service
of type NodePort
Service
型NodePort
Service
of type LoadBalancer
LoadBalancer
类型的Service
Ingress
resource - specific to HTTP
/ HTTPS
traffic Ingress
资源 - 特定于HTTP
/ HTTPS
流量All of the above solutions will heavily depend on where your Kubernetes cluster is deployed.上述所有解决方案都在很大程度上取决于您的 Kubernetes 集群的部署位置。
For example:例如:
With cloud solutions like GKE
, AKS
, EKS
you can use service type of LoadBalancer
or Ingress
resource to direct the traffic to your pod.借助
GKE
、 AKS
、 EKS
等云解决方案,您可以使用LoadBalancer
或Ingress
资源的服务类型将流量定向到您的 Pod。
With bare metal solution you would need to use additional tools like MetalLB
to use service of type LoadBalancer
使用裸机解决方案,您需要使用其他工具(如
MetalLB
来使用LoadBalancer
类型的服务
You could also look on this resources:您还可以查看此资源:
As for an example assume that you have 2 Kubernetes clusters that can expose traffic with service of type LoadBalancer
.例如,假设您有 2 个 Kubernetes 集群,可以使用
LoadBalancer
类型的服务公开流量。
Apply on first cluster:应用于第一个集群:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
replicas: 3
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: LoadBalancer
Check the EXTERNAL-IP
associated with the service:检查与服务关联的
EXTERNAL-IP
:
$ kubectl get service nginx-service
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service LoadBalancer 10.92.10.48 A.B.C.D 80:30994/TCP 26s
Switch to second cluster and run:切换到第二个集群并运行:
$ kubectl run -it ubuntu --image=ubuntu -- /bin/bash
$ apt update && apt install curl
$ curl ABCD
You should be able to see:您应该能够看到:
<--- REDACTED --->
<p><em>Thank you for using nginx.</em></p>
<--- REDACTED --->
Additional resources:其他资源:
GKE
GKE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.