Should I register pod or kubernete service to consul on kubernetes cluster
Headless Service
is the answer
Kubernetes environment is more dynamic in nature.
deregister a service when the pod is dead
Yes
Kubernetes Pods are mortal. They are born and when they die, they are not resurrected. While each Pod gets its own IP address, even those IP addresses cannot be relied upon to be stable over time. A Kubernetes Service is an abstraction which defines a logical set of Pods and provides stable ip
That's why it is recomended to use headless service
which basically fits into this situation. As they mentioned in first line in docs
Sometimes you don’t need or want load-balancing and a single service IP. In this case, you can create “headless” services by specifying "None" for the cluster IP (.spec.clusterIP)
headless service doesn't get the ClusterIP
. If you do nslookup
on the headless servive, it will resolve all IPs of pods that are under headless service. K8s will take care of adding/managing pod IP under the headless service. Please for more details. And I believe, you can register/provide this headless service name in Cosule.
- Please refer this blog for detailed here
UPDATE1:
Please refer this Youtube video. May give you some idea.(Even I have to watch it..!!)