Can't port forward in Kubernetes

8/12/2019

Trying to port forward the neo4j helm chart (stable/neo4j) using the command:

kubectl port-forward svc/neo-helm-neo4j 7474:7474

However it then gave me the following when I try and hit it from localhost:7474.

Forwarding from 127.0.0.1:7474 -> 7474                                                                                                                                   
Forwarding from [::1]:7474 -> 7474                                                                                                                                       
Handling connection for 7474                                                                                                                                             
E0812 16:19:07.312926   26275 portforward.go:400] an error occurred forwarding 7474 -> 7474: error forwarding port 7474 to pod   b0b0e55e1bcc82090308a82666aa103bb65a48cc34
79ecdb1d51cb0861ddd131, uid : exit status 1: 2019/08/12 15:19:07 socat[50406] E connect(17, AF=2 127.0.0.1:7474, 16): Connection refused

The pods are up and available and the get svc yields

NAME                     TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)    AGE
kubernetes               ClusterIP   10.96.0.1       <none>        443/TCP    10d
neo-helm-neo4j           ClusterIP   None            <none>        7474/TCP   143m

I don't know what I'm missing out on. The fact that the service has no cluster-ip is odd; I would expect there to be one as it is a service. However I'm new to k8s, so this may all be very obviously wrong.

-- David Boshton
kubernetes

1 Answer

8/12/2019

You can port forward pods. Normally this would create problems with scaled deployments but in this case it is headless service. This means neo4j handles master-slave communication itself. You can port forward master pod, please check this reference: https://kubernetes.io/docs/tasks/access-application-cluster/port-forward-access-application-cluster/#forward-a-local-port-to-a-port-on-the-pod

-- Akın Özer
Source: StackOverflow