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

登錄后用su -命令切換到root賬號;
設置允許遠程root賬號登錄
打開/etc/ssh/sshd_config文件,找到下面這一行:
PermitRootLogin prohibit-password
改成下面這樣:
然后執行命令service ssh restart
重啟ssh服務,以后就可以在SecureCRT上通過root賬號直接登錄虛擬機了;
更新源
root賬號登錄虛擬機,打開/etc/apt/sources.list文件,將內容全部刪除,然后增加以下內容(阿里云的源,目前速度較快):
# 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
更新完畢后,執行apt-get update
命令,用最新的源進行更新;
安裝docker
安裝依賴應用:
apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
下載軟件包密鑰,并添加到本地trusted數據庫中:
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狀態
啟動成功后狀態信息如下圖:

備份鏡像文件
關閉虛擬機,找到對應的文件夾,把整個文件夾作為標準化的鏡像備份起來,后續我們安裝rancher的server和node節點的時候,直接復制這些文件夾然后打開就可以了;
下一章,我們將安裝rancher的server,再把node節點加入到server環境中,然后體驗kubernetes;
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。