sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config && systemctl stop firewalld.service && systemctl disable firewalld
设置hosts
cat <
172.16.1.240 c1-k1
172.16.1.241 c1-k2
172.16.1.242 c1-k3
172.16.1.243 c1-k4
172.16.1.244 c1-k5
EOF
关闭swapoff
swapoff -a ; sed -i ‘/swap/d‘ /etc/fstab
docker安装:
step 1: 安装必要的一些系统工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
Step 2: 添加软件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Step 3
sudo sed -i ‘s+download.docker.com+mirrors.aliyun.com/docker-ce+‘ /etc/yum.repos.d/docker-ce.repo
Step 4: 更新并安装Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
Step 4: 开启Docker服务
systemctl restart docker
setp 5: 开机启动
systemctl enable docker --now
配置加速器:
配置这个只是为了获取镜像更快一些罢了
直接复制下面命令执行即可
cat > /etc/docker/daemon.json <<EOF
{
"registry-mirrors": ["https://frz7i079.mirror.aliyuncs.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
设置内核参数
由于网桥工作于数据链路层,在iptables没有开启bridge-nf时,数据会直接经过网桥转发,结果就是对forward的设置失效。
cat <
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
EOF
安装kubernetes
查看可用版本
yum list --showduplicates kubeadm --disableexcludes=kubernetes
配置k8s 阿里云镜像源
cat <
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1
gpgcheck=1
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
安装
yum install -y kubelet kubeadm kubectl
启动
systemctl enable kubelet --now && systemctl start kubelet
手动安装初始化环境
(命令记录不执行):删除所有docker images:docker rmi -f $(docker images -qa)
docker pull registry.aliyuncs.com/google_containers/coredns:1.8.4
docker tag registry.aliyuncs.com/google_containers/coredns:1.8.4 registry.aliyuncs.com/google_containers/coredns:v1.8.4
删除:docker rmi registry.aliyuncs.com/google_containers/coredns:1.8.4
kubeadm config images pull --image-repository=registry.aliyuncs.com/google_containers
kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.22.0 --pod-network-cidr=10.244.0.0/16
kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.22.0 --control-plane-endpoint c1-k1 --apiserver-advertise-address 172.16.1.240 --pod-network-cidr 10.244.0.0/16
安装POD网络插件
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
查看kubelet状态:
[root@c1-k1 ~]# kubectl get nodes
NAME STATUS ROLES AGE VERSION
c1-k1 Ready control-plane,master 26m v1.22.0
让其他节点加入集群
通过kubeadm初始化后,都会提供node加入的token,查看token:
[root@c1-k1 ~]# kubeadm token create --print-join-command
kubeadm join c1-k1:6443 --token tg7aob.f7ydb2h7vc7hxr6a --discovery-token-ca-cert-hash sha256:522c4ccc3da6c00c87d845cf8966b79f3f10631cc592fa8cf95adfbece7257ac
**默认token的有效期为24小时,当过期之后,该token就不可用了。