################## Rancher v2.1.7 + Kubernetes 1.13.4 ################html
####################### 如下爲聲明 #####################node
此文檔是在兩臺機上進行的實踐,kubernetes處於不斷開發階段linux
不能保證每一個步驟都能準確到同步開發進度,因此若是安裝部署過程當中有問題請儘可能googlenginx
按照下面步驟能獲得什麼?git
1.兩臺主機之一會做爲Rancher的server,另一臺做爲Rancher Server的node節點添加進Rancher Server,獲得安裝好的Rancher,並以Rancher UI進行呈現github
2.做爲node節點的主機會被安裝kubernetes,並以kubernetes dashboard的方式呈現docker
3.將創建一個登錄帳號登錄kubernetes dashboard 並解決kubernetes dashboard token超時的問題json
4.部署測試pod 和 container,(以nginx爲例)centos
5,認識Rancher和kubernetes,知道其長什麼樣子能作什麼工做。數組
6.此文不作生產環境使用,若是使用到生產環境,責任自負。只做爲學習Rancher和kubernetes使用,因爲時間關係,文中有錯誤的地方歡迎指正交流。
7.此文分爲三部分:
CentOS7安裝Rancher2.0並部署kubernetes (一)---部署Rancher
CentOS7安裝Rancher2.0並部署kubernetes (二)---部署kubernetes
CentOS7安裝Rancher2.0並部署kubernetes (三)---解決登陸kubernets超時和部署測試Pod和Containter[nginx爲例]
############################## 下面爲文檔正文 #####################################
setenforce 0 sudo sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config systemctl stop firewalld.service && systemctl disable firewalld.service
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime sudo echo 'LANG="en_US.UTF-8"' >> /etc/profile;source /etc/profile
[root@rancher ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@node01 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
[root@rancher ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.166 rancher 192.168.0.167 node01 --- [root@node01 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.0.166 rancher 192.168.0.167 node01
driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync allow 192.168.0.167/16 local stratum 8 logdir /var/log/chrony
server rancher iburst driftfile /var/lib/chrony/drift makestep 1.0 3 rtcsync allow 192.168.0.166/24 local stratum 9 logdir /var/log/chrony
[root@rancher ~]# chronyc sources -v 210 Number of sources = 0 .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current synced, '+' = combined , '-' = not combined, | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample ===============================================================================
[root@node01 ~]# chronyc sources -v 210 Number of sources = 1 .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current synced, '+' = combined , '-' = not combined, | / '?' = unreachable, 'x' = time may be in error, '~' = time too variable. || .- xxxx [ yyyy ] +/- zzzz || Reachability register (octal) -. | xxxx = adjusted offset, || Log2(Polling interval) --. | | yyyy = measured offset, || \ | | zzzz = estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^* rancher 8 10 377 592 -190us[ -192us] +/- 496us
cat >> /etc/sysctl.conf<<EOF net.ipv4.ip_forward=1 net.bridge.bridge-nf-call-iptables=1 net.ipv4.neigh.default.gc_thresh1=4096 net.ipv4.neigh.default.gc_thresh2=6144 net.ipv4.neigh.default.gc_thresh3=8192 EOF
sysctl -p
[root@rancher ~]# cat add_mod.sh #!/bin/sh mods=( br_netfilter ip6_udp_tunnel ip_set ip_set_hash_ip ip_set_hash_net iptable_filter iptable_nat iptable_mangle iptable_raw nf_conntrack_netlink nf_conntrack nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat nf_nat_ipv4 nf_nat_masquerade_ipv4 nfnetlink udp_tunnel VETH VXLAN x_tables xt_addrtype xt_conntrack xt_comment xt_mark xt_multiport xt_nat xt_recent xt_set xt_statistic xt_tcpudp ) for mod in ${mods[@]};do modprobe $mod lsmod |grep $mod done
chmod a+x add_mod.sh ./add_mod.sh
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
cat > /etc/yum.repos.d/CentOS-Base.repo << EOF [base] name=CentOS-$releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 EOF
sudo yum remove docker \ docker-client \ docker-client-latest \ docker-common \ docker-latest \ docker-latest-logrotate \ docker-logrotate \ docker-selinux \ docker-engine-selinux \ docker-engine \ container*
export docker_version=17.03.2
sudo yum update -y sudo yum install -y yum-utils device-mapper-persistent-data lvm2 bash-completion
sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sudo yum makecache all version=$(yum list docker-ce.x86_64 --showduplicates | sort -r|grep ${docker_version}|awk '{print $2}') sudo yum -y install --setopt=obsoletes=0 docker-ce-${version} docker-ce-selinux-${version}# 若是已經安裝高版本Docker,可進行降級安裝(可選) yum downgrade --setopt=obsoletes=0 -y docker-ce-${version} docker-ce-selinux-${version}# 把當前用戶加入docker組 sudo usermod -aG docker `<new_user>`# 設置開機啓動 sudo systemctl enable docker
[root@rancher ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/"], "max-concurrent-downloads": 3, "max-concurrent-uploads": 5, "storage-driver": "overlay2", "storage-opts": ["overlay2.override_kernel_check=true"], "log-driver": "json-file", "log-opts": { "max-size": "100m", "max-file": "3" } }
[root@node01 ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/"], "max-concurrent-downloads": 3, "max-concurrent-uploads": 5, "storage-driver": "overlay2", "storage-opts": ["overlay2.override_kernel_check=true"], "log-driver": "json-file", "log-opts": { "max-size": "100m", "max-file": "3" } }
"max-concurrent-downloads": 3, "max-concurrent-uploads": 5
{ "registry-mirrors": ["https://7bezldxe.mirror.aliyuncs.com/","https://IP:PORT/"] }
{ "insecure-registries": ["192.168.1.100","IP:PORT"] }
{ "storage-driver": "overlay2", "storage-opts": ["overlay2.override_kernel_check=true"] }
{ "log-driver": "json-file", "log-opts": { "max-size": "100m", "max-file": "3" } }
[root@rancher ~]# docker version Client: Version: 17.03.2-ce API version: 1.27 Go version: go1.7.5 Git commit: f5ec1e2 Built: Tue Jun 27 02:21:36 2017 OS/Arch: linux/amd64 Server: Version: 17.03.2-ce API version: 1.27 (minimum version 1.12) Go version: go1.7.5 Git commit: f5ec1e2 Built: Tue Jun 27 02:21:36 2017 OS/Arch: linux/amd64 Experimental: false --- [root@node01 ~]# cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core) [root@node01 ~]# docker version Client: Version: 17.03.2-ce API version: 1.27 Go version: go1.7.5 Git commit: f5ec1e2 Built: Tue Jun 27 02:21:36 2017 OS/Arch: linux/amd64 Server: Version: 17.03.2-ce API version: 1.27 (minimum version 1.12) Go version: go1.7.5 Git commit: f5ec1e2 Built: Tue Jun 27 02:21:36 2017 OS/Arch: linux/amd64 Experimental: false
CentOS7安裝Rancher2.0並部署kubernetes (一)---部署Rancher
CentOS7安裝Rancher2.0並部署kubernetes (二)---部署kubernetes
CentOS7安裝Rancher2.0並部署kubernetes (三)---解決登陸kubernets超時和部署測試Pod和Containter[nginx爲例]