kuberntes-msater - kubeadm v1.14.1 版本的shell脚本安 (1)

备注,脚本中涉及的IP ,hosts,要根据实际情况修改,请勿直接用,会报错。。如果有疑问请留言,或者私信。互相交流学习。

#!/bin/bash
#author shadow2017
#kubernetes 1.14.1
yum install vim wget net-tools lrzsz -y
#1:配置环境:
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
iptables -F
iptables -t nat -F
iptables -I FORWARD -s 0.0.0.0/0 -d 0.0.0.0/0 -j ACCEPT
yum -y install ntp
ntpdate pool.ntp.org
systemctl start ntpd
systemctl enable ntpd
systmctl stop firewalld.serice iptables.service
systemctl disable firewalld.service
systemctl disable iptable.service

#2:配置hosts 解析
cat > /etc/hosts < 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.137 k8s-test
EOF

#备注根据实际情况修改IP

#3:配置内核参数:
cat > /etc/sysctl.conf < 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
vm.swappiness=0
EOF
#4:关闭selinux
echo -n “正在关闭SELinux……”
setenforce 0 > /dev/null 2>&1
sed -i ‘/^SELINUX=/s/=.*/=disabled/’ /etc/selinux/config
if [ KaTeX parse error: Expected 'EOF', got '#' at position 51: …inux初始化完毕!" fi #̲setenforce 0 #s…/SELINUX=disabled/’ /etc/selinux/config
cat /etc/selinux/config
#5:保存修改内核参数生效
sysctl -p
#6:配置kubernetes

echo -n “正在配置kubernetes.repo”
cat > /etc/yum.repos.d/kubernetes.repo < [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/rpm-package-key.gpg
enabled=1
EOF
if [ $? -eq 0 ];then
echo -n “kubernetes配置完毕!”
fi
#7、安装Docker
echo -n “正在安装docker…!”
wget -P /etc/yum.repos.d https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum list docker-ce --showduplicates | sort -r
yum install docker-ce -y
#8:启动docker并设置开机启动
systemctl start docker
systemctl enable docker
systemctl status docker
if [ $? -eq 0 ];then
echo -n “docker安装配置完毕!”
fi
#9:执行下面命令配置加速器:
echo -n “配置加速器…”
curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://f1361db2.m.daocloud.io
systemctl restart docker
#10:安装kubeadm和kubelet
#备注:
#可以指定型号安装:

echo -n “安装kubeadm,kubelet,kubectl…!”
yum install -y kubelet-1.14.1 kubernetes-cni-0.6.0-0.x86_64 kubeadm-1.14.1 kubectl-1.14.1 --disableexcludes=kubernetes &&
systemctl enable --now kubelet &&
systemctl start kubelet &&
systemctl status kubelet
#11:设置开机启动kubelet
systemctl daemon-reload &&
systemctl start kubelet &&
systemctl enable kubelet &&
systemctl status kubelet
if [ $? -eq 0 ];then
echo -n “kubeadm,kubelet,kubectl haved install
!”
fi

#12:此时查看下面两个文件的值是否为1
cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
#13:执行命令查看需要哪些镜像安装:
kubeadm config images list
#14:下载所需要的镜像:

#master节点所需要的全部镜像如下:
echo -n “Downloading the kubernetes image…”
docker pull mirrorgooglecontainers/kube-apiserver:v1.14.1 &&
docker pull mirrorgooglecontainers/kube-controller-manager:v1.14.1 &&
docker pull mirrorgooglecontainers/kube-scheduler:v1.14.1 &&
docker pull mirrorgooglecontainers/etcd:3.3.10 &&
docker pull willdockerhub/coredns:1.3.1 &&
docker pull mirrorgooglecontainers/kube-proxy:v1.14.1 &&
docker pull mirrorgooglecontainers/pause:3.1

#15:给镜像打上标签:
echo -n “Labeling kubernetes mirror…!”
docker tag mirrorgooglecontainers/kube-apiserver:v1.14.1 k8s.gcr.io/kube-apiserver:v1.14.1
docker tag mirrorgooglecontainers/kube-controller-manager:v1.14.1 k8s.gcr.io/kube-controller-manager:v1.14.1
docker tag mirrorgooglecontainers/kube-scheduler:v1.14.1 k8s.gcr.io/kube-scheduler:v1.14.1
docker tag mirrorgooglecontainers/kube-proxy:v1.14.1 k8s.gcr.io/kube-proxy:v1.14.1
docker tag mirrorgooglecontainers/pause:3.1 k8s.gcr.io/pause:3.1
docker tag mirrorgooglecontainers/etcd:3.3.10 k8s.gcr.io/etcd:3.3.10
docker tag willdockerhub/coredns:1.3.1 k8s.gcr.io/coredns:1.3.1
if [ $? -eq 0 ];then
echo -n “Preparations for the mirror work have been completed!”
fi

#16:执行以下命令初始化:注意修改ip 为master节点
echo -e “\033[32m Preparing to initialize the kubernetes node, please pay attention to the observation…\033[0m”
kubeadm init
–kubernetes-version=v1.14.1
–pod-network-cidr=10.244.0.0/16
–service-cidr=10.96.0.0/12
–apiserver-advertise-address=192.168.1.137 |tee /root/kubeadm.log

#ip 为master的ip,根据情况,这里初始化后产生的tokeng 送到/root/kubeadm.log文件,后面可以用来添加Node节点

echo -e “\033[32m Congratulations on the completion of initialization\033[0m”

#kubeadm join 192.168.1.137:6443 --token 9dwb71.qfhdiue06r7axfmn \

–discovery-token-ca-cert-hash sha256:a6b92496ed39f9643e0c6d6c5e9dd3f692316dae400b27c636a51cf70a6cfba1

#kubeadm token create
#openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \

openssl dgst -sha256 -hex | sed ‘s/^.* //’

#17:修改环境变量:

echo -e “\033[32m Configuring kubernetes System Environment\033[0m”
mkdir -p $HOME/.kube &&
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config &&
chown ( i d − u ) : (id -u): (idu):(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
if [ $? -eq 0 ];then
echo -n “Configuring kubernetes System Environment have been completed!”
fi

#18:创建安装flannel网络
echo -e “\033[32m initialization flannel netork…\033[0m”
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/a70459be0084506e4ec919aa1c114638878db11b/Documentation/kube-flannel.yml
if [ $? -eq 0 ];then
echo -n “initialization flannel have been completed!”
fi

你可能感兴趣的:(运维基础配置,自动化运维,运维学习笔记,微服务,linux服务器)