mmumshad / kubernetes-the-hard-way

Bootstrap Kubernetes the hard way on Vagrant on Local Machine. No scripts.
Apache License 2.0
4.6k stars 4.48k forks source link

[Bug]: dig worker-1 is worng #340

Closed yin-zt closed 6 months ago

yin-zt commented 6 months ago

Your Workstation

Windows 10 Laptop, 16 GB RAM, 8 core i7 CPU

What happened?

MASTER_1=$(dig +short master-1) MASTER_2=$(dig +short master-2) LOADBALANCER=$(dig +short loadbalancer)

dig command only analyze domain record with the content of /etc/resolv.conf, it can't get correct answer with above command. Unless your bind server has domain record, via master-1 in the special zone "rpz.zone".

Relevant output

No response

fireflycons commented 6 months ago

Hi @yin-zt

Are you using the latest version of this lab? Judging by what you have pasted above, I would guess not. A new version of the lab was merged around 48 hours ago.

The way this is set up is that the provisioner writes the IP addresses of all VMs to the hosts file of each VM therefore the dig command will return the IP addresses as per the content of /etc/hosts

DNS is not used for resolving addresses of local nodes, only for external addresses. /etc/nsswitch.conf is set to prefer files over DNS for name resolution.

Nodes cannot be resolved from outside of the VMs.

Expected behaviour:

vagrant@controlplane01:~$ cat /etc/hosts
127.0.0.1       localhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost   ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

192.168.56.11  controlplane01
192.168.56.12  controlplane02
192.168.56.21  node01
192.168.56.22  node02
192.168.56.30  loadbalancer

vagrant@controlplane01:~$ CONTROL01=$(dig +short controlplane01)
vagrant@controlplane01:~$ CONTROL02=$(dig +short controlplane02)
vagrant@controlplane01:~$ LOADBALANCER=$(dig +short loadbalancer)
vagrant@controlplane01:~$ echo $CONTROL01
192.168.56.11
vagrant@controlplane01:~$ echo $CONTROL02
192.168.56.12
vagrant@controlplane01:~$ echo $LOADBALANCER
192.168.56.30
vagrant@controlplane01:~$
yin-zt commented 6 months ago

i am so grateful for your reply, i had finished the experiment following your articles. But i doubt to use dig command to find out vm ip. the following is the output when i execute command:

[root@master-1 ~]# cat /etc/hosts
::1 localhost   localhost.localdomain   localhost6  localhost6.localdomain6
10.9.89.220 mailong-test-3.cloud.onecloud.io    mailong-test-3
127.0.0.1   localhost
10.9.89.220 master-1
10.9.89.219 master-2
10.9.89.221 worker-1
10.9.89.222 worker-2

[root@master-1 ~]# cat /etc/nsswitch.conf | grep hosts 
#hosts:     db files nisplus nis dns
hosts:      files dns myhostname
[root@master-1 ~]# cat /etc/resolv.conf 
; generated by /usr/sbin/dhclient-script
#search cloud.onecloud.io
#nameserver 10.1.48.72
nameserver 10.9.108.223
nameserver 10.9.109.221
[root@master-1 ~]# dig +short master-1
[root@master-1 ~]# vim /etc/resolv.conf 
[root@master-1 ~]# cat /etc/resolv.conf 
; generated by /usr/sbin/dhclient-script
#search cloud.onecloud.io
#nameserver 10.1.48.72
nameserver 8.8.8.8
#nameserver 10.9.108.223
#nameserver 10.9.109.221
[root@master-1 ~]# dig +short master-1
[root@master-1 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
fireflycons commented 6 months ago

Your configuration does not look like it was built according to the instructions in this repo. This repo is set up for building VMs on your workstation, not in cloud. We can only support the two methods presented in the repo

We do not currently support this for cloud providers. Also note that this configuration is NOT production grade by any means.

yin-zt commented 6 months ago

all right, thanks.

fireflycons commented 6 months ago

I'm going to close this now, but should you want to complete this course, please start at the beginning and follow the instructions precisely.

Take special note of the paragraph on the start page titled Before shouting "Help! It's not working!" 😄