Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can an `ExternalName` service point to the host machine?

Tags:

kubernetes

I'm working locally (within Docker for Mac) on a Kubernetes cluster that will eventually be deployed to the cloud. We plan to use a database service in that environment. To simulate that, I'd like to have the services in the cluster connect to a database running outside the cluster on my laptop.

Can I do that? Here's what I thought I'd try.

  • Define a Service with type: ExternalName and externalName: somedb.local
  • Add 127.0.0.1 somedb.local to /etc/hosts on the laptop

Is that correct? Is there a better way?

like image 902
Nathan Long Avatar asked Oct 30 '25 21:10

Nathan Long


1 Answers

After talking with some colleagues, I found a solution.

In Docker for Mac, host.docker.internal points to the host machine, and that lets me connect to the db running there, even from containers running in the K8s cluster.

like image 171
Nathan Long Avatar answered Nov 01 '25 14:11

Nathan Long



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!