一、基础环境准备:
1、网络
2、主机名
3、绑定hosts
4、常用软件
5、防火墙
6、禁用selinux
7、关闭交换分区
swapoff -a
sed -i '/swap/s/^/#/' /etc/fstab
二、部署Docker环境(三台主机)
1.yum install -y yum-utils device-mapper-persistent-data lvm2
2.yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3.yum makecache fast
4.yum -y install docker-ce-19.03.15 docker-ce-cli-19.03.15
5.systemctl start docker
6.systemctl enable docker
7.国内加速
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://hub-mirror.c.163.com"
]
}
8.内核优化
cat << EOF >> /etc/sysctl.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
9.sysctl -p
三、部署Kubernetns集群(三台主机)
1.YUM源
cat <<EOF >> /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=0
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
2.安装kubelet、kubeadm和kubectl
yum install -y --nogpgcheck kubelet-1.17.4 kubeadm-1.17.4 kubectl-1.17.4
systemctl enable kubelet
3.生成初始化配置文件(一台主机)
kubeadm config print init-defaults > init-config.yaml
4.修改配置文件
vim init-config.yaml
advertiseAddress: 192.168.107.136
name: k8s-master
dataDir: /var/lib/etcd
imageRepository: registry.aliyuncs.com/google_containers
podSubnet: 10.244.0.0/16
5.拉取所需镜像
kubeadm config images list --config init-config.yaml
kubeadm config images pull --config=init-config.yaml
6.初始化k8s-master
kubeadm init --config=init-config.yaml
注释:报错解决方法:
kubeadm reset (三个节点都要修改)
7.并修改docker的配置文件(三个节点都要修改)
vim /etc/docker/daemon.json
{
"registry-mirrors": [
"https://hub-mirror.c.163.com"
],
"exec-opts": ["native.cgroupdriver=systemd"] //添加
}
systemctl restart docker
8.根据提示复制配置文件到用户的home目录,并将node节点加入集群
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown (id -u):(id -g) $HOME/.kube/config
9.node 节点加入集群(node1 node2分别执行)
kubeadm join 192.168.107.136:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:212ecd885037b675824f952f16789eb5acbabd2f8968f087e098e97a0011a9f0
在k8s-master查看节点
kubectl get nodes
10.安装flannel网络(MASTER)
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
注释:如无法下载,提供的yml文件文件内 quay.io 国内无法访问,替换为七牛地址
sed -i 's@quay.io@quay-mirror.qiniu.com@g' kube-flannel.yml
11.运行开启flannel网络Pod
kubectl apply -f kube-flannel.yml
kubectl get nodes -o wide