I have created a redis deployment and a headless service. How do I access the same? I have an ingress deployment which am able to route traffic thro’ nodeport (it works fine when am not experimenting with headless).

The endpoints seem to be fine.

root@curl:/# curl default-http-backend.ingress-nginx.svc.cluster.local
root@curl:/# curl redis-commander.default.svc.cluster.local
curl: (7) Failed to connect to redis-commander.default.svc.cluster.local port 80: Connection refused

curl to the endpoint works fine.

kubectl describe svc/redis-commander
Name:              redis-commander
Namespace:         default
Labels:            name=redis-commander
Annotations:       <none>
Selector:          name=redis-commander
Type:              ClusterIP
IP:                None
Port:              <unset>  8080/TCP
TargetPort:        8081/TCP
Endpoints:         10.244.0.144:8081,10.244.1.4:8081,10.244.1.84:8081
Session Affinity:  None
Events:            <none>

Pls help.

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi there @madhavig77,

As far as I can see from the information that you’ve provided the Redis service is only available on port 8080 and not port 80, this is why you are getting the Connection refused message when you try to use curl.

Hope that this helps!
Regards,
Bobby

  • Thanks. I should have mentioned earlier, it doesn’t work with the port 8080 which my service should be listening on. However, it works with 8081 which my pods are listening… Is this how headless service is supposed to work?

    # curl default-http-backend.ingress-nginx.svc.cluster.local
    default backend - 404
    
    root@curl:/# curl redis-commander.default.svc.cluster.local:8080
    curl: (7) Failed to connect to redis-commander.default.svc.cluster.local port 8080: Connection refused
    
    root@curl:/# curl redis-commander.default.svc.cluster.local:8081 
    <!DOCTYPE html>
    <html>
    <head>
    
    edited by bobbyiliev
    • Hi there @madhavig77,

      Ah yes indeed, the Endpoints are all listening on 8081 so this is why it is available on port 8081 locally on the cluster.

      If you use the service name itself redis-commander then you should be able to use port 8080 instead: redis-commander:8080.

      Regards,
      Bobby

      • Here’s my understanding - The headless service uses target port - in this case 8081 with the selector name: redis-commander.

        Headless svc is just grouping the pods with the same label selector together and hence there’s no actual meaning to the port(service) I got the svc working when i made both the target port and service port same.

        Thank you Bobby.

        Best regards,
        MG.

Submit an Answer