简体   繁体   中英

Check kubernetes pod name from other VM

I have a separate VM in the same network as my kubernetes in Azure. I have a kafka pod and I am able to reach this pod using the IP. The problem is that the pod IP is changing all the time.

Is there any way to get the correct IP each time the pod IP is changing?

I would suggest using a kubernetes service to expose pod. This avoids the problem with change in POD IP because service IP does not change.

Kubernetes ServiceTypes allow you to specify what kind of Service you want. The default is ClusterIP .

Type values and their behaviors are:

ClusterIP : Exposes the Service on a cluster-internal IP. Choosing this value makes the Service only reachable from within the cluster. This is the default ServiceType.

NodePort : Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created. You'll be able to contact the NodePort Service, from outside the cluster, by requesting:.

LoadBalancer : Exposes the Service externally using a cloud provider's load balancer. NodePort and ClusterIP Services, to which the external load balancer routes, are automatically created.

ExternalName : Maps the Service to the contents of the externalName field (eg foo.bar.example.com), by returning a CNAME record

Since you are accessing the POD from outside the kubernetes cluster itself use NodePort or LoadBalancer type service.

As mentioned by @arghya-sadhu already going for Kubernetes service, is the best option. The kubernetes service has an IP depending on the type of kubernetes service.

  • For services of type ClusterIP , you get a cluster IP address
  • For services of type Load Balancer , you get a Loadbalancer IP address (ie) public IP address
  • For services of type NodePort , you can access using the node's address.

But, whatever the type of service is, you can access the service using the kube-DNS within the cluster. So, let's say your service name is other-service and it exposes port 8080 , running on namespace abc , then you can access the service as follows:

http://other-service.abc:8080

Since, your VM runs outside the cluster, it is better to use Loadbalancer and access the pod using Loadbalancer url or IP address. You can set an ingress in case there are multiple pods in the cluster that you want to connect to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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