一、环境准备
两台服务器:
1、master
2、worker-node
3、关闭防火墙:
systemctl stop firewalld
systemctl disable firewalld
4、关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
5、关闭swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
6、服务器规划
cat > /etc/hosts << EOF
10.10.10.112 k8s-master
10.10.10.113 k8s-node
EOF
7、主机名称配置:
hostnamectl set-hostname k8s-master
8、时间同步配置
yum install -y ntpdate
ntpdate time.windows.com
9、开启流量转发
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
二、安装
1、docker容器额安装
yum install -y yum-utils
安装配置 国内推荐使用阿里云
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
docker的安装
sudo yum install docker-ce-20.10.14 docker-ce-cli-20.10.14 containerd.io docker-compose-plugin
启动docker
systemctl start docker
sudo systemctl enable docker
三、k8s的安装
1、k8s源配置
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[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
EOF
2、安装kubeadm,kubelet和kubectl[所有节点]
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
systemctl enable kubelet
3、在master节点使用kubeadm安装初始化集群
kubeadm init \
--apiserver-advertise-address=<MASTER_NODE_IP> \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
3、安装网络插件 flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
或者安装:
kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
4、加入主节点
5、加入工作节点