Skip to content

x4901/tcp-echo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tcp-echo

An echo server for TCP socket communication. Besides echoing it provides details about its current location (Docker, Kubernetes) and the IP addresses connecting to it.

Its primary function is to serve as a debugging tool for socket based communication with Docker containers and Kubernetes.

A modernized and adapted version of go-tcp-echo.

Docker

Running the container the traditional way will result in getting the IP address of the Docker gateway instead of the real client address on connections:

> docker run --rm -it -e TCP_PORT=2701 -e NODE_NAME="EchoNode" -p 2701:2701 tcp-echo
...

> nc localhost 2701
Connecting from: 172.17.0.1:53340
Welcome, you are connected to node EchoNode.

While running the container in host networking mode will provide the correct client address. However, in this mode other network settings, like port redirection, will be ignored.

> docker run --rm -it -e TCP_PORT=2701 -e NODE_NAME="EchoNode" -p 2701:2701 --network host tcp-echo
WARNING: Published ports are discarded when using host network mode

> nc localhost 2701
Connecting from: 127.0.0.1:36680
Welcome, you are connected to node EchoNode.

Kubernetes

cd k8s
kubectl install/delete -f .

Running the container as a normal service with a load balancer will result in the service getting the IP address of the load balancer instead of the address of the connecting client:

> kubectl get svc
NAME               TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
oms-aks            LoadBalancer   10.0.179.52    20.93.175.223   8080:32273/TCP   2d7h
tcp-echo-service   LoadBalancer   10.0.10.197    20.23.160.77    2701:32226/TCP   11s
ts-aks             LoadBalancer   10.0.233.135   20.76.150.36    8080:32335/TCP   32h

> nc 20.23.160.77 2701
Connecting from: 10.244.2.1:45440
Welcome, you are connected to node aks-agentpool-12549896-vmss000002.
Running on Pod tcp-echo-deployment-5fc89597fd-88sgx.
In namespace default.
With IP address 10.244.2.45.
Service default.

Adding externalTrafficPolicy: Local to the service description changes that. The echo service can pickup the client address again. See A Deep Dive into Kubernetes External Traffic Policies for an explanation.

> kubectl get svc
NAME               TYPE           CLUSTER-IP     EXTERNAL-IP     PORT(S)          AGE
kubernetes         ClusterIP      10.0.0.1       <none>          443/TCP          5d7h
oms-aks            LoadBalancer   10.0.179.52    20.93.175.223   8080:32273/TCP   2d7h
tcp-echo-service   LoadBalancer   10.0.192.132   20.23.160.87    2701:30382/TCP   88s

> nc 20.23.160.87 2701
Connecting from: 95.91.215.108:46020
Welcome, you are connected to node aks-agentpool-12549896-vmss000002.
Running on Pod tcp-echo-deployment-5fc89597fd-sz8nj.
In namespace default.
With IP address 10.244.2.46.
Service default.

About

An echo server for TCP socket communication, mainly for testing (K8s, Docker)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors