I have deployed NATS (https://nats.io/) into my Kubernetes cluster which is running on AWS and I am trying to expose this service externally.
These are the current details of my nats service.
NAME TYPE CLUSTER-IP EXTERNAL-IP
nats ClusterIP None None
Port(s)
4222/TCP,6222/TCP,8222/TCP,7777/TCP,7422/TCP,7522/TCP
Currently, the nats service is a ClusterIP service and when I try to patch it to become a LoadBalancer service with this command:
kubectl patch svc nats -p '{"spec": {"type": "LoadBalancer"}}'
It leads to this error:
The Service "nats" is invalid: spec.clusterIP: Invalid value: "None": may not be set to 'None' for LoadBalancer services.
Hence, how can I be actually expose this Nats service externally? Any guidance provided will be greatly appreciated.
You probably noticed that your
.spec.clusterIP
is set toNone
. SettingNone
will make the serviceheadless
. This is the exact reason why you are unable to patch this service.Headless Service are used for service discovery mechanism and your
nats
service is used exactly for that purpose. Basically with headless service instead of returning single DNS A records, the DNS server will return multiple A records for your service each pointing to the IP of an individual pods that backs the service. So you do simle DNS A records lookup and get the IP of all of the pods that are part of the service.In its essence
nats
service is used forcluster-advertising
:Finally, instead of patching this service you should create a new service with type Loadbalancer.
For more reading please check: