使用Rancher的RKE快速部署Kubernetes集群
本文共涉及3臺Ubuntu機器,1臺RKE部署機器(192.168.3.161),2臺Kubernetes集群機器(3.162和3.163)。
先在Windows機器上,將rke_linux-amd64從github上下載下來,重新命名為rke ,編輯好cluster.yml集群部署文件,使用putty提供的pscp命令,將文件上傳到3.161機器上。在3.161機器上,執行rke命令,將集群部署到3.162和3.163機器上。
只要環境配置正確,部署非常快,整個集群5分鐘搞定。
準備工作:
# 1、Ubuntu 16.04.3 LTS + Docker 1.12.6 系統安裝、網絡基礎設置
# 2、將普通用戶加入到Docker組。(sudo reboot重啟機器才能生效)
sudo usermod -aG docker catty
sudo reboot
# 3、啟用cgroup內存和Swap限額,修改/etc/default/grub 配置文件,修改/增加兩項:
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
# 更新grub,重啟系統後生效
sudo update-grub
sudo reboot
# 4、永久禁用交換分區,直接修改/etc/fstab文件,註釋掉swap項
sudo vi /etc/fstab
# 5、修改/etc/hosts主機名文件,設置127.0.0.1 localhost主機名
# 6、禁用SELinux,Ubuntu默認未安裝,無需設置。
# *可以先安裝selinux工具包,然後使用getenforce工具查看SELinux狀態。
sudo apt install selinux-utils
sudo getenforce
# 7、啟用ipv4轉發。Ubuntu默認已啟用,無需設置。
# 可以查看內核參數文件 /proc/sys/net/ipv4/ip_forword ,值為1,表示啟用。
# 也可以在/etc/sysctl.conf配置文件中強制指定 net.ipv4.ip_forward=1,重啟生效。
# 8、關閉ufw防火墻,Ubuntu默認未啟用,無需設置。手工關閉UFW:
sudo ufw disable
# 9、使用配置文件中的部署用戶,建立ssh單向通道,在RKE所在機器到Kubernetes集群機器,建立單向免密登錄(即通道)
[email protected]: ssh-keygen #三次回車,生成ssh公鑰和私鑰文件
[email protected]: ssh-copy-id [email protected] #將公鑰分發給162機器
[email protected]: ssh-copy-id [email protected] #將公鑰分發給163機器
# 註意:不要使用sudo ssh-copy-id ,這樣會變成root用戶登錄。
# 驗證是否可以直接免密登錄:
[email protected]: ssh 192.168.3.162
exit
[email protected]: ssh 192.168.3.163
exit
# 10、修改cluster.ym集群部署配置文件,避免使用gcr.io鏡像,可用的文件附後
安裝部署:
# 11、將rke工具下載下來,通過putty的pscp命令,拷貝到161機器的/home/catty目錄下,
# 將RKE程序和cluster.yml配置文件放到Windows機器上的putty目錄下:
pscp rke 192.168.3.161:/home/catty
pscp cluster.yml 192.168.3.161:/home/catty
# 到161的/home/catty目錄下,增加RKE文件的可執行權限,
chmod +x rke
# 一切就緒,在161機器上,執行部署命令
./rke up --config cluster.yml
# 結束。
可用的配置文件cluster.yml:
---
auth:
strategy: x509
options:
foo: bar
# supported plugins are:
# flannel
# calico
# canal
# weave
#
# If you are using calico on AWS, use the network plugin config option:
# 'cloud_provider: aws'
network:
plugin: flannel
options:
flannel_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/flannel
flannel_cni_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/flannel-cni
nodes:
- address: 192.168.3.162
user: catty
role: [controlplane, etcd]
ssh_key_path: ~/.ssh/id_rsa
- address: 192.168.3.163
user: catty
role: [worker]
ssh_key_path: ~/.ssh/id_rsa
# - address: 192.168.3.164
# user: catty
# role: [worker]
# ssh_key_path: ~/.ssh/id_rsa
services:
etcd:
image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/etcd:latest
kube-api:
image: rancher/k8s:v1.8.3-rancher2
service_cluster_ip_range: 10.233.0.0/18
pod_security_policy: false
extra_args:
v: 4
kube-controller:
image: rancher/k8s:v1.8.3-rancher2
cluster_cidr: 10.233.64.0/18
service_cluster_ip_range: 10.233.0.0/18
scheduler:
image: rancher/k8s:v1.8.3-rancher2
kubelet:
image: rancher/k8s:v1.8.3-rancher2
cluster_domain: cluster.local
cluster_dns_server: 10.233.0.3
infra_container_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/pause-amd64:3.0
command: --fail-swap-on=false
kubeproxy:
image: rancher/k8s:v1.8.3-rancher2
system_images:
alpine: alpine:latest
nginx_proxy: rancher/rke-nginx-proxy:0.1.0
cert_downloader: rancher/rke-cert-deployer:0.1.0
kubedns_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-kube-dns-amd64:1.14.5
dnsmasq_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-dnsmasq-nanny-amd64:1.14.5
kubedns_sidecar_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/k8s-dns-sidecar-amd64:1.14.5
kubedns_autoscaler_image: registry.cn-shenzhen.aliyuncs.com/rancher_cn/cluster-proportional-autoscaler-amd64:1.0.0
# all addon manifests MUST specify a namespace
addons: |-
---
apiVersion: v1
kind: Pod
metadata:
name: my-nginx
namespace: default
spec:
containers:
- name: my-nginx
image: nginx
ports:
- containerPort: 80
運行截圖:
01-執行rke命令,部署Kubernetes集群1
02-執行rke命令,部署Kubernetes集群2
03-執行rke命令,部署Kubernetes集群3
04-執行rke命令,部署Kubernetes集群4
參考鏈接:
使用Rancher的RKE部署Kubernetes要點
http://blog.csdn.net/csdn_duomaomao/article/details/79317846
RKE快速上手指南:開源的輕量級K8S安裝程序
https://www.cnrancher.com/an-introduction-to-rke/
免費視頻培訓:如何安裝使用RKE
http://www.itdks.com/liveevent/detail/8343
RKE 簡介
https://github.com/rancher/rke
RKE工具下載頁面
https://github.com/rancher/rke/releases/
RKE cluster.yml 文件說明
https://github.com/rancher/rke/blob/master/cluster.yml
使用Rancher的RKE快速部署Kubernetes集群