Kubernetes–三节点部署
- 这里使用了三个节点来部署K8s,一个master,三个node的形式。
host | ip |
---|
master | 192.168.80.10 | node1 | 192.168.80.11 | node2 | 192.168.80.12 |
部署脚本:kubernetes_install.sh
使用: master上执行 sh kubernetes_install.sh master node1,2上执行 sh kubernetes_install.sh 都执行完之后,两个node加入kubernetes集群。
#!/bin/bash
function prepare_env()
{
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/^SELINUX.*/SELINUX\=disabled/' /etc/selinux/config
setenforce 0
swapoff -a
cat >> /etc/hosts << 'EOF'
192.168.80.10 master
192.168.80.11 node1
192.168.80.12 node2
EOF
cat > /etc/sysctl.d/k8s.conf << 'EOF'
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl -p
}
function check_req()
{
rpm -qa | grep wget
if [ $? != 0 ];then
yum -y install wget
sleep 2s
rpm -qa | grep wget
if [ $? != 0 ];then
echo -n "NO wget, EXIT\n"
exit
fi
fi
}
function install_component()
{
check_req
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce
systemctl enable docker && systemctl start docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://t0oXXXXn.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
echo "--------------------------docker install success----------------------"
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
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.20.0 kubeadm-1.20.0 kubectl-1.20.0
systemctl enable kubelet
}
function init_master()
{
kubeadm init \
--apiserver-advertise-address=192.168.80.10 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.20.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16 \
--ignore-preflight-errors=all
sleep 10s
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
export KUBECONFIG=/etc/kubernetes/admin.conf
echo 'export KUBECONFIG=/etc/kubernetes/admin.conf' >> /etc/profile
wget --no-check-certificate https://docs.projectcalico.org/manifests/calico.yaml
}
opt=$1
if [ -z $opt ];then
prepare_env
install_component
elif [ $opt == "master" ];then
prepare_env
install_component
init_master
else
echo -n "Param is Wrong\n"
exit
fi
|