How to Add Custom Host Entries to CoreDNS in Kubernetes?

February 4, 2026 2 answers
Asked by CloudySky99
Hey folks! I'm trying to inject some local host entries into the CoreDNS engine for my Kubernetes setup. I've crafted a YAML file to add these custom entries, which looks like this: ``` 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 } ``` After creating this, I launched a Fedora container, but I can't seem to see those entries in the host table. It looks like the config map is expecting `/etc/coredns/custom/*.override`, and I'm not sure if what I've created matches that requirement. I also tried adding a custom host block, but that caused DNS issues in the containers. I attempted to create a block for docker hosts similar to the node hosts, but that didn't persist either. All I want is custom name resolution without needing a full DNS server setup. Any advice would be greatly appreciated! Another thingโ€”I noticed the coredns pod won't even start after I added my entries. Help!

Answers

TechieTurtle42
You might want to check this guide out; it could provide the clarity you need: [Adding Custom Host to Kubernetes](https://hjrocha.medium.com/add-a-custom-host-to-kubernetes-a06472cedccb). Also, `local-containers.override` doesn't seem to be standard in Kubernetes, so that could be part of the issue.
Reply to this answer
NodeNinja88
Another option is to utilize the hostAlias feature directly in your deployment definition. It might streamline the process for you. You can find more about it here: https://kubernetes.io/docs/tasks/network/customize-hosts-file-for-pods/.
Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions