CentOS 7 部署 K8S
基础:
三台2核2G虚拟机
CentOS 7
192.168.5.101
192.168.5.102
192.168.5.103
一、基础配置(所有节点都关闭)
1、关闭防火墙、selinux、SWAP
systemctl stop firewalld && systemctl disable firewalld && setenforce 0
sed -i 's/^SELINUX=.*/SELINUX=disabled/' /etc/selinux/config
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
2、内核开启网络支持
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p /etc/sysctl.conf
3、设置 /etc/hosts
192.168.5.101 node101
192.168.5.102 node102
192.168.5.103 node103
二、Docker部署
1、安装依赖与镜像
yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
2、安装软件包
yum install -y docker-ce docker-ce-cli containerd.io
#默认安装最新版本,可以指定安装版本
#查看可以安装哪些版本
yum list docker-ce --showduplicates|sort -r
yum install -y docker-ce-18.09.9-3.el7 docker-ce-cli-18.09.9-3.el7 containerd.io
3、启动Docker
systemctl enable docker && systemctl start docker
4、修改Cgroup Driver
cat > /etc/docker/daemon.json <<EOF
{ "exec-opts": ["native.cgroupdriver=systemd"] }
EOF
systemctl restart docker
注意:Docker默认驱动是cgroupfs,由于k8s推荐是systemd,需要修改
三、安装kubeadm部署K8S集群
#k8s阿里云镜像
cat <<EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF
#安装指定版本
yum list kubelet --showduplicates | sort -r
yum install -y kubelet-1.18.20 kubeadm-1.18.20 kubectl-1.18.20
systemctl enable kubelet && systemctl start kubelet
#初始化Master节点
cat <<EOF > kubeadm.yaml apiVersion: kubeadm.k8s.io/v1beta2 kind: InitConfiguration nodeRegistration: KubeletExtraArgs: cgroup-driver: "systemd" --- apiVersion: kubeadm.k8s.io/v1beta2 kind: ClusterConfiguration kubernetesVersion: v1.18.20 clusterName: "kubernetes" controllerManager: extraArgs: horizontal-pod-autoscaler-sync-period: "10s" node-monitor-grace-period: "10s" apiServer: extraArgs: runtime-config: "api/all=true" networking: podSubnet: "172.36.0.0/16" serviceSubnet: 10.96.0.0/12 imageRepository: k8s.gcr.io scheduler: {} EOF