New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generated /etc/hosts names are backwards #3521

Closed
anarcat opened this Issue Oct 12, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@anarcat
Contributor

anarcat commented Oct 12, 2018

The /etc/hosts files generated by kubespray are useful, but actually use an incorrect (but common) syntax, for example:

# Ansible inventory hosts BEGIN
10.0.1.20 kubeadmin kubeadmin.example.org
10.0.1.21 kube01 kube01.example.org
10.0.1.22 kube02 kube02.example.org
# Ansible inventory hosts END

Notice how the short domain name (e.g. kubeadmin) is before the fully-qualified domain name (FQDN, kubeadmin.example.org).

This is, arguably, a very minor difference, but it has an impact over unrelated components. For example, hostname -f does not return the right domain name:

$ hostname
kubeadmin
$ hostname -f
kubeadmin

A properly configured host would return a FQDN for hostname -f, like this:

$ hostname
kubeadmin
$ hostname -f
kubeadmin.example.org

The /etc/hosts manual page is pretty clear on the topic:

For each host a single line should be present with the following information:

IP_address canonical_hostname [aliases...]

[...] Optional aliases provide for name changes, alternate spellings, shorter hostnames, or generic hostnames (for example, localhost).

The EXAMPLES section is similarly unambiguous: the FQDN comes first.

Reversing those domain names in the /etc/hosts file will fix that problem, for which I will submit a PR shortly.

Environment:

  • Cloud provider or hardware configuration: baremetal
  • OS (printf "$(uname -srm)\n$(cat /etc/os-release)\n"): Linux 4.9.0-7-amd64 x86_64 Debian GNU/Linux 9 (stretch)
  • Version of Ansible (ansible --version): N/A

Kubespray version (commit) (git rev-parse --short HEAD): v2.5.0 (but also applies to later versions)

Network plugin used: calico

Copy of your inventory file:

[all]
kubeadmin        ansible_host=192.168.0.1 ip=10.0.1.20
kube01           ansible_host=192.168.0.2 ip=10.0.1.21
kube02           ansible_host=192.168.0.2 ip=10.0.1.22

[kube-master]
kubeadmin

[kube-node]
kubeadmin
kube01
kube02

[etcd]
kubeadmin

[k8s-cluster:children]
kube-node
kube-master

[calico-rr]

[vault]
kubeadmin
kube01
kube02

Command used to invoke ansible:

ansible-playbook -u root -b -i inventory/mykube/hosts.ini cluster.yml

Output of ansible run:

N/A

anarcat added a commit to anarcat/kubespray that referenced this issue Oct 12, 2018

show FQDN first in /etc/hosts (closes: kubernetes-incubator#3521)
The hosts(5) manpage clearly states that the first entry is the
"canonical name", or FQDN (Fully-Qualified Domain Name):

    IP_address canonical_hostname [aliases...]

By using the alias as a first entry, `hostname -f` does not return the
correct domain which breaks all sorts of unrelated functionality (it
has impact over email server configuration, for example).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment