通过vagrant+virtualbox安装k8s找不到pod问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了通过vagrant+virtualbox安装k8s找不到pod问题相关的知识,希望对你有一定的参考价值。

参考技术A

通过vagrant+virtualbox安装k8s集群的小伙伴都会碰到找不到pod的问题,但是通过api服务查看,这些pod却是活的好好的。
原因是 ,在virtualbox组网的过程中,采用了双网卡方案,网卡1使用NAT地址转换用来访问互联网,网卡2使用Host-only来实现虚拟机互相访问。 各节点各kubelet默认把网卡1的NAT地址当做了自己的IP,上报给了master节点,而节点之间是无法通过这个地址连通的 。所以我们将其改成虚拟机之间可以相互访问的地址(这里是host-only)即可。

将 /etc/sysconfig/kubelet 中的 KUBELET_EXTRA_ARGS 改成如下所示

然后重启kubelet

待kubelet起来后,问题解决。

vagrant + virtualbox安装centos环境

1. 下载vagrant 并安装,安装完成后,输入vagrant回车查看是否安装成功

2. 下载virtualbox.box并安装,安装完成后。

3. 创建虚拟机文件夹,例如、F:/vmimg/first-docker-centos 在此目录下运行 vagrant init 生成Vagrantfile文件(可以自定义一些属性)

 

然后绑定centos的操作系统镜像virtualbox.box所在路径 

F:vmimgfirst-docker-centos>vagrant box add centos/7 E:BaiduNetdiskDownloadcentos7.0virtualbox.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box ‘centos/7‘ (v0) for provider:
box: Unpacking necessary files from: file:///E:/BaiduNetdiskDownload/centos7.0/virtualbox.box
box:
==> box: Successfully added box ‘centos/7‘ (v0) for ‘virtualbox‘!

输入vagrant list 查看当前box

F:vmimgfirst-docker-centos>vagrant box list
centos/7 (virtualbox, 0)

然后输入vagrant up命令创建并启动虚拟机

F:vmimgfirst-docker-centos>vagrant up

Bringing machine ‘default‘ up with ‘virtualbox‘ provider...
==> default: Importing base box ‘centos/7‘...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: lf-centos7
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
default: Adapter 2: bridged
==> default: Forwarding ports...
default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running ‘pre-boot‘ VM customizations...
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2222
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it‘s present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Configuring and enabling network interfaces...
==> default: Rsyncing folder: /cygdrive/f/vmimg/first-docker-centos/ => /vagrant

F:vmimgfirst-docker-centos>

查看centos一些相关信息

F:vmimgfirst-docker-centos>vagrant ssh-config
Host default
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile F:/vmimg/first-docker-centos/.vagrant/machines/default/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

Xshell连接:

Ip:127.0.0.1

port:2222

username:vagrant

password:vagrant

文件 identityfile所指向的路径

使用root用户登录:

sudu -i

vi etc/ssh/sshd_config

修改PasswordAuthentication yes

passwd修改密码

systemctl restart sshd

root vagrant 登录

BOX打包分发:

01退出虚拟机  vagrant halt

02打包 vagrant package --output first-docker-centos.box

03得到first-docker-centos.box

04 将first-docker-centos.box添加到其他vagrant环境中

  vagrant box add first-docker-centos first-docker-centos.box

05 得到vagrantfile

  vagrant init  first-docker-centos

06 根据vagrantfile启动虚拟机

  vagrant up (网络可能需要从新配置)

以上是关于通过vagrant+virtualbox安装k8s找不到pod问题的主要内容,如果未能解决你的问题,请参考以下文章

使用vagrant搭建k8s节点一

使用vagrant搭建k8s节点一

mac上kubeadmin安装k8s(完整)

二:通过VirtualBox+Vagrant创建一个centos的虚拟机:

怎么使用vagrant的box

mac下virtualbox+vagrant安装