1.关闭防火墙 $ systemctl stop firewalld
备注:必须关闭
2.关闭selinux $ setenforce 0
3.关闭swap $ swapoff -a 临时关闭
$ free 可以通过这个命令查看swap是否关闭了
$ vim /etc/fstab 永久关闭
#/dev/mapper/centos_k8s--master-swap swap swap defaults 0 0
备注:必须关闭
4.添加主机名与IP对应的关系 $ vim /etc/hosts
添加如下内容:
192.168.122.* k8s-master
192.168.122.* test3
5.将桥接的IPV4流量传递到iptables 的链 $ cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1 net.ipv4.ip_forward = 1 net.bridge.bridge-nf-call-iptables = 1
EOF
1、安装docker、kubelet、kubectl、kubeadm、socat
cat kubernets.repo
[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
安装相应版本的kubernets 安装docker 源
scp /etc/yum.repos.d/docker-ce.repo
2、将需要的镜像都加载到服务器上面:
yum install docker、kubelet、kubectl、kubeadm、socat -y
3、在master上面copy cni文件到node节点上面:
#mkdir -p /etc/cni/net.d
在master上面copy:
#scp /etc/cni/net.d/10-flannel.conf ip:/etc/cni/net.d
4、加入cluster
首先k8s默认的cgroup-driver为cgroupfs,但是yum安装kubelet的时候自动修改为systemd,而docker通过docker info命令查看是cgroupfs,所以需要将k8s的修改为cgroupfs:
#vim /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
Environment="KUBELET_CGROUP_ARGS=--cgroup-driver=cgroupfs"
#systemctl enable docker
#systemctl enable kubelet
kubeadm token create kubeadm token list openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | openssl dgst -sha256 -hex | sed 's/^.* //'
#kubeadm join --token c04f89.b781cdb55d83c1ef 10.10.3.4:63 --discovery-token-ca-cert-hash sha256:986e83a9cb948368ad0552b95232e31d3b76e2476b595bd1d905d5242ace29af --ignore-preflight-errors=Swap
#kubectl label node km1 node-role.kubernetes.io/node=
[root@k8s-node02 ~]# kubeadm join 192.168.*.*:6443 --token q1yxmd.zyydq6ll75twmn6p --discovery-token-ca-cert-hash sha256:758341b77ec419f488a697a97cbe9c082aef934b5c0b3b62d9d4ea9414ae897d
yum list docker-ce --showduplicates|sort -r yum install -y docker-ce-19.03.13
添加标签 kubectl label node k-node-test2 nodetype=file
kubeadm join 192.168.*.*:6443 --token 73v71h.ehgzsrxub4n5zqfs --discovery-token-ca-cert-hash sha256:5e46356ced09d140cee70811da0df82d8b8b2d990122ac75577ad08ec48b4485
mke2fs -t ext4 /dev/vdb1 cat >> /etc/fstab << EOF /dev/vdb1 /data ext4 defaults 1 1 EOF
标签:node,--,etc,token,yum,kubeadm,k8s,docker From: https://blog.51cto.com/u_16056808/6193483