0

I'm new to Kubernetes, but have managed to build myself a container that runs perfectly directly under Docker and also seems to run up fine in a k8s deployment.

The container is an implementation of a couple of UDP packet replicators from github installed on Ubuntu.

When it's running directly under Docker on my machine, I can send UDP packets to the container and have them replicated back to different ports on my machine proving that the replication works. (Sending and receiving the packets with netcat).

However, I think I am missing something in the k8s networking side of things.

I am using MiniKube on my machine and I am using the following k8s manifest to create the deployment with just one container.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: samplicator-deployment
  labels:
    app: samplicator
spec:
  replicas: 1
  selector:
    matchLabels:
      app: samplicator
  template:
    metadata:
      labels:
        app: samplicator
    spec:
      containers:
      - name: samplicator-container-01
        image: dgbes/udp-fan-out-tools:latest
        command: ["samplicate"]
        args: ["-p3160","192.168.1.159/3161","192.168.1.159/3162"]
        ports:
        - name: receiver
          protocol: UDP
          containerPort: 3160

I then create the deployment with: kubectl apply -f create-samplicator-deployment.yaml

I then set up a couple of UDP listeners with netcat on my host machine with nc -ulk -p 3161 and nc -ulk -p 3162.

If I then connect to the running container with kubectl exec --stdin --tty samplicator-deployment-{randomPodName} -- /bin/bash and manually use netcat send packets to my host machine I can see those arriving no problem.

I find the container/pod IP address with kubectl get pod -o wide.

When I try to send a packet to the samplicator process in the pod, though, I see nothing coming back to my host machine.

So, I then spawned a shell in the container/pod, checked that the samplicator process was running correctly (it was), and installed netcat in the container instance.

Using netcat -u {my host machine IP} 3161 I can send packets from the container to my host machien and they are received no problem.

So, it seems that the issue is getting the packets TO the container.

I confirmed this by running nc -ulk -p 3600 in the container shell and sending a packet from my host to that port in the container - nothing is received in the container.

I am aware that the ports need to be exposed on the container and that 'services' are used for this, but I thought that that was what the ports: section in the template spec of the deployment was doing.

That didn't create a service to expose the port, so I added a service definition to the end of my deployment manifest YAML as follows:

---
apiVersion: v1       
kind: Service
metadata:
  name: samplicator-service
spec:
  selector:
    app: samplicator
  type: LoadBalancer
  ports:
  - name: receiver-service
    protocol: UDP
    port: 3160
    targetPort: 3160

I'm obviously missing something here, and my apologies if my k8s terminology is a bit mangled - as I say I'm completely new to k8s.

Any pointers to how to correctly make that UDP port reachable?

Fat Monk
  • 2,077
  • 1
  • 26
  • 59

1 Answers1

0

I figured it out...

Service type=LoadBalancer doesn't work with MiniKube as it relies on an external cloud service apparently.

I noticed that my service was sat in a pending state with the ExternalIP never being allocated, which lead me to this answer.

The magic being to simply run the following command in a separate terminal window which then allowed the external IP to be allocated to the service.

minikube tunnel

Once that was run and the ExternalIP allocated, sending packets to that ExternalIP works perfectly.

Fat Monk
  • 2,077
  • 1
  • 26
  • 59