Home > database >  Why Kubernetes services can not be resolved?
Why Kubernetes services can not be resolved?

Time:06-13

In my namespace I have services

k get svc
NAME              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)          AGE
blue-service      NodePort    10.107.127.118   <none>        80:32092/TCP     60m
demo              ClusterIP   10.111.134.22    <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)... 10.107.127.118
Connecting to blue-service (blue-service)|10.107.127.118|:80... failed: Connection timed out.
Retrying.

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
IP:                       10.107.127.118
IPs:                      10.107.127.118
Port:                     <unset>  80/TCP
TargetPort:               8080/TCP
NodePort:                 <unset>  32092/TCP
Endpoints:                172.17.0.39:8080,172.17.0.40:8080,172.17.0.41:8080
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   <none>

Why?

CodePudding user response:

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

or

  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

  • Related