Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:
like image 826
Shubham Chadokar Avatar asked Jan 26 '20 13:01

Shubham Chadokar


People also ask

What is the Kubernetes port?

Port configurations for Kubernetes Services Port exposes the Kubernetes service on the specified port within the cluster. Other pods within the cluster can communicate with this server on the specified port. TargetPort is the port on which the service will send requests to, that your pod will be listening on.

What is Kubernetes used for?

Kubernetes, often abbreviated as “K8s”, orchestrates containerized applications to run on a cluster of hosts. The K8s system automates the deployment and management of cloud native applications using on-premises infrastructure or public cloud platforms.

What is a Kubernetes service?

A Kubernetes service is a logical abstraction for a deployed group of pods in a cluster (which all perform the same function). Since pods are ephemeral, a service enables a group of pods, which provide specific functions (web services, image processing, etc.) to be assigned a name and unique IP address (clusterIP).


2 Answers

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.

like image 119
lastsecondsave Avatar answered Sep 21 '22 14:09

lastsecondsave


It seems that Windows docker changed your hosts file. So, if you want to get rid of these connections, just comment out the corresponding lines in the hosts file.

The hosts file on Windows 10 is located in C:\Windows\System32\drivers\etc and the records may look something like 127.0.0.1 kubernetes.docker.internal. I am pretty sure it will disrupt your docker service on Windows (yet, I am not an expert), so don't forget to uncomment these lines whenever you need to get the docker service back.

like image 41
Leo Skhrnkv Avatar answered Sep 22 '22 14:09

Leo Skhrnkv