#!/bin/bash
NODENUM=$1
if [ ! -n "$NODENUM" ];then
echo "请输入节点名称"
exit 1
else
echo $NODENUM
fi
hostnamectl set-hostname $NODENUM
modprobe br_netfilter
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-ip6tables = 1" >> /etc/sysctl.conf
echo "net.bridge.bridge-nf-call-iptables = 1" >> /etc/sysctl.conf
sysctl -p
yum install -y nfs-utils wget
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum install -y docker-ce docker-ce-cli
systemctl enable docker && systemctl start docker
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
yum install -y kubelet-1.17.0 kubeadm-1.17.0 kubectl-1.17.0
systemctl enable kubelet && systemctl start kubelet
cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors": ["https://8xta6lj0.mirror.aliyuncs.com"]
}
EOF
sed -i "s#^ExecStart=/usr/bin/dockerd.*#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd#g" /usr/lib/systemd/system/docker.service
systemctl daemon-reload && systemctl restart docker
echo "172.16.10.9 apiserver.shiji" >> /etc/hosts
echo "172.16.10.9 shiji.com" >> /etc/hosts
echo `ip addr |grep eth0 |awk -F' ' '{print $2}'| grep -v eth0 |awk -F'/' '{print $1}'` $NODENUM >> /etc/hosts
echo "节点初始化操作完成,请在master节点上设置hosts解析后加入K8S集群"