How to Add Custom Hostnames in Kubernetes CoreDNS?

0
7
Asked By TechieTurtle42 On

Hey everyone, I'm trying to get some local host entries integrated into the CoreDNS of my Kubernetes setup. I've drafted a YAML to add custom DNS entries but when I boot a Fedora container, I can't see these entries in the host table. Here's what I've got:

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: coredns-custom
namespace: kube-system
data:
# The key name can be anything, but must end with .override
local-containers.override: |
hosts {
192.168.12.6 oracle.fedora.local broker01.fedora.local broker02.fedora.local broker03.fedora.local oracle broker01 broker02 broker03

fallthrough
}
```

I noticed the config map seems to expect files in `etc/coredns/custom/*.override`, but I'm not sure if what I've created fits that requirement. I briefly experimented with adding a custom host block, but that broke DNS in the containers. Plus, a block for Docker hosts didn't persist. Ultimately, I'm just looking for a way to set up custom name resolution without going through the hassle of setting up a full DNS server. For what it's worth, after implementing the above configuration, my CoreDNS pod fails to start. Any insights would be greatly appreciated!

2 Answers

Answered By CodeWanderer77 On

It looks like you might be missing some details in your setup. Check out this guide that talks about adding custom hosts to Kubernetes. The `local-containers.override` might not be recognized as part of the Kubernetes standard, which could be why you're not seeing those entries. Here's the link: [How to add custom hosts](https://hjrocha.medium.com/add-a-custom-host-to-kubernetes-a06472cedccb).

Answered By CloudNinja21 On

Another approach you could consider is using the `hostAlias` feature directly in your deployment definitions. This allows you to specify hostnames right in the deployment file, which might be easier than messing with CoreDNS directly. You can find more info about it here: [Customize Hosts File for Pods](https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/).

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.