先安装docker
yum install docker-ce (社区版)
配置加速云和cgroupdriver
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://8xh9s4md.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
"registry-mirrors": ["https://8xh9s4md.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
1
、关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
2
、关闭
selinux
sed
‐
i
's/enforcing/disabled/'
/
etc
/
selinux
/
config
永久关闭
setenforce
0
临时关闭
3
、关闭
swap
swapoff
‐
a
临时关闭
vim
/
etc
/
fstab
永久关闭
注释这行
#
/
dev
/
mapper
/
centos
‐
swap swap swap defaults
0 0
systemctl reboot
重启生效
free
‐
m
查看下
swap
交换区
4
、给三台机器分别设置主机名
hostnamectl
set
‐
hostname
<
hostname
>
k8s
_
master、k8s
_
node01、k8s
_
node02
5
、
添加
hosts
192.168.93.128 k8s_master
192.168.93.131 k8s_node01
192.168.93.132 k8s_node02
192.168.93.131 k8s_node01
192.168.93.132 k8s_node02
6
、vim /etc/sysctl.d/k8s.conf
net
.
bridge
.
bridge
‐
nf
‐
call
‐
ip6tables
=
1
net
.
bridge
.
bridge
‐
nf
‐
call
‐
iptables
=
1
sysctl
‐‐
system
生效
7
、设置时间同步
yum install chrony
8
、添加k8s 源
vim /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
8
、主从节点安装kubelet(服务)、kubectl、kubeadm (最好选相同版本)
yum install kubelet kubectl kubeadm
设置开机启动(这里用systemctl start kubelet是启动不了的因为还没初始化,主节点初始化后启动,从节点加入集群后自动启动)
systemctl enable kubelet
9
、主节点初始化(下面的apiserver-advertise-address改成自己主节点IP)
kubeadm init --apiserver-advertise-address=192.168.93.128 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.18.0 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16
10
、根据上图主节点执行命令后,配置主节点Pod网络插件
kubectl apply
‐
f 文件名
配置文件放在下面链接
链接:https://pan.baidu.com/s/1r2EmKWSqyFn2WaWUwmHEPQ
提取码:8dmu
提取码:8dmu
执行上图从节点加入集群后可在主节点看下集群信息
kubectl get nodes
至此安装完成
小提示:如果kubeadm join 后面的参数忘记了用这条命令查看
kubeadm token create --print-join-command