Connect external app to database running in kubernetes?

4/23/2020

I am testing connecting an application running in an external docker container, to a database running in a separate kubernetes cluster. What is the best way to make this connection with security practices in mind.

I am planning on creating an ingress service for the database in the kubernetes cluster. Then, when making the connection from the application, I should only need to add the ingress/service connection to be able to use this db, right?

-- mm_wvu18
docker
kubernetes
kubernetes-ingress
kubernetes-pod
service

2 Answers

4/24/2020

We're running NGINX Ingress Controller which has the option to allow TCP connection from Outside. It's not possible over the CRD Ingress but you can modify a ConfigMap to route traffic to your Service.

https://kubernetes.github.io/ingress-nginx/user-guide/exposing-tcp-udp-services/#exposing-tcp-and-udp-services

The other option would be you create a Service with a NodePort. You will need then a LoadBalancer in front of the NodePort / Nodes to ensure the HA.

If you tell us more about your setup, I believe we can give you more detailed suggestions.

-- CLNRMN
Source: StackOverflow

4/23/2020

Just like anything else, use TLS, make sure all hops are encrypted and verified. Unless your database of choice uses an HTTP-based protocol, Ingress won't help you. So usually this means setting up TLS at the DB level and exposing it with a LoadBalancer service.

-- coderanger
Source: StackOverflow