在所有的机器上:

1.关闭selinux:

sed -i '/^SELINUX/s/enforcing/disabled/' /etc/selinux/config

setenforce 0

2.设置IPV4转发

cat >> /etc/sysctl.conf << END

net.ipv4.ip_forward = 1

net.bridge.bridge-nf-call-ip6tables = 1

net.bridge.bridge-nf-call-iptables = 1

END

 

#执行如下命令生效

sysctl -p

若出现下面报错:
 

[root@k8s-master ~]# sysctl -p

net.ipv4.ip_forward = 1

sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory

sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory

执行下面的操作:

modprobe br_netfilter

sysctl -p

3.设置防火墙策略:

关闭防火墙:

systemctl stop firewalld

关闭swap:

sed -i '/swap/s/^/#/g' /etc/fstab

mount -a

4.启用cgroup
修改配置文件/etc/default/grub,启用cgroup内存限额功能,配置两个参数:

vim /etc/default/grub
##在文件中加入下面语句

GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"

GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"

运行下面命令使得上面设置生效

grub2-mkconfig -o /boot/grub2/grub.cfg

5.在各个节点创建docker_user用户将docker_user用户加入到docker组,因为rke要使用docker组用户对于/var/run/docker.sock对docker进行远程操作。

useradd docker_user

usermod -aG docker docker_user

6.在主节点上创建rke用户:(Centos系列的系统的root用户不能用来起rke。)

useradd rke

6.设置rke服务器到各个节点的ssh免密:

在三个节点上创建ssh用户:

user add docker_user

ssh-keygen

ssh-copy-id -i docker_user@rke

ssh-copy-id -i docker_user@rkenode1

ssh-copy-id -i docker_user@rkenode2

7.下载rke包:https://github.com/rancher/rke/releases

8.编辑cluster.yml文件,文件中写入:(需要根据自己的情况对文件进行编辑)

nodes: 

  - address: 10.0.32.175

    user: docker_user

    role: [controlplane,etcd]

  - address: 10.0.32.177 

    user: docker_user

    ssh_key_path: ~/.ssh/id_rsa

    role: [worker]

  - address: 10.0.32.178

    ssh_key_path: ~/.ssh/id_rsa

    user: docker_user

    role: [worker]

services:

   etcd:

     image: quay.io/coreos/etcd:latest 

   kube-api:

     pod_security_policy: false

     image: rancher/k8s:v1.8.5-rancher4    

     service_cluster_ip_range: 10.233.0.0/18

   kube-controller:

     cluster_cidr: 10.233.64.0/18 

     image: rancher/k8s:v1.8.5-rancher4 

   scheduler:

     image: rancher/k8s:v1.8.5-rancher4 

   kubelet:

     cluster_domain: cluster.local

     cluster_dns_server: 10.233.0.3

     infra_container_image: gcr.io/google_containers/pause-amd64:3.0    

     image: rancher/k8s:v1.8.5-rancher4 

    kubeproxy:

     image: rancher/k8s:v1.8.5-rancher4

network:

  plugin: flannel

system_images:

  flannel: rancher/coreos-flannel:v0.9.1 

  kubedns: rancher/k8s-dns-kube-dns-amd64:1.14.5 

  dnsmasq: rancher/k8s-dns-dnsmasq-nanny-amd64:1.14.5 

  kubedns_sidecar: rancher/k8s-dns-sidecar-amd64:1.14.5 

  kubedns_autoscaler: rancher/cluster-proportional-autoscaler-amd64:1.0.0 

  dashboard: k8s.gcr.io/kubernetes-dashboard-amd64:v1.8.3

authentication:

  strategy: x509

下面的镜像需要科学上网进行操作,如果没有这个包集群的网络组件起不来

infra_container_image: gcr.io/google_containers/pause-amd64:3.0

9. ./rke up(使用rke用户)

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐