简体   繁体   English

Kubernetes中的集群IP是什么?

[英]What is the cluster IP in Kubernetes?

I have created a cluster of three nodes: one master, two minions. 我创建了一个由三个节点组成的集群:一个主节点,两个小节点。 How to check the cluster IP in Kubernetes? 如何在Kubernetes中检查群集IP? Is it the IP of the master node? 它是主节点的IP吗?

ClusterIP can mean 2 things: a type of service which is only accessible within a Kubernetes cluster, or the internal ("virtual") IP of components within a Kubernetes cluster. ClusterIP可以表示两件事:一种只能在Kubernetes集群中访问的服务,或者一个Kubernetes集群内的组件的内部(“虚拟”)IP。 Assuming you're asking about finding the internal IP of a cluster, it can be accessed in 3 ways (using the simple-nginx example ): 假设您要求查找集群的内部IP,可以通过3种方式访问​​它(使用simple-nginx示例 ):

  1. Via command line kubectl utility: 通过命令行kubectl实用程序:

     $ kubectl describe service my-nginx Name: my-nginx Namespace: default Labels: run=my-nginx Selector: run=my-nginx Type: LoadBalancer IP: 10.123.253.27 LoadBalancer Ingress: 104.197.129.240 Port: <unnamed> 80/TCP NodePort: <unnamed> 30723/TCP Endpoints: 10.120.0.6:80 Session Affinity: None No events. 
  2. Via the kubernetes API (here I've used kubectl proxy to route through localhost to my cluster): 通过kubernetes API(这里我使用kubectl proxy将localhost路由到我的集群):

     $ kubectl proxy & $ curl -G http://localhost:8001/api/v1/namespaces/default/services/my-nginx { "kind": "Service", "apiVersion": "v1", "metadata": <omitted>, "spec": { "ports": [ { "protocol": "TCP", "port": 80, "targetPort": 80, "nodePort": 30723 } ], "selector": { "run": "my-nginx" }, "clusterIP": "10.123.253.27", "type": "LoadBalancer", "sessionAffinity": "None" }, "status": { "loadBalancer": { "ingress": [ { "ip": "104.197.129.240" } ] } } } 
  3. Via the $<NAME>_SERVICE_HOST environment variable within a Kubernetes container (in this example my-nginx-yczg9 is the name of a pod in the cluster): 通过Kubernetes容器中的$<NAME>_SERVICE_HOST环境变量(在此示例中, my-nginx-yczg9是群集中pod的名称):

     $ kubectl exec my-nginx-yczg9 -- sh -c 'echo $MY_NGINX_SERVICE_HOST' 10.123.253.27 

More details on service IPs can be found in the Services in Kubernetes documentation, and the previously mentioned simple-nginx example is a good example of exposing a service outside your cluster with the LoadBalancer service type. 有关服务IP的更多详细信息,请参阅Kubernetes中的Services文档,前面提到的simple-nginx示例是使用LoadBalancer服务类型公开集群外服务的一个很好的示例。

Run this 运行这个

$ kubectl cluster-info

It shows result like this where you can see the Kubernetes master IP 它显示了这样的结果,您可以在其中看到Kubernetes主IP

Kubernetes集群IP

集群IP只分配给服务,它是Kubernetes的内部ip。

Cluster IP is a virtual IP that is allocated by the K8s to a service. 群集IP是由K8分配给服务的虚拟IP。 It is K8s internal IP. 它是K8s的内部IP。

A Cluster IP makes it accessible from any of the Kubernetes cluster's nodes. 群集IP使其可以从任何Kubernetes群集的节点访问。 The use of virtual IP addresses for this purpose makes it possible to have several pods expose the same port on the same node – All of these pods will be accessible via a unique IP address. 为此目的使用虚拟IP地址可以使多个pod在同一节点上公开相同的端口 - 所有这些pod都可以通过唯一的IP地址访问。

This IP is stable and never changes in the service lifecycle(unless deleted explicitly). 此IP是稳定的,并且在服务生命周期中永远不会更改(除非明确删除)。

2 different pods can communicate using this IP, though I recommend using cluster DNS service. 2个不同的pod可以使用此IP进行通信,但我建议使用群集DNS服务。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM