Search code examples
kubernetestcpminikubenetstat

netstat showing foreign ports as kubernetes:port. What does this mean?


I am using a Windows 10 Pro machine.

When I run netstat, it is showing kubernetes:port as foreign address in active connections.

What does this mean? I have checked and there is no kubernetes cluster running on my machine.

How do I close these connections?

enter image description here

Minikube status:

$ minikube status
host:
kubelet:
apiserver:
kubectl:

Solution

  • That happens because of the way netstat renders output. It has nothing to do with actual Kubernetes.

    I have Docker Desktop for Windows and it adds this to the hosts file:

    # Added by Docker Desktop
    192.168.43.196 host.docker.internal
    192.168.43.196 gateway.docker.internal
    # To allow the same kube context to work on the host and the container:
    127.0.0.1 kubernetes.docker.internal
    # End of section
    

    There is a record which maps 127.0.0.1 to kubernetes.docker.internal. When netstat renders its output, it resolves foreign address and it looks at the hosts file and sees this record. It says kubernetes and that is what you see in the console. You can try to change it to

    127.0.0.1 tomato.docker.internal
    

    With this, netstat will print:

      Proto  Local Address          Foreign Address        State
      TCP    127.0.0.1:6940         tomato:6941            ESTABLISHED
      TCP    127.0.0.1:6941         tomato:6940            ESTABLISHED
      TCP    127.0.0.1:8080         tomato:40347           ESTABLISHED
      TCP    127.0.0.1:8080         tomato:40348           ESTABLISHED
      TCP    127.0.0.1:8080         tomato:40349           ESTABLISHED
    

    So what actually happens is there are connections from localhost to localhost (netstat -b will show apps that create them). Nothing to do with Kubernetes.