k8s搭建实操记录干货二(node)

#注:172.16.110.111为master,172.16.110.112\114为node1\node2(kubeadm join部分要等master完成后手工操作,其它可执行本脚本一键安装)

#!/bin/bash  
##本脚本执行后再执行master机器,因为master有docker配置文档要cp过来,cp后要systemctl daemon-reload
#1)关闭CentOS7自带的防火墙服务
systemctl disable firewalld
systemctl stop firewalld

sed -i "s@SELINUX=enforcing@SELINUX=disabled@g" /etc/selinux/config

#2)修改主机名。
hostnamectl set-hostname master
hostnamectl set-hostname node1
hostnamectl set-hostname node2

#3)修改/etc/hosts
cat >> /etc/hosts <<EOF
172.16.110.111 master
172.16.110.112 node1
172.16.110.114 node2
EOF

#4)修改时间:
yum -y install ntpdate
ntpdate ntp1.aliyun.com

##虚拟机要关swap:
swapoff -a
#5)下载源与安装docker:
Yum  -y install wget
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

cat >>/etc/yum.repos.d/kubernetes.repo <<EOF
[kubernetes]
name=kubernetes Repo
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
enabled=1
EOF

wget https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
rpm --import rpm-package-key.gpg
yum -y install docker-ce kubelet kubeadm


cat >> /etc/sysctl.conf <<EOF
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
EOF

echo "################安装后的输出结果#################" >>/opt/k8s_node_install.log

rpm -ql kubelet >>/opt/k8s_node_install.log
cat /proc/sys/net/bridge/bridge-nf-call-iptables >>/opt/k8s_node_install.log
cat /proc/sys/net/bridge/bridge-nf-call-ip6tables >>/opt/k8s_node_install.log
sysctl -p >>/opt/k8s_node_install.log

#6) 启动docker并添加主集群里:
systemctl daemon-reload
systemctl start docker && systemctl enable docker kubelet
kubeadm join 172.16.110.111:6443 --token gmxuck.nybmu19vbe3j7vm8 --discovery-token-ca-cert-hash sha256:99a8e071df1a498bcf0797812640d58edf08fb6a0c6f8f496641021b27d0dbf4
##或看情况加--ignore-preflight-errors=Swap参数
kubeadm join 172.16.110.111:6443 --token gmxuck.nybmu19vbe3j7vm8 --discovery-token-ca-cert-hash sha256:99a8e071df1a498bcf0797812640d58edf08fb6a0c6f8f496641021b27d0dbf4 --ignore-preflight-errors=Swap

docker image ls

##其它:

##重置master信息
kubeadm reset 
kubeadm join 172.16.110.111:6443 --token gmxuck.nybmu19vbe3j7vm8 --discovery-token-ca-cert-hash sha256:99a8e071df1a498bcf0797812640d58edf08fb6a0c6f8f496641021b27d0dbf4

 

上一篇:JNI odx bridge install dependent libs


下一篇:Docker网络配置