ps 过程中可能有点缺漏,因为后补有的,查History 可能有些遗漏,公供参考
服务器安装
-
先安装三台centos ,我安装的是centos 7.9 版本
-
分别对三台服务器进行命名
hostname k8s-master bash hostname k8s-node1 bash hostname k8s-node2 bash
Docker 安装
yum install docker systemctl start docker systemctl enable docker
导入证书
rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
配置host (master 操作)
192.168.2.161 k8s-master 192.168.2.211 k8s-node1 192.168.2.125 k8s-node2
同步配置(master 操作)
ssh-keygen ssh-copy-id -i root@k8s-node1 ssh-copy-id -i root@k8s-node2 #同步hosts 文件 scp /etc/hosts root@k8s-node1:/etc scp /etc/hosts root@k8s-node2:/etc
防火墙等配置(所有服务器都要)
swapoff –a systemctl stop firewalld && systemctl disable firewalld setenforce 0 sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config vi /etc/fstab #将分区类型为swap的一行注释掉 /dev/mapper/centos-swap swap yum install epel-release -y
将桥接的IPv4流量传递到iptables的链(master 操作)
vim /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 sysctl --system
配置k8s仓库
vim /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
master 上安装k8s
# 指定版本,以防止版本差异问题 yum install -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.0 systemctl enable kubelet.service kubeadm init \ --apiserver-advertise-address=192.168.2.161 \ --image-repository registry.aliyuncs.com/google_containers \ --kubernetes-version v1.20.0 \ --service-cidr=10.96.0.0/12 \ --pod-network-cidr=10.244.0.0/16 \ --ignore-preflight-errors=all
初始化安装后生成join 代码
kubeadm join 192.168.2.161:6443 --token 1qcuuj.z66au8xyztjx58m3 --discovery-token-ca-cert-hash sha256:9cd5c251200e193e8c7ded71ae74e6381a0f64dc5e0bcc401591d70e8c67d1df
其他节点安装k8s
yum install -y kubelet-1.20.0 kubeadm-1.20.0 kubectl-1.20.0 systemctl enable kubelet.service # 执行join 代码,加入到集群中 kubeadm join 192.168.2.161:6443 --token 1qcuuj.z66au8xyztjx58m3 --discovery-token-ca-cert-hash sha256:9cd5c251200e193e8c7ded71ae74e6381a0f64dc5e0bcc401591d70e8c67d1df
卸载k8s
如果安装过程中,有什么问题,可以卸载重来
sudo yum remove -y kubelet kubeadm kubectl kubeadm reset -f yum erase -y kubelet kubectl kubeadm kubernetes-cni modprobe -r ipip lsmod rm -rf ~/.kube/ rm -rf /etc/kubernetes/ rm -rf /etc/systemd/system/kubelet.service.d rm -rf /etc/systemd/system/kubelet.service rm -rf /usr/bin/kube* rm -rf /etc/cni rm -rf /opt/cni rm -rf /var/lib/etcd rm -rf /var/etcd