Can Nginx be used to balance TCP traffic inside Kubernetes?

1/16/2020

My leegacy server uses TCP sockets to serve clients (also inside kubernetes). Clients also run inside the same cluster in which server is. Can we use NGINX to distribute traffic to server POD instances ? If so how ?

-- Chandu
kubernetes
load-balancing
nginx
tcp

2 Answers

1/16/2020

Kubernetes Service does exactly that. You don't need nginx to do load balancing across pods inside the cluster.

If you want to to weighted distribution of traffic, look at istio or envoy ambassador.

https://istio.io/docs/tasks/traffic-management/tcp-traffic-shifting/ https://www.getambassador.io/reference/tcpmappings/

-- Shashank V
Source: StackOverflow

1/16/2020

Yes its possible.The standard Kubernetes Ingress resources assume that all traffic is HTTP-based; they do not cater for the case of basic TCP or UDP load balancing. You need to use the stream-snippets ConfigMap key to embed the required TCP and UDP load-balancing configuration directly into the stream{} block of the NGINX configuration file. Here is the example.

-- Arghya Sadhu
Source: StackOverflow