Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UDP send and receive in kubernetes

For my project, I need to send UDP packets to a Kubernetes Pod from an outside cluster. How can I do this?

I am using Kubeadm for creating the cluster. I tried to use nodePort but it seems that my requirement cannot be fulfilled with Nodeport.

like image 252
Ranjith Koova Avatar asked Jul 13 '18 18:07

Ranjith Koova


People also ask

Does Kubernetes use UDP?

Kubernetes Services support TCP (default), UDP, and SCTP protocols. One of the most popular ways to use Kubernetes Services in AWS is with the LoadBalancer type.

How do you communicate between two services in Kubernetes?

Summary. In Kubernetes, pods can communicate with each other a few different ways: Containers in the same Pod can connect to each other using localhost , and then the port number exposed by the other container. A container in a Pod can connect to another Pod using its IP address.

Can 2 pods communicate in Kubernetes?

Kubernetes assumes that pods can communicate with other pods, regardless of which host they land on. Kubernetes gives every pod its own cluster-private IP address, so you do not need to explicitly create links between pods or map container ports to host ports.

How port forwarding works in Kubernetes?

Kubectl port-forward is a method to access, interact and manage internal Kubernetes clusters directly from your local network. This method is popularly used to investigate issues concerning your applications. Kubectl is a command-line tool that is used to run commands and control Kubernetes clusters.


2 Answers

Actually, NodePort can be used to expose ports within TCP and UDP protocols. What was the problem in your case?

You can consider using Nginx Ingress Controller and creating ReplicationController to implement Nginx ingress in order to expose your Pods across UDP port as described Here or you can check this Link.

Create ConfigMap and specify External port like <namespace/service name>:<service port> which you want to access from outside Kubernetes cluster.

Finally, Nginx ingress can be exposed, i.e., using Kubernetes ExternalIP.

like image 109
Nick_Kh Avatar answered Oct 14 '22 06:10

Nick_Kh


I am able to find the solution for my requirement.

I have exposed the UDP port for my pod and it works fine.

Example

kubectl expose pod udp-server-deployment-8c8d6d868-c77zx --port=10001 --protocol=UDP --external-ip=10.1.11.82 --name=udp-server

Thank you all for your support :)

like image 40
Ranjith Koova Avatar answered Oct 14 '22 05:10

Ranjith Koova