Migrating from Docker Swarm: Exposing my Kubernetes service to the world (on a well-known port)

2/5/2019

I run a tiny (read: single-node) Docker Swarm cluster that I want to migrate to Kubernetes, and I can't figure out how to expose a Service on a specific port so that I can access it from the outside world.

In Docker Swarm, I could expose e.g. a MySQL server by specifying

ports:
  - '3306:3306'

as part of the service block in my stack configuration file, which would let me access it on 127.0.0.1:3306.

To replicate this in Kubernetes, my first instinct was to use the NodePort service type and specifying

ports:
  - port: 3306
    targetPort: 3306
    nodePort: 3306

in the service spec. But this is not allowed: Kubernetes tells me provided port is not in the valid range. The range of valid ports is 30000-32767.

Then there is Ingress, which seems closely aligned with what I want to do, but it's in beta and is apparently geared towards HTTP services (which does not cover all my use cases). There is also the LoadBalancer type, but I'm not using a cloud provider with support for it and so that isn't an option for me.

This has left me a bit confused. If I want to expose a service in my Kubernetes cluster so that I can access it from the outside (e.g. from the internet at large on some-public-ip:3306), what is a recommended (or alternatively, beginner-friendly) way to set it up? What am I missing?

-- James
docker-swarm
kubernetes

2 Answers

2/5/2019

Run ha-proxy to proxy database traffic to mysq k8 service, Ha-proxy supports https as well as tcp traffic

-- P Ekambaram
Source: StackOverflow

2/5/2019

NodePort is probably the simplest approach, but you will need to pick a port in the range 30000 - 32767. That way you'd access say some-public-ip:30306 which would map to your service's port 3306 internally.

-- Paul Annetts
Source: StackOverflow