kubernetes: Unable to resolve hostname using `kubectl logs`
Using kubectl logs shows the following error:
Error from server: Get https://node-1:10250/containerLogs/kube-system/kibana-logging-v1-x1hr3/kibana-logging: dial tcp: lookup node-1: no such host
Kubernetes master uses nodeName to fetch logs from kubelet, which doesn’t always resolve. There are two workarounds as I can think of:
- Manually add host entry in master’s /etc/hosts, but this doesn’t scale;
- Use hostname override to use raw IP address. This is better, but raw IP is hard to manage and we see this error https://github.com/kubernetes/kubernetes/issues/22109
Since master already have the mapping from nodeName to IPAddress, we can get rid of the problem by just using internal IP?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 14
- Comments: 24 (9 by maintainers)
Commits related to this issue
- Use nodeutil.GetHostIP consistently when talking to nodes Most of our communications from apiserver -> nodes used nodutil.GetNodeHostIP, but a few places didn't - and this meant that the node name ne... — committed to justinsb/kubernetes by justinsb 8 years ago
- Hostname alias fixes Change the kubelet --hostname-override flag to use the ansible_hostname variable which should be more consistent with the value required by cloud providers Add ansible_hostname ... — committed to chadswen/kargo by chadswen 8 years ago
- couldn't fetch log from dashboard or run kubectl exec: kubernetes/kubernetes#22770 — committed to fouadsemaan/ansible-kubernetes-cluster by fouadsemaan 7 years ago
- kubernetes/kubernetes#22770 couldn't fetch log from dashboard or run kubectl exec (#8) * couldn't fetch log from dashboard or run kubectl exec: kubernetes/kubernetes#22770 * put kubelet preferred... — committed to andrewrothstein/ansible-kubernetes-cluster by fouadsemaan 7 years ago
This is about to become a much bigger problem as it affects everyone using the new
kubeadmtool: https://lukemarsden.github.io/docs/getting-started-guides/kubeadm/#limitationsI confirm that
kubectl logsandkubectl execwork when using Kubernetes 1.5.0-beta3 and having set--kubelet-preferred-address-types=InternalIP,Hostname,ExternalIPfor apiserver.We should be using the
nodeutil.GetNodeHostIP, not the NodeName. It is a long standing bug. I’ll try to put together a PR.I also encountered a similar problem, weave network Kai not.
@mkulke minor correction (because I just ran into it), use
--kubelet-preferred-address-types.I haven’t had the time to test an 1.5 cluster yet, but from looking at the code, i guess what works now is:
--hostname-overrideon the kubelet.@hectorj2f By default the node uses the node’s hostname, so when you use
--hostname-overridewith some non-resolvable display name (e.g. “my-node-1”), the master will not be able to talk to the kubelet, because by default the hostname will be preferred as means to talk to the kubelet.however in 1.5 there is also
--kubelet-preferred-address-types(https://github.com/kubernetes/kubernetes/blob/release-1.5/cmd/kube-apiserver/app/options/options.go#L112), which you can use to specify a priority list of comm options (Hostname, InternalIP, ExternalIP, LegacyHostIP).The flag is not documented yet, but I think this should solve most issues around apiserver->kubelet comm.
We also have a similar problem. We defined a specific hostname (not resolvable) to get a customized node name. We also specify the node-ip to a resolvable IP address in the kubelet parameters. So we expected the master api to use that
node-ipinstead of the hostname or node name.Surprisingly for us, kubernetes master uses the hostname to communicate with the kubelet instead of the node ip. So it cannot fetch the logs of our apps.