c# - How to fetch pod endpoints from a headless service in Kubernetes - Stack Overflow

I have a headless service in my cluster:apiVersion: v1kind: Servicemetadata:namespace: my-namespacen

I have a headless service in my cluster:

apiVersion: v1
kind: Service
metadata:
  namespace: my-namespace
  name: my-headless-service
spec:
  clusterIP: None # <- Headless service
  selector:
    service: my-app
  ports:
  - port: 52323
    targetPort: 52323

However I don't quite get how I'm supposed to extract the endpoints the headless service defines. I can see them in OpenLens:

How can I get these endpoints from my C# application that's running in the cluster?

I have a headless service in my cluster:

apiVersion: v1
kind: Service
metadata:
  namespace: my-namespace
  name: my-headless-service
spec:
  clusterIP: None # <- Headless service
  selector:
    service: my-app
  ports:
  - port: 52323
    targetPort: 52323

However I don't quite get how I'm supposed to extract the endpoints the headless service defines. I can see them in OpenLens:

How can I get these endpoints from my C# application that's running in the cluster?

Share Improve this question edited Mar 26 at 16:35 Sal asked Mar 25 at 13:05 SalSal 5,9646 gold badges31 silver badges60 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To quote the Kubernetes documentation:

headless Services report the endpoint IP addresses of the individual pods via internal DNS records, served through the cluster's DNS service.

So you can perform a DNS lookup on your headless service's host name to resolve those ip's:

var ips = Dns.GetHostEntry("my-headless-service.my-namespace").AddressList;

This won't return the ports however. Not quite sure how to get those

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744194217a4562575.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信