kubeadm搭建k8s集群

一、k8s架构


kubeadm搭建k8s集群

二、环境准备


  1. 关闭防火墙
[root@master ~]# systemctl stop firewalld
[root@master ~]# systemctl disable firewalld
  1. 关闭selinux
[root@master ~]# sed -i 's/enforcing/disabled/' /etc/selinux/config
  1. 关闭swap
第一步 关闭swap分区:
swapoff -a

第二步修改配置文件 - /etc/fstab
删除swap相关行 /mnt/swap swap swap defaults 0 0 这一行或者注释掉这一行
  1. 添加hosts
[root@master ~]# cat >> /etc/hosts << EOF
> 192.168.31.60 master
> 192.168.31.61 slave-1
> 192.168.31.62 slave-2
> EOF
  1. 将桥接的IPv4流量传递到iptables的链
[root@master ~]# cat > /etc/sysctl.d/k8s.conf << EOF
> net.bridge.bridge-nf-call-ip6tables = 1
> net.bridge.bridge-nf-call-iptables = 1
> EOF
[root@master ~]# sysctl --system
  1. 时间同步
[root@master ~]# yum install ntpdate -y
[root@master ~]# ntpdate time.windows.com

三、安装docker

$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce
$ systemctl enable docker && systemctl start docker

配置镜像加速器

$ cat > /etc/docker/daemon.json << EOF
{
  "registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
$ systemctl restart docker
$ docker info

三、master安装kubeadm,kubelet和kubectl

  1. 添加yum源
[root@master ~]# 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
  1. 安装
[root@master ~]# yum install -y kubelet-1.19.0 kubeadm-1.19.0 kubectl-1.19.0
[root@master ~]# systemctl enable kubelet

四、部署master

  1. master上执行
[root@master ~]# kubeadm init \
>   --apiserver-advertise-address=192.168.2.60 \
>   --image-repository registry.aliyuncs.com/google_containers \
>   --kubernetes-version v1.19.0 \
>   --service-cidr=10.96.0.0/12 \
>   --pod-network-cidr=10.244.0.0/16 \
>   --ignore-preflight-errors=all
  1. 拷贝kubectl连接k8s使用的认证文件到默认路径

上一篇:docker-compose.yml mysql


下一篇:背水一战 Windows 10 (8) - 控件 UI: StateTrigger