节点为centos7.4
一、node节点基本环境配置
1、配置主机名
2、配置hosts文件(master和node相互解析)
3、时间同步
ntpdate pool.ntp.org
date
echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org' >>/var/spool/cron/root
crontab -l
4、关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
5、关闭swap
swapoff -a
echo "vm.swappiness=0" >> /etc/sysctl.conf
sysctl -pswapoff -a
6、修改内核参数
yum install -y bridge-utils.x86_64
modprobe bridge
modprobe br_netfilter
echo "net.bridge.bridge-nf-call-iptables=1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables=1" >> /etc/sysctl.conf
sysctl -p
二、设置yum源,安装docker和k8s相关组件
1、设置yum源
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
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=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
2、安装
yum -y install docker-ce
以下两个,注意版本要和master端一致,可以去master看下
yum -y install kubelet-1.13.4-0.x86_64
yum -y install kubeadm-1.13.4-0.x86_64
systemctl enable kubelet
3、下载相关镜像
docker pull mirrorgooglecontainers/kube-proxy-amd64:v1.13.3
docker pull mirrorgooglecontainers/pause:3.1
docker tag docker.io/mirrorgooglecontainers/kube-proxy-amd64:v1.13.3 k8s.gcr.io/kube-proxy:v1.13.3
docker tag docker.io/mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
三、加入k8s集群
1、master中的节点认证信息24小时会失效,可以重新生成(master端操作)
重新生成用于节点加入集群的认证命令
创建token
[root@master ~]# kubeadm token create
创建新的sha
[root@master ~]# openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der sha256 -hex | sed 's/^.* //'
2、加入集群(node操作)
kubeadm join 172.16.20.102:6443 --token 【token】--discovery-token-ca-cert-hash sha256:【sha值】
四、如何删除节点(master端)
[root@master ~]# kubectl drain node03.linux.com --delete-local-data --force --ignore-daemonsets
[root@master ~]# kubectl delete node node03.linux.com