安装kubenetes有5种部署工具,分别是kubeadm、kops、KRIB、Kubespray。本实验采用的是kubeadm部署工具。如有想了解其他部署工具,请点击这里
环境说明
角色/主机名 |
系统版本 |
CPU |
MEM |
IP |
master |
CentOS 7.7 |
4 |
4 |
192.168.100.80 |
node01 |
CentOS 7.7 |
4 |
4 |
192.168.100.81 |
node02 |
CentOS 7.7 |
4 |
4 |
192.168.100.82 |
注:系统版本要求7.4+
环境准备
检查网络(三个主机)
ping baidu.com
检查端口
Control-plane node
Protocol |
Port Range |
Purpose |
TCP |
6443 |
Kubernetes API server |
TCP |
2379-2380 |
etcd server client API |
TCP |
10250 |
Kubelet API |
TCP |
10251 |
kube-scheduler |
TCP |
10252 |
kube-controller-manager |
Worker node(s)
Protocol |
Port Range |
Purpose |
TCP | 10250 | Kubelet API |
TCP | 30000-32767 | NodePort Services** |
设置主机名映射(三个主机)
vim /etc/hosts
192.168.100.80 master
192.168.100.81 node01
192.168.100.82 node02
关闭防火墙和selinux(三个主机)
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -ri 's/(^SELINUX=).*/1disabled/' /etc/selinux/config
配置docker和kubernetes源(三个节点)
yum install wget –y
cd /etc/yum.repos.d && wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo && cd -
cat >> /etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=Aliyun-kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
EOF
下载docker(三个主机)
yum install docker-ce-18.06.3.ce-3.el7 -y
设置docker加速器和Cgroup drivers
mkdir /etc/docker
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://registry.docker-cn.com"]
}
启动docker并设置开机自启动(三个主机)
systemctl start docker.service
systemctl enable docker.service
查看docker版本
docker --version
安装kubeadm, kubelet and kubectl(master)
yum install kubelet kubeadm kubectl –y
安装kubeadm,kubelet(nodes)
yum install kubelet kubeadm -y
设置Cgroup drivers和交换分区(三个主机)
vim /etc/sysconfig/kubelet
KUBELET_EXTRA_ARGS="--fail-swap-on=false --cgroup-driver=systemd"
说明:
--fail-swap-on:关闭交换分区,kubernetes不允许开启交换分区
--cgroup-driver:指定Cgroup drivers用谁
设置kubectl开机自启动(三个主机)
systemctl enable --now kubelet
设置必须的sysctl参数,让这些参数重启后仍然生效
cat > /etc/sysctl.d/99-kubernetes-cri.conf <<EOF
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
sysctl --system
使用kubernetes创建单个控制平面集群(master)
kubeadm init --kubernetes-version=v1.16.3 --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
说明:
--kubernetes-version:为控制平面选择特定的Kubernetes版本。
--image-repository :指定镜像部署的地址,原地址https://k8s.gcr.io不可用
--pod-network-cidr:pod的网络地址
--service-cidr:server的网络地址
是输出一段字符保持好,后面需要用到
kubeadm join 192.168.100.80:6443 --token oc5h3c.bs1gikpbvgzbc86y
--discovery-token-ca-cert-hash sha256:e0e176b55cb5fbf1238351e8d009bf8cc1f9a69a283a47c9ec5766564657d6a0