Why Kubernetes services can not be resolved?

In my namespace I have services

k get svc
NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
blue-service      NodePort   <none>        80:32092/TCP     60m
demo              ClusterIP    <none>        80/TCP           3d

I added blue-service to /etc/hosts
It failes again

wget -O- blue-service
--2022-06-13 11:11:32--  http://blue-service/
Resolving blue-service (blue-service)...
Connecting to blue-service (blue-service)||:80... failed: Connection timed out.

I decided to chech with describe

Name:                     blue-service
Namespace:                default
Labels:                   app=blue
Annotations:              <none>
Selector:                 app=blue
Type:                     NodePort
IP Family Policy:         SingleStack
IP Families:              IPv4
Port:                     <unset>  80/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32092/TCP
Endpoints:      ,,
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>


>Solution :

The services you are referring to do not have an external IP (the External IP field is empty) so you cannot access those services.

If you want to access those services, you either need to

  1. Make them a LoadBalancer service type which will give them an external IP


  1. Use kubectl port-forward to connect a local port on your machine to the service then use localhost:xxxx to access the service

If you want to map a DNS name to the service, you should look at the External DNS project as mentioned in this answer which will allow you to create DNS entries in your provider’s DNS service (if you are running the cluster on a managed platform)

OR, use nip.io if you’re only testing

Leave a Reply