使用RKE部署K8S ========================== 主机准备 -------- .. warning:: 由于在安装k8s时,有些镜像因被墙,安装不了,请提前配置旁路由,并在路由上翻墙。 主机规划 ^^^^^^^^ ======== ============= ======================== hostname ip 用途 ======== ============= ======================== master01 192.168.10.10 controlplane,rancher,rke master02 192.168.10.11 controlplane worker01 192.168.10.12 worker worker02 192.168.10.13 worker etcd01 192.168.10.14 etcd ======== ============= ======================== .. note:: * 所有主机的IP需要配置成静态IP,并且可用互相访问。 * cpu和内存的比例: 1:2或1:4 配置hostname ^^^^^^^^^^^^^^^^ .. code-block:: bash $ sudo hostnamectl set-hostname xxx 配置hosts ^^^^^^^^^^^^^^^^ .. code-block:: bash $ sudo vim /etc/hosts 在该文件中添加主机到IP的映射: .. code-block:: text master01 192.168.10.10 master02 192.168.10.11 worker01 192.168.10.12 worker02 192.168.10.13 etcd01 192.168.10.14 禁用交换 ^^^^^^^^ 临时禁用: .. code-block:: bash $ sudo swapoff -a 永久禁用: .. code-block:: bash $ sudo vim /etc/fstab 把type为swap的行的记录注释掉,重启即可。 配置ip_forward及过滤机制 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: bash $ sudo vim /etc/sysctl.conf sysctl.conf文件用于配置 Linux 内核参数。通过修改这个文件,可以动态地调整内核的运行参数,不需要重新启动系统。 追加下列内容: .. code-block:: linux-config # 启用/禁用IP转发 net.ipv4.ip_forward=1 # 用于启用网桥的IPv6表过滤功能,这个参数设置为1时,IPv6流量通过网桥时会调用IPv6表过滤规则。 net.bridge.bridge_nf_call_ipv6tables=1 # 作用与net.bridge.bridge_nf_call_ipv6tables类似,但针对的是IPv4流量。 net.bridge.bridge_nf_call_iptables=1 .. code-block:: bash $ sudo modprobe br_netfilter .. note:: 该命令用于加载br_netfilter模块,该模块实现了网桥的netfilter过滤功能。 加载该模块后,我们就可以在网桥上应用netfilter防火墙规则,实现流量过滤和控制。 具体来说,加载 br_netfilter 模块后: - 我们可以在网桥的输入链(INPUT)和输出链(OUTPUT)应用netfilter规则,控制流入和流出网桥的流量 - 我们可以在网桥的转发链(FORWARD)应用netfilter规则,控制流经网桥的流量 - 我们可以使用iptables和ip6tables命令在网桥的三个链上添加和删除规则 - 我们可以启用 params net.bridge.bridge-nf-call-iptables 和 net.bridge.bridge-nf-call-ip6tables,在网桥上启用IPv4和IPv6的netfilter规则 所以,如果我们需要使用netfilter框架在Linux网桥上进行流量过滤和控制,就需要加载br_netfilter模块。 只有加载了这个模块,netfilter才能正确地工作在网桥环境中。 总的来说,modprobe br_netfilter 命令实现了在网桥上启用netfilter功能,让我们得以使用iptables等工具进行网桥流量管理。 关闭防火墙 ^^^^^^^^^^^^ .. code-block:: bash $ sudo systemctl stop firewalld $ sudo systemctl disable firewalld 关闭selinux ^^^^^^^^^^^^^^^^^^ .. code-block:: bash $ sudo vim /etc/selinux/config .. code-block:: text #setenforce 0 同步主机时间 ^^^^^^^^^^^^^^^^ 可用写一个crontab,定时同步时间。 .. code-block:: bash crontabl -e .. code-block:: text 0 */1 * * * ntpdate time1.aliyun.com 这里我们使用阿里云的时间同步服务器。 安装docker --------------- 安装rke ---------------