K8S搭建教程及部署脚本

部署环境:

主机名 IP地址 系统OS 内核
master 10.5.1.10 CentOS7 Linux master 3.10.0-1062
node1 10.5.1.11 CentOS7 Linux master 3.10.0-1062
etcd/node2 10.5.1.12 CentOS7 Linux master 3.10.0-1062

1:配置安装前配置

1.1:SELINUX配置

首先获取selinux的状态

[root@localhost ~]# sestatus

 可以看到当前的状态是启用的,此状态更改有两种方式:

1:临时关闭

[root@localhost ~]# setenforce 0  #临时关闭

2:永久关闭(修改配置文件)

selinux配置文件涉及到两个,如下

/etc/selinux/config 
/etc/sysconfig/selinux 

用vi命令分别修改这两个配置文件的SELINUX参数为disabled

SELINUX=disabled

修改完成如下

[root@localhost ~]# vi /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX=disabled
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

配置文件修改之后需要重启系统才能生效,但是可以先使用相关指令临时关闭,无需浪费时间,至此,SELINUX配置完成

1.2:防火墙配置

[root@localhost ~]# systemctl disable firewalld #禁止防火墙开机自启
[root@localhost ~]# systemctl stop firewalld #关闭防火墙

关闭之后,查看服务状态

[root@localhost ~]# systemctl status firewalld #查看防火墙当前运行状态

 可以看到当前状态为dead #不活跃的,所以防火墙配置完成

 

1.3:关闭swap

 

[root@localhost ~]# swapoff -a  #临时关闭swap

[root@localhost ~]# cat /etc/fstab #查看系统挂载

 可以看到,当前的分区挂载是存在有swap的,关闭的方法很简单,在swap这一行前面加入一个:#

 至此,swap配置完成

1.4:配置K8S虚拟网络路由转发

[root@localhost ~]# sudo echo -e "net.bridge-nf-call-ip6tables = 1\nnet.bridge-nf-call-iptables = 1" > /etc/sysctl.d/k8s.conf

上面的命令就是将下面两个参数写入k8s.conf配置文件,当文件存在时清除原数据,不存在则创建,创建结果如下:

 参数如下:

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

 至此,路由转发配置完成

猜你喜欢

转载自www.cnblogs.com/liuyi778/p/12109034.html
今日推荐