且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从Pod连接到其他Pod

更新时间:2022-06-27 00:41:24

我如何将我的项目连接到在其他Pod中运行,可独立扩展的Redis服务器?

How do i connect my project to the redis server that is running in other pod, that scales independently?

您在这里有三种可能的状态:

You have three possible states here:

  • 要从内部与运行Redis Pod的同一名称空间中运行的其他Pod在内连接到Redis Pod.在这种情况下,您将使用服务名称redis-service并指定服务端口6379以通过其当前的ClusterIP访问该端口(kube-dns正在为您进行DNS解析).我猜您是在要求这种情况.

  • To connect to Redis pod from within any other pod running in the same namespace as Redis pod is running. In this case you will use service name redis-service and designates service port 6379 to reach it over it's current ClusterIP (kube-dns is making DNS resolution for you there). I'm guessing that you are asking for this scenario.

  • 这里仅是从另一个容器中访问一个容器的示例(在您的情况下).首次运行:

  • Here is just an example of accessing one pod from within another pod (in your case). First run:

kubectl run -it --rm test --image=busybox --restart=Never -- sh

这将运行新的测试容器,并在该容器中提供sh.现在,如果您在测试窗格内键入nslookup redis-service,您将检查DNS在各个窗格之间是否正常工作.您也可以尝试使用nc -zv redis-service 6379查看redis端口是否真正打开.如果您的kube-dns工作正常,您应该会看到该端口已打开.

this will run new test pod and give you sh within that pod. Now if you type nslookup redis-service there (within test pod) you will check that DNS is working correctly between pods. You can also try to see if redis port is actually open with nc -zv redis-service 6379. If your kube-dns is working properly you should see that port is opened.

要从连接到Redis Pod,在同一kubernetes集群中运行,但在不同命名空间中.在这种情况下,您将使用由服务名称和名称空间名称组成的FQDN,如

To connect to Redis pod from within any other pod running in the same kubernetes cluster but in different namespace. In this case you will use FQDN consisting of service name and namespace name like it is given in the documentation.

要从kubernetes集群的外部连接到Redis Pod.在这种情况下,您将需要一些入口之王或类似机制的nodePort才能将redis服务公开给外界.有关此内容的更多信息,请阅读官方文档.

To connect to Redis pod from outside of the kubernetes cluster. In this case you will need some king of ingress, or nodePort of similar mechanism to expose redis service to outside world. More on this you can read in the official documentation.