學(xué)習(xí)kubernetes的時候,我們需要在kubernetes環(huán)境下實(shí)戰(zhàn)操作,然而kubernetes環(huán)境安裝并不容器,現(xiàn)在通過rancher可以簡化安裝過程,咱們來實(shí)戰(zhàn)rancher下的kubernetes吧;
整個實(shí)戰(zhàn)分為兩章:《構(gòu)建標(biāo)準(zhǔn)化vmware鏡像》和《安裝部署rancher、kubernetes》
前提條件
由于要用到谷歌的服務(wù),所以要求您的網(wǎng)絡(luò)環(huán)境可以科學(xué)上網(wǎng),具體的方案就不在這里說了;
實(shí)戰(zhàn)環(huán)境
本次實(shí)戰(zhàn)用的電腦是win10家庭版,通過vmware運(yùn)行三個ubuntu16.04的虛擬機(jī),一個作為rancher server,在上面創(chuàng)建kubernetes環(huán)境,另外兩臺作為節(jié)點(diǎn)加入到這個kubernetes環(huán)境中;
標(biāo)準(zhǔn)化vmware鏡像是什么?
本次實(shí)戰(zhàn)要用三個ubuntu虛擬機(jī),如果都從安裝ubuntu開始顯然很費(fèi)時,所以我們只裝一次ubuntu系統(tǒng),在這個系統(tǒng)上做一些通用的設(shè)置,裝上通用的應(yīng)用,然后把這個虛擬機(jī)的文件作為標(biāo)準(zhǔn)化鏡像,復(fù)制三份,就可以啟動三個虛擬機(jī)了;
安裝操作系統(tǒng)
在ubuntu官網(wǎng)下載Ubuntu Server 16.04.3 LTS的安裝文件ubuntu-16.04.3-server-amd64.iso
;
用下載好的ubuntu-16.04.3-server-amd64.iso文件在vmware上安裝一個虛擬機(jī),我用的是VMware® Workstation 12 Player
,版本號12.5.6 build-5528349,虛擬機(jī)硬盤設(shè)置為60G,內(nèi)存2G;
遠(yuǎn)程連接到虛擬機(jī)
裝好系統(tǒng)后,用SecureCRT工具遠(yuǎn)程連接到虛擬機(jī)上,如下圖:

登錄后用su -命令切換到root賬號;
設(shè)置允許遠(yuǎn)程root賬號登錄
打開/etc/ssh/sshd_config文件,找到下面這一行:
PermitRootLogin prohibit-password
改成下面這樣:
然后執(zhí)行命令service ssh restart
重啟ssh服務(wù),以后就可以在SecureCRT上通過root賬號直接登錄虛擬機(jī)了;
更新源
root賬號登錄虛擬機(jī),打開/etc/apt/sources.list文件,將內(nèi)容全部刪除,然后增加以下內(nèi)容(阿里云的源,目前速度較快):
# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse
更新完畢后,執(zhí)行apt-get update
命令,用最新的源進(jìn)行更新;
安裝docker
安裝依賴應(yīng)用:
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
下載軟件包密鑰,并添加到本地trusted數(shù)據(jù)庫中:
curl -fsSL https://download.daocloud.io/docker/linux/ubuntu/gpg | sudo apt-key add -
添加 ppa 源:
add-apt-repository \
"deb [arch=$(dpkg --print-architecture)] https://download.daocloud.io/docker/linux/ubuntu \
$(lsb_release -cs) \
stable"
做一次更新
安裝docker
apt-get install -y -q docker-ce=17.03.2*
啟動docker
查看docker狀態(tài)
啟動成功后狀態(tài)信息如下圖:

備份鏡像文件
關(guān)閉虛擬機(jī),找到對應(yīng)的文件夾,把整個文件夾作為標(biāo)準(zhǔn)化的鏡像備份起來,后續(xù)我們安裝rancher的server和node節(jié)點(diǎn)的時候,直接復(fù)制這些文件夾然后打開就可以了;
下一章,我們將安裝rancher的server,再把node節(jié)點(diǎn)加入到server環(huán)境中,然后體驗(yàn)kubernetes;
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。