简体   繁体   English

使用yaml在K8s中不同集群中的Pod之间进行通信

[英]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:最常见的设置,以通信的方式Pod1Cluster1Pod2Cluster2是使用:

  • Service of type NodePort ServiceNodePort
  • 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.借助GKEAKSEKS等云解决方案,您可以使用LoadBalancerIngress资源的服务类型将流量定向到您的 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:其他资源:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 数据包捕获,用于在K8集群上的两个pod之间进行通信 - packet capture for communication between 2 pods on K8 cluster 在命名空间之间隔离 k8s pods.network - Isolate k8s pods network between namespaces 如何收集 k8s 集群 pod 的所有 igress 和 egress 流量? - How to collect all the igress and egress traffic of k8s cluster pods? 客户端到k8s集群之间的连接问题[TCP-reset-by-server] - Connectivity issues between client to k8s cluster [TCP-reset-by-server] 使 k8s 集群服务可用于本地 docker 容器 - Make k8s cluster services available to local docker containers K8s:通过 Pod 将流量路由到子网(从 Pod 访问 VPN 客户端) - K8s: routing traffic to a subnet via a pod (accesing VPN clients from pods) 设置可以访问多个 GKE k8s pods&amp;services 集群的 VPN - Setting up a VPN with access to multiple GKE k8s pods&services clusters 在不同节点上运行的 K8s Pod 无法相互通信 - K8s pods running in diffrent node can't communicate with each other 如何在K8s集群中切换默认的CNI提供程序 - How can I switch the default CNI providers in a K8s cluster 如何以可读的方式将两台主机之间的 udp 流量镜像到第三台远程 k8s 主机? - How to mirror udp traffic between two hosts to a third remote k8s host in a readable manner?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM