Hosts for Pods that cannot resolve DNS.
A Rust sidecar that rewrites /etc/hosts from hosts_list and AWS endpoints.
Rewritten every 10 seconds
-
Rebuild from base_hosts
kubelet’s hosts is kept as base_hosts and copied back each cycle.
-
Resolve eight at a time
Each line is resolved as an A record. Only answers are appended.
-
Validate, then replace
Every line is checked as IPv4 / IPv6, then written in place.
TTL in setting.ini sets the interval. Ten seconds by default.
A container’s hosts file is its own
nginx only reads the file the sidecar writes if both containers mount it. An initContainer copies kubelet’s hosts into an emptyDir; each container mounts that file over /etc/hosts with subPath.
CoreDNS is the one point every Pod queries. Start with NodeLocal DNSCache; add this for Pods that must survive DNS.
Not faster DNS. No DNS.
Both approaches still resolve names. hosts-creator does not.
| Aspect | NodeLocal DNSCache | single-request-reopen | hosts-creator |
|---|---|---|---|
| Path | Node cache, then CoreDNS | glibc stub resolver | /etc/hosts via NSS |
| When DNS fails | Fails after cache | Fails | Unaffected |
| Load on CoreDNS | Lower on hits | Unchanged | None |
| RDS failover | Record TTL | Record TTL | Next cycle |
| App changes | None | resolv.conf | None, privileged |
CoreDNS is the one point every Pod queries. hosts-creator sends nothing there. Start with NodeLocal DNSCache; add this for Pods that must survive DNS.
Run one cycle and check
Validate the settings and read the resolution before production. Neither writes /etc/hosts.
hosts-creator --check-config
hosts-creator --once --dry-run
--once one cycle, then exit
--dry-run print, write nothing
--check-config validate only
Drop --once to run as a daemon. Exit 0 is healthy; 1 means a setting, a lookup or a write failed.
What setting.ini decides
| Key | Value | Default |
|---|---|---|
| TTL | Seconds between rewrites | 10 |
| GET_RDS_ENDPOINT | List RDS endpoints | False |
| GET_REDIS_ENDPOINT | List ElastiCache endpoints | False |
| CLOUD_ENV | Per section. aws only | aws |
| SELECT_TAG_KEY | Tag key. Empty is all | empty |
| SELECT_TAG_VALUE | Tag value | empty |
Install with kustomize
One emptyDir, one initContainer to seed it, then the same file in both containers. To list RDS or ElastiCache, use a ServiceAccount with Describe permissions (IRSA).
initContainers:
- name: seed-hosts
image: busybox:1.36
command: ["sh", "-c", "cp /etc/hosts /hosts-shared/hosts"]
volumes:
- name: hosts-shared
emptyDir: {}
containers:
- name: create-hosts
image: rhemsjapan/hosts-creator:rust-latest
volumeMounts:
- { name: hosts-shared, mountPath: /etc/hosts, subPath: hosts }
- { name: setting-ini, mountPath: /etc/create_hosts/setting.ini, subPath: setting.ini }
What it costs to run
Measured, not estimated: the arm64 image ran in Docker at TTL 10 s for two minutes.
| Metric | Measured, 8 hostnames, TTL 10 s, 2 min |
|---|---|
| cgroup memory | 9.4 MiB |
| Threads | 17 |
| CPU | 0.00 % |
| Image, arm64 unpacked | 172 MB |
Read from the cgroup after two minutes at TTL 10 s on arm64. There is no cache, so nothing is retained per name. Suggested requests cpu 10m / memory 32Mi, limits cpu 100m / memory 64Mi, for this container alone.
Inside, and when it fails
| Aspect | Behaviour |
|---|---|
| Resolution | hickory, eight at a time. No cache. |
| Write | Validate, then replace in place. |
| Shutdown | SIGTERM finishes the cycle in flight. |
| Settings | setting.ini, env, defaults. Flags win. |
| On failure | Exit 1. Kubernetes restarts it. |
| Records | A records only. |
| Tags | One side only warns. |