Kubernetes local development DB

6/2/2018

I have a local kubernetes cluster setup using the edge release of docker (mac). My pods use an env var that I've defined to be my DB's url. These env vars are defined in a config map as:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config 
data:
  DB_URL: postgres://user@localhost/my_dev_db?sslmode=disable

What should I be using here instead of localhost? I need this env var to point to my local dev machine.

-- TheKernel
docker
kubernetes

2 Answers

6/2/2018

You can use the private lan address of your computer, but please ensure that your database software is listening to all network interfaces and there is no firewall blocking incoming traffic.

If your LAN address is dynamic, you could use an internal DNS name pointing to your computer if your network setup provides one.

Another option is to run your database inside the kubernetes cluster: this way you could use it's service name as the hostname.

-- whites11
Source: StackOverflow

9/18/2018

Option 1 - Local Networking Approach

If you are running minikube, I would recommend taking a look at the answers to this question: Routing an internal Kubernetes IP address to the host system

Option 2 - Tunneling Solution: Connect to an External Service

A very simple but a little hacky solution would be to use a tunneling tool like ngrok: https://ngrok.com/

Option 3 - Cloud-native Development (run everything inside k8s)

If you plan to follow the suggestions of whites11, you could make your life a lot easier with using a kubernetes-native dev tool such as DevSpace (https://github.com/covexo/devspace) or Draft (https://github.com/Azure/draft). Both work with minikube or other self-hosted clusters.

-- LukasGentele
Source: StackOverflow