原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢! 原文链接地址:『中级篇』Vagrant在本地搭建多节点K8S集群(65) 这次说说service,service和网络有非常密切的 关系,为了能让大家很好的理解和直观的展示,重新搭建一个环境,之前用minikube搭建是单节点的环境,但是不够直观,这次coreos搭建一个多节点的。源码:https://github.com/limingios/docker/tree/master/No.10
https://github.com/limingios/docker/tree/master/No.9
PS:遗憾的是:Tectonic已经sandbox下架了,我在网上找了一份直接传到github了,自己下载吧。直接通过vagantfile的方式搭建。
vagrant up
出现下面的错误,你需要访问外国网站了兄弟。 Installing the 'vagrant-ignition' plugin. This can take a few minutes...
Vagrant failed to load a configured plugin source. This can be caused
by a variety of issues including: transient connectivity issues, proxy
filtering rejecting access to a configured plugin source, or a configured
plugin source not responding correctly. Please review the error message
below to help resolve the issue:
开启访问外国网站后
因为目前Tectonic 已经没有sandbox 保持通用,我还是用传统的方式安装吧。
Vagrant.configure(2) do |config|
# 设置dev虚机环境(下面还要写dev.vm,好扯淡)
config.vm.define "dev" do |dev|
# 设置虚拟机的Box
dev.vm.box = "centos7"
# 设置虚拟机的主机名
dev.vm.hostname = "dev"
# 设置虚拟机的IP
dev.vm.network "private_network", ip: "192.168.0.2"
# VirtaulBox相关配置
dev.vm.provider "virtualbox" do |vb|
# 设置虚拟机的内存大小
vb.memory = 512
# 设置虚拟机的CPU个数
vb.cpus = 1
end
# 挂载失败了,mount: unknown filesystem type 'vboxsf'
# config.vm.synced_folder ".", "/home/vagrant/deployk8s"
# 使用默认挂载
# 使用shell脚本进行软件安装和配置
dev.vm.provision "shell", path: "dev.sh"
end
# ssh配置
config.ssh.username = "vagrant"
config.ssh.private_key_path = "~/.vagrant.d/insecure_private_key"
config.ssh.insert_key = false
end
# vagrant box add centos7 path_to_your_centos7
# 例如:
vagrant box add centos7 centos7.box
vagrant up dev
scp -i ~/.vagrant.d/insecure_private_key \
~/.vagrant.d/insecure_private_key \
vagrant@192.168.0.2:~/.ssh/id_rsa
#这个id_rsa的权限是644,需要改为600,在dev机中执行:
chmod 600 ~/.ssh/id_rsa
本来想吧几个文件上传到github让懒人老铁不直接下载了,确实上传太慢了我放弃了我直接大家网址,他们通过迅雷下载也很快的。
image.png
https://vagrantcloud.com/centos/boxes/7/versions/1804.02/providers/virtualbox.box
https://dl.k8s.io/v1.11.0/kubernetes-server-linux-amd64.tar.gz
https://github.com/coreos/etcd/releases/download/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz
https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz
https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
https://pkg.cfssl.org/R1.2/cfssl_linux-amd64
http://www.keepalived.org/software/keepalived-2.0.6.tar.gz
https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64
#下载后还放到No.10的deployk8s-master下就可以了。
有老铁问我,dev,master,node,他们之间的关系dev 就是锤子,node 就是房子,master就是打开房子的大门。用锤子打造了一个建筑,但是锤子不属于建筑物,所以ping 什么一系列的操作都ping不通pod的。
PS:这种方式感觉很受用,感谢xujintao 的技术指导和他的github的思路引导成功部署的https://github.com/xujintao/deployk8s的一键部署!