『中級篇』Vagrant在本地搭建多節點K8S集群(65)
>原創文章,歡迎轉載。轉載請註明:轉載自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
Tectonic
- Tectonic介紹,註冊後可以免費試用節點數小於10個的
https://coreos.com/tectonic/docs/latest/tutorials/
- 賬號註冊
- 垃圾郵件裏面有
- 註冊成功
PS:遺憾的是:Tectonic已經sandbox下架了,我在網上找了一份直接傳到github了,自己下載吧。直接通過vagantfile的方式搭建。
- 通過vagrantfile安裝
具體vagrant的安裝看我(六)和(七)兩節。關於mac和window下的安裝。
整個安裝過程用了40分鐘。
vagrant up
出現下面的錯誤,你需要×××了兄弟。
Installing the ‘vagrant-ignition‘ plugin. This can take a few minutes...
Vagrant failed to load a configured plugin source. This can be causedby 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 保持通用,我還是用傳統的方式安裝吧。
shell vagrant的方式安裝k8s集群
源碼:https://github.com/limingios/docker/tree/master/No.10
- 下載源碼
https://github.com/limingios/docker/tree/master/No.10
- 本地開發機
所有的部署工作都是在開發機(dev)上進行的。我已經準備好了在源碼中提供。
- 虛機vagrantfile已經編譯好
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
- 把Vagrantfile中的box名與box鏡像關聯起來
# vagrant box add centos7 path_to_your_centos7
# 例如:
vagrant box add centos7 centos7.box
- 啟動開發機(dev)
以後就使用dev來指×××發機了。
圖方便我已經把不安全的公鑰添加到集群機器的/root/.ssh/authorized_keys中了,
為了讓root能從dev遠程登錄到集群機器,需要把insecure_private_key弄到dev的~/.ssh/id_rsa中,可以scp,如果使用的是xshell那就用xshell自帶的sftp
vagrant up dev
-
啟動集群 要安裝6個機器 老鐵你準備好空間
cd vagrant-cluster vagrant up master1 vagrant up master2 vagrant up master3 vagrant up node1 vagrant up node2 vagrant up node3 # 可以直接vagrant up來啟動所有機器
-
進入dev的虛擬主機
vagrant ssh dev #這一步的目的是把壓縮包直接放在vagrant共享目錄下解壓, #結果在最後報軟連接錯誤,直接放入虛擬機的自身目錄就不會爆這個錯誤這個很重要 cp -r deployk8s-master deployk8s cd deployk8s
-
進入dev的虛擬主機通過SecureCRT
- 找到insecure_private_key
- 輸入192.168.0.2 選擇紅色框
- 找到insecure_private_key
- 需要把insecure_private_key弄到dev的~/.ssh/id_rsa中,借助git bash
scp -i ~/.vagrant.d/insecure_private_key ~/.vagrant.d/insecure_private_key [email protected]:~/.ssh/id_rsa
#這個id_rsa的權限是644,需要改為600,在dev機中執行:
chmod 600 ~/.ssh/id_rsa
- 進入dev的虛擬主機
vagrant ssh dev #這一步的目的是把壓縮包直接放在vagrant共享目錄下解壓, #結果在最後報軟連接錯誤,直接放入虛擬機的自身目錄就不會爆這個錯誤這個很重要 cp -r deployk8s-master deployk8s cd deployk8s
-
進入dev的虛擬主機
- 如果可以×××,用下面的腳本。如果×××不了,我已經下載到源碼裏面了 進入vagrant裏面下載。
# 下載cfssl curl -O https://pkg.cfssl.org/R1.2/cfssl_linux-amd64 curl -O https://pkg.cfssl.org/R1.2/cfssljson_linux-amd64 curl -O https://pkg.cfssl.org/R1.2/cfssl-certinfo_linux-amd64
下載keepalived v2.0.6
curl -O http://www.keepalived.org/software/keepalived-2.0.6.tar.gz
下載etcd v3.3.8
curl -O https://github.com/coreos/etcd/releases/download/v3.3.8/etcd-v3.3.8-linux-amd64.tar.gz
下載flannel v0.10.0
curl -O https://github.com/coreos/flannel/releases/download/v0.10.0/flannel-v0.10.0-linux-amd64.tar.gz
下載kubernetes v1.11.0
curl -O https://dl.k8s.io/v1.11.0/kubernetes-server-linux-amd64.tar.gz
最後就開始執行腳本進行部署吧。
![](https://upload-images.jianshu.io/upload_images/11223715-514a1183ee3d643a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
* 部署集群
``` cmd
./deployk8s.sh 2>&1 | tee deployk8s.log
本來想吧幾個文件上傳到github讓懶人老鐵不直接下載了,確實上傳太慢了我放棄了我直接大家網址,他們通過迅雷下載也很快的。
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的一鍵部署!
『中級篇』Vagrant在本地搭建多節點K8S集群(65)