阅读本文前默认您已经了解k8s相关知识,适用于想快速部署进行开发
1.环境准备
1.1安装虚拟机
准备三台以上Linux服务器(虚拟机) 我这里使用centos7.6作为镜像文件创建三台虚拟机
配置要求:2G以上\30G硬盘\2颗cpu核心
1.2系统初始化
以下操作没有特殊说明默认在每台服务器上都执行命令
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭 selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config
setenforce 0
关闭 swap
swapoff -a
sed -ri 's/.*swap.*/#&/' /etc/fstab
根据规划设置主机名 这里针对不同虚拟机设置不同名称
hostnamectl set-hostname <hostname>
master
node1
node2
在 master节点 添加 其它两个节点hosts
cat >> /etc/hosts << EOF
192.168.182.128 k8smaster
192.168.182.129 k8snode1
192.168.182.130 k8snode2
EOF
设置网络
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
让配置生效
sysctl --system
同步服务器时间
yum install ntpdate -y
ntpdate time.windows.com
1.3安装依赖环境
每台服务器安装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-18.06.1.ce-3.el7
systemctl enable docker && systemctl start docker
修改docker源
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
修改k8s的阿里yum源
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
安装kubeadm,kubelet和kubectl
yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
systemctl enable kubelet
2.部署k8s节点
在master节点启动相关组件 注意把对应ip改成你的master节点的ip(192.168.182.128)
kubeadm init --apiserver-advertise-address=192.168.182.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
执行完毕查看结果 会看到successfully!下边有一段脚本
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user: mkdir -pHOME/.kube sudo cp -i /etc/kubernetes/admin.confHOM**E/.kubesudoc**p−i/etc/kubernete**s/admin.con**fHOME/.kube/config sudo chown(id -u)