K8S Cluster Setup script

 

Currently the script is not yet complete optimization:

#! / bin / bash 

# initialize the environment 
# ============== initialization environment ================= 
echo -e "\ E [ 1; 31m ============== initialization environment ================= \ E [0m " 
# turn off the firewall: 
echo -e" \ e [1; 31m << ==== turn off the firewall, turn off the firewall and start their own >> ==== \ E [0m "&& 
systemctl STOP firewalld && 
systemctl disable firewalld && 

# turn off SELinux 
echo -e" \ E [ 1; 31m << ==== SELinux off, and power-off start their own SELinux >> ==== \ E [0m "&& 
the setenforce 0 && 
Sed -i" S / enforcing / Disabled / G "/ etc / SELinux / config 

# swap area close 
echo -e "\ e [1; 31m << ==== SELinux off, and power-off start their own SELinux >> ==== \ E [0m" && 
The swapoff && -a 
Sed -i ' s /.* swap. * / # & / '/ etc / fstab &&


#yum installation sshpass, wget and other necessary packages: 
yum -y install wget && sshpass


# << =============================================== ========== hostname and hosts file to add record ============================== ============= >> 
# emptied the entry rules only when the test is added, and if the actual operation, delete the entry 
#> / etc / hosts 
# ======== ============================== 

> / root / Host 
the Read -p "Please enter your current Master node for the IP node node communication: "Master_IP 
echo" # K8S set up to resolve the use of cluster ">> / etc / hosts 
host # first master node can be resolved locally written to the hosts file: 
echo" $ Master_IP master ">> / etc / hosts 


echo "Please the enter your Mount the Node (input process after this and as you enter the wrong, you can press Ctrl + Backspace key to delete wrong input parameters enter the correct parameters again):" 
the Read Mount 
echo -e "\ e [1; 31m your child node number is: $ mount a \ E [0m" 

I =. 1 
the while [$ I $ -le Mount] 
do 
Read -p "Enter your first $ i th Node node IP: "Ip
echo "$ I $ Ip Node" >> / etc / hosts && echo "$ Ip" >> / the root / Host 
the let + = I. 1	 
DONE 



# copy cycle hosts file and confirm the password to the password machine: 
I =. 1 
the while [$ i -le $ Mount] 
do 
the Read -s -p "enter your Node_IP is:` sed -n "$ i" p / root / host` machine password: "the Passwd 
echo '\ the n-' 
# add the hosts copy the file to the node node: 
/ usr / bin / SCP sshpass -p -o $ StrictHostKeyChecking the Passwd = NO / etc / Sed the hosts the root -n @ `" $ I "P / the root / host`: / etc / the hosts 
echo "hosts file has been copied to the node node" 
the let + = I. 1 
DONE 

echo "set host name" 
hostnamectl master hostname sET- 

echo "kernel parameter set" 
CAT> << /etc/sysctl.d/k8s.conf the EOF 
net.bridge .bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF 
sysctl - System 

echo "yum configuration domestic source"
# Configure yum domestic source
yum install -y wget
mkdir /etc/yum.repos.d/bak && mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.tencent.com/repo/centos7_base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.cloud.tencent.com/repo/epel-7.repo
yum clean all && yum makecache

echo "配置国内Kubernetes源"
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

echo "Configuration docker Source: " 
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 

echo" installation docker " 
# installation Docker 
yum the install Docker -Y-CE-18.06.1.ce-3.el7 
systemctl && systemctl Start enable Docker Docker 
Docker -version 

echo "installation kubeadm, kubelet, kubectl" 
# installation kubeadm, kubelet, kubectl 
yum the install -Y kubelet kubectl kubeadm 
systemctl enable kubelet 

echo "initial installation master node:" 
# initial installation master node:
kubeadm init --kubernetes-version = 1.15.3 --apiserver-advertise-address = $ Master_IP --image-repository registry.aliyuncs.com/google_containers --service-cidr = 10.1.0.0 / 16 --pod-network- cidr = 10.244.0.0 / 16 

  

Guess you like

Origin www.cnblogs.com/sdrbg/p/11440783.html