kubeadm安装k8s集群

1.准备
1.1 系统准备:
cat /etc/hosts 
10.211.55.3 node1 
10.211.55.5 node2

关闭防火墙:

systemctl stop firewalld
systemctl disable firewalld

禁用SELINUX:

setenforce 0 
vi /etc/selinux/config
SELINUX=disabled 

创建/etc/sysctl.d/k8s.conf文件,添加如下内容:

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

执行命令使修改生效。

modprobe br_netfilter 
sysctl -p /etc/sysctl.d/k8s.conf 
1.2kube-proxy开启ipvs的前置条件

由于ipvs已经加入到了内核的主干,所以为kube-proxy开启ipvs的前提需要加载以下的内核模块:

ip_vs 
ip_vs_rr 
ip_vs_wrr 
ip_vs_sh 
nf_conntrack_ipv4 

在所有的Kubernetes节点node1和node2上执行以下脚本:

cat > /etc/sysconfig/modules/ipvs.modules <<EOF 
#!/bin/bash 
modprobe -- ip_vs 
modprobe -- ip_vs_rr 
modprobe -- ip_vs_wrr 
modprobe -- ip_vs_sh 
modprobe -- nf_conntrack_ipv4 
EOF 
chmod 755 /etc/sysconfig/modules/ipvs.modules && bash /etc/sysconfig/modules/ipvs.modules && lsmod | grep -e ip_vs -e nf_conntrack_ipv4 

上面脚本创建了的/etc/sysconfig/modules/ipvs.modules文件,保证在节点重启后能自动加载所需模块。 使用

lsmod | grep -e ip_vs -e nf_conntrack_ipv4命令查看是否已经正确加载所需的内核模块。

接下来还需要确保各个节点上已经安装了ipset软件包yum install ipset。 为了便于查看ipvs的代理规则,最好安装一下管理工具ipvsadm yum install ipvsadm

1.3安装Docker

Kubernetes从1.6开始使用CRI(Container Runtime Interface)容器运行时接口。默认的容器运行时仍然是Docker,使用的是kubelet中内置dockershim CRI实现。

安装docker的yum源:

yum install -y yum-utils device-mapper-persistent-data lvm2 
yum-config-manager \     
--add-repo \     
https://download.docker.com/linux/centos/docker-ce.repo 

查看最新的Docker版本:

yum list docker-ce.x86_64  --showduplicates |sort -r

docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable 
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable 
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable 

Kubernetes 1.12已经针对Docker的1.11.1, 1.12.1, 1.13.1, 17.03, 17.06, 17.09, 18.06等版本做了验证,需要注意Kubernetes 1.12最低支持的Docker版本是1.11.1。Kubernetes 1.13对Docker的版本依赖方面没有变化。 我们这里在各节点安装docker的18.06.1版本。

yum makecache fast 

yum install -y --setopt=obsoletes=0 \   
docker-ce-18.06.1.ce-3.el7  

systemctl start docker 
systemctl enable docker 

确认一下iptables filter表中FOWARD链的默认策略(pllicy)为ACCEPT。

iptables -nvL 
Chain INPUT (policy ACCEPT 263 packets, 19209 bytes)  
pkts bytes target     prot opt in     out     source               destination  
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) 
pkts bytes target     prot opt in     out     source               destination
0     0 DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0     
0     0 DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0     0     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED     
0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0    
0     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0    
0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0 

Docker从1.13版本开始调整了默认的防火墙规则,禁用了iptables filter表中FOWARD链,这样会引起Kubernetes集群中跨Node的Pod无法通信。但这里通过安装docker 1806,发现默认策略又改回了ACCEPT,这个不知道是从哪个版本改回的,因为我们线上版本使用的1706还是需要手动调整这个策略的。

2.使用kubeadm部署Kubernetes
2.1 安装kubeadm和kubelet

下面在各节点安

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值