Writing Host Aliases in Kubernetes Manifests

kubernetes
2022-04-22 13:24 (3 years ago)
Writing Host Aliases in Kubernetes Manifests

I often forget this, so here's a note.

https://kubernetes.io/ja/docs/tasks/network/customize-hosts-file-for-pods/

apiVersion: apps/v1
kind: Deployment
  spec:
  ...
  template:
    ...
    spec:
      hostAliases:
        - hostnames:
            - target-host.example.com
          ip: 192.168.0.XX

How to check

$ cat /etc/hosts
# Kubernetes-managed hosts file.
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
172.31.XX.XX    podname-aaaabbbb

# Entries added by HostAliases.
192.168.0.XX   target-host.example.com
Please rate this article
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Categories

Archive