一、 基础环境

操作系统:CentOS7.6
内核版本:Linux 3.10.0-957.el7.x86_64
kubernetes:v1.13.5
docker版本:18.06.1-ce

二、 准备工作

你需要准备如下这些东西

1 rke安装包

https://github.com/rancher/rke/releases 这个链接,找你要的版本,本例为v0.2.1

2 cluster.yml文件

https://rancher.com/docs/rke/latest/en/example-yamls/ 这里有cluster.yml文件的样例

3 主机分配

IP 角色 备注
10.3.222.222 rke部署机
10.3.222.223 master1
10.3.222.224 master2
10.3.222.225 node3
10.3.222.226 node1
10.3.222.227 node2
10.3.222.224 node3

4 关闭所有主机的selinux、firewalld

# setenforce 0
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
# systemctl stop firewalld && systemctl disable firewalld

三、 部署过程

1 安装docker

# yum install -y epel-release
# yum install -y yum-utils net-tools conntrack-tools wget
# yum-config-manager \
--add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
可以查看都有哪些docker的版本
# yum list docker-ce --showduplicate
# yum install -y docker-ce-18.06.1.ce

2 添加用户

# useradd -g docker docker

3 免密登录

将10.3.222.222主机root用户的公钥添加到k8s所有节点docker用户下的authorized_keys文件中。
# echo "your key" >> /home/docker/.ssh/authorized_keys

4 rke操作

在10.3.222.222(rke部署机)上
下载rke
# wget https://github.com/rancher/rke/releases/download/v0.2.1/rke_linux-amd64
# chmod 777 rke_linux-amd64
# mv rke_linux-amd64 rke

5 cluster.yml文件

nodes:
    - address: 10.3.222.223
      user: docker
      role:
         - controlplane
         - etcd
      labels:
         ingress: 'true'
    - address: 10.3.222.224
      user: docker
      role:
         - controlplane
         - etcd
      labels:
         ingress: 'true'
    - address: 10.3.222.225
      user: docker
      role:
         - controlplane
         - etcd
      labels:
         ingress: 'true'
    - address: 10.3.222.226
      user: docker
      role:
         - worker
    - address: 10.3.222.227
      user: docker
      role:
         - worker
  - address: 10.3.222.228
    user: docker
    role:
       - worker
ingress:
   provider: none

ignore_docker_version: true

cluster_name: k8s_test

services:
    kube-api:
        service_cluster_ip_range: 10.96.0.0/16
        service_node_port_range: 30000-42767
        pod_security_policy: false
    kubelet:
        cluster_domain: cluster.local
        cluster_dns_server: 10.96.0.10
        fail_swap_on: false
        extra_args:
            max-pods: 250
            cgroup-driver: cgroupfs

    kube-controller:
        cluster_cidr: 10.244.0.0/16
        service_cluster_ip_range: 10.96.0.0/16

authentication:
    strategy: x509

authorization:
    mode: rbac
network:
    plugin: flannel

addons_include:
    - https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/v1.11/nvidia-device-plugin.yml

本例中的cluster.yml文件提供一个样例,可以根据自己实际需要在文件中添加或删除一些参数。

6 安装集群

将cluster.yml和下载的rke放到同一个目录
# ./rke up