kubernetes v1.20.0
This commit is contained in:
@ -29,6 +29,7 @@ EOF
|
||||
|
||||
# kubeadm init
|
||||
# 根据您服务器网速的情况,您需要等候 3 - 10 分钟
|
||||
kubeadm config images pull --config=kubeadm-config.yaml
|
||||
kubeadm init --config=kubeadm-config.yaml --upload-certs
|
||||
|
||||
# 配置 kubectl
|
||||
|
||||
45
.vuepress/public/install-script/v1.20.x/init_master.sh
Normal file
45
.vuepress/public/install-script/v1.20.x/init_master.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 只在 master 节点执行
|
||||
|
||||
# 脚本出错时终止执行
|
||||
set -e
|
||||
|
||||
if [ ${#POD_SUBNET} -eq 0 ] || [ ${#APISERVER_NAME} -eq 0 ]; then
|
||||
echo -e "\033[31;1m请确保您已经设置了环境变量 POD_SUBNET 和 APISERVER_NAME \033[0m"
|
||||
echo 当前POD_SUBNET=$POD_SUBNET
|
||||
echo 当前APISERVER_NAME=$APISERVER_NAME
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# 查看完整配置选项 https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2
|
||||
rm -f ./kubeadm-config.yaml
|
||||
cat <<EOF > ./kubeadm-config.yaml
|
||||
apiVersion: kubeadm.k8s.io/v1beta2
|
||||
kind: ClusterConfiguration
|
||||
kubernetesVersion: v${1}
|
||||
imageRepository: registry.aliyuncs.com/k8sxio
|
||||
controlPlaneEndpoint: "${APISERVER_NAME}:6443"
|
||||
networking:
|
||||
serviceSubnet: "10.96.0.0/16"
|
||||
podSubnet: "${POD_SUBNET}"
|
||||
dnsDomain: "cluster.local"
|
||||
EOF
|
||||
|
||||
# kubeadm init
|
||||
# 根据您服务器网速的情况,您需要等候 3 - 10 分钟
|
||||
kubeadm config images pull --config=kubeadm-config.yaml
|
||||
kubeadm init --config=kubeadm-config.yaml --upload-certs
|
||||
|
||||
# 配置 kubectl
|
||||
rm -rf /root/.kube/
|
||||
mkdir /root/.kube/
|
||||
cp -i /etc/kubernetes/admin.conf /root/.kube/config
|
||||
|
||||
# 安装 calico 网络插件
|
||||
# 参考文档 https://docs.projectcalico.org/v3.13/getting-started/kubernetes/self-managed-onprem/onpremises
|
||||
echo "安装calico-3.13.1"
|
||||
rm -f calico-3.13.1.yaml
|
||||
wget https://kuboard.cn/install-script/calico/calico-3.13.1.yaml
|
||||
kubectl apply -f calico-3.13.1.yaml
|
||||
112
.vuepress/public/install-script/v1.20.x/install_kubelet.sh
Normal file
112
.vuepress/public/install-script/v1.20.x/install_kubelet.sh
Normal file
@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 在 master 节点和 worker 节点都要执行
|
||||
|
||||
# 安装 docker
|
||||
# 参考文档如下
|
||||
# https://docs.docker.com/install/linux/docker-ce/centos/
|
||||
# https://docs.docker.com/install/linux/linux-postinstall/
|
||||
|
||||
# 卸载旧版本
|
||||
apt-get remove -y docker \
|
||||
docker-client \
|
||||
docker-client-latest \
|
||||
docker-ce-cli \
|
||||
docker-common \
|
||||
docker-latest \
|
||||
docker-latest-logrotate \
|
||||
docker-logrotate \
|
||||
docker-selinux \
|
||||
docker-engine-selinux \
|
||||
docker-engine
|
||||
|
||||
# 设置 apt-get repository
|
||||
apt-get update && apt-get install -y apt-transport-https lvm2
|
||||
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
|
||||
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
|
||||
apt-get -y update
|
||||
|
||||
# 安装并启动 docker
|
||||
apt-get install -y docker-ce=5:20.10.1~3-0~ubuntu-focal docker-ce-cli=5:20.10.1~3-0~ubuntu-focal containerd.io=
|
||||
|
||||
mkdir /etc/docker || true
|
||||
|
||||
cat > /etc/docker/daemon.json <<EOF
|
||||
{
|
||||
"registry-mirrors": ["${REGISTRY_MIRROR}"],
|
||||
"exec-opts": ["native.cgroupdriver=systemd"],
|
||||
"log-driver": "json-file",
|
||||
"log-opts": {
|
||||
"max-size": "100m"
|
||||
},
|
||||
"storage-driver": "overlay2",
|
||||
"storage-opts": [
|
||||
"overlay2.override_kernel_check=true"
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
mkdir -p /etc/systemd/system/docker.service.d
|
||||
|
||||
# Restart Docker
|
||||
systemctl daemon-reload
|
||||
systemctl enable docker
|
||||
systemctl restart docker
|
||||
|
||||
# 安装 nfs-utils
|
||||
# 必须先安装 nfs-utils 才能挂载 nfs 网络存储
|
||||
apt-get install -y nfs-utils
|
||||
apt-get install -y wget
|
||||
|
||||
# 关闭 防火墙
|
||||
systemctl stop firewalld
|
||||
systemctl disable firewalld
|
||||
|
||||
# 关闭 SeLinux
|
||||
setenforce 0
|
||||
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
|
||||
|
||||
# 关闭 swap
|
||||
swapoff -a
|
||||
yes | cp /etc/fstab /etc/fstab_bak
|
||||
cat /etc/fstab_bak |grep -v swap > /etc/fstab
|
||||
|
||||
# 修改 /etc/sysctl.conf
|
||||
# 如果有配置,则修改
|
||||
sed -i "s#^net.ipv4.ip_forward.*#net.ipv4.ip_forward=1#g" /etc/sysctl.conf
|
||||
sed -i "s#^net.bridge.bridge-nf-call-ip6tables.*#net.bridge.bridge-nf-call-ip6tables=1#g" /etc/sysctl.conf
|
||||
sed -i "s#^net.bridge.bridge-nf-call-iptables.*#net.bridge.bridge-nf-call-iptables=1#g" /etc/sysctl.conf
|
||||
sed -i "s#^net.ipv6.conf.all.disable_ipv6.*#net.ipv6.conf.all.disable_ipv6=1#g" /etc/sysctl.conf
|
||||
sed -i "s#^net.ipv6.conf.default.disable_ipv6.*#net.ipv6.conf.default.disable_ipv6=1#g" /etc/sysctl.conf
|
||||
sed -i "s#^net.ipv6.conf.lo.disable_ipv6.*#net.ipv6.conf.lo.disable_ipv6=1#g" /etc/sysctl.conf
|
||||
sed -i "s#^net.ipv6.conf.all.forwarding.*#net.ipv6.conf.all.forwarding=1#g" /etc/sysctl.conf
|
||||
# 可能没有,追加
|
||||
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
|
||||
echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
|
||||
echo "net.ipv6.conf.default.disable_ipv6 = 1" >> /etc/sysctl.conf
|
||||
echo "net.ipv6.conf.lo.disable_ipv6 = 1" >> /etc/sysctl.conf
|
||||
echo "net.ipv6.conf.all.forwarding = 1" >> /etc/sysctl.conf
|
||||
# 执行命令以应用
|
||||
sysctl -p
|
||||
|
||||
# 配置K8S的apt-get源
|
||||
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
|
||||
cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
|
||||
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
|
||||
EOF
|
||||
|
||||
# 卸载旧版本
|
||||
apt-get remove -y kubelet kubeadm kubectl
|
||||
|
||||
# 安装kubelet、kubeadm、kubectl
|
||||
# 将 ${1} 替换为 kubernetes 版本号,例如 1.19.0
|
||||
apt-get install -y kubelet=${1}-00 kubeadm=${1}-00 kubectl=${1}-00
|
||||
|
||||
# 重启 docker,并启动 kubelet
|
||||
systemctl daemon-reload
|
||||
systemctl restart docker
|
||||
systemctl enable kubelet && systemctl start kubelet
|
||||
|
||||
docker version
|
||||
Reference in New Issue
Block a user