kubeadm构建k8s集群脚本
程序员文章站
2022-03-07 18:05:24
...
环境:
内存:大于2G
内核核心数:大于4
磁盘空间:大于20G
centos7.7 | 4.4.206-1.el7.elrepo.x86_64 |
kubeadm | v1.16.3 |
kubelet | v1.16.3 |
kubectl | v1.16.3 |
docker | docker-ce-18.09.6 |
系统安装完成之后的kernel是3.10版本,升级centos内核参照:
https://blog.csdn.net/kikajack/article/details/79396793
简易脚本:
代码当中两个变量需要注意:
DOCKER_REGISTRY:下载镜像时自己镜像仓库名称,
PASSWORD:登录仓库的密码
如何使用阿里云镜像与github构建镜像参照:
https://blog.csdn.net/sinat_35543900/article/details/103290782
网盘有我已经打包好的镜像压缩包:
https://pan.baidu.com/s/1JSBSejoPfjxZE6tifnAYiQ 提取码:t8xd
#!/bin/bash
TAG_INFO=v1.16.3
sed -i "s/Slinux=enforing/Slinux=disabled/g" /etc/selinux/config
setenforce 0
#set hostname
hostnamectl set-hostname master
cat >/etc/hosts <<EFO
127.0.0.1 localhost localhost localhost4 localhost4.localdomain4
::1 localhost localhost localhost6 localhost6.localdomain6
192.168.10.151 master
192.168.10.152 node01
192.168.10.151 node02
EFO
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=6443/tcp --permanent
firewall-cmd --zone=public --add-port=2379-2380/tcp --permanent
firewall-cmd --zone=public --add-port=10250-10255/tcp --permanent
firewall-cmd --zone=public --add-port=30000-32767/tcp --permanent
firewall-cmd --reload
firewall-cmd --zone=public --list-ports
yum install -y conntrack ntpdate ntp ipvsadm ipset curl sysstat libseccomp wget vim net-tools git
systemctl stop firewalld && systemctl disable firewalld
yum install iptables-services -y && systemctl start iptables && systemctl enable iptables && iptables -F && service iptables save
swapoff -a && sed -i "s/selinux=enforing/selinux=disable/g" /etc/selinux/config
touch /etc/sysctl.d/k8s.conf
cat </etc/sysctl.d/k8s.conf<<EFO
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
vm.swappiness=0
vm.panic_on_oom=0
net.ipv6.conf.all.disable_ipv6=1
EFO
sysctl -p /etc/sysctl.d/k8s.conf
modprobe br_netfilter
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
#insatll docker and kebernetes repos
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
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
yum makecache fast
#install k8s_cluster appliacations
yum install docker-ce-18.09.6 -y
yum install kubeadm-1.16.3 kubectl-1.16.3 kubelet-1.16.3 -y
echo "1">/proc/sys/net/bridge/bridge-nf-call-iptables
echo "1">/proc/sys/net/bridge/bridge-nf-call-ip6tables
systemctl enable docker && systemctl start docker
systemctl enable kubelet && systemctl start kubelet
#speed up docker images
cat > /etc/docker/daemon.json <<EOF
{
"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
systemctl daemon-reload
systemctl restart docker
docker login --username=DOCKER_REGISTRY -p PASSWOD
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/kube-apiserver:${TAG_INFO}
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/kube-controller-manage:${TAG_INFO}
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/kube-scheduler:${TAG_INFO}
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/kube-proxy:${TAG_INFO}
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/pause:3.1
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/etcd:3.3.15-0
docker pull registry.cn-chengdu.aliyuncs.com/shixiong/coredns:1.6.2
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/kube-apiserver:${TAG_INFO} k8s.gcr.io/kube-apiserver:v1.16.3
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/kube-controller-manage:${TAG_INFO} k8s.gcr.io/kube-controller-manager:v1.16.3
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/kube-scheduler:${TAG_INFO} k8s.gcr.io/kube-scheduler:v1.16.3
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/kube-proxy:${TAG_INFO} k8s.gcr.io/kube-proxy:v1.16.3
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/pause:3.1 k8s.gcr.io/pause:3.1
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/etcd:3.3.15-0 k8s.gcr.io/etcd:3.3.15-0
docker tag registry.cn-chengdu.aliyuncs.com/shixiong/coredns:1.6.2 k8s.gcr.io/coredns:1.6.2
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/kube-apiserver:${TAG_INFO}
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/kube-controller-manage:${TAG_INFO}
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/kube-scheduler:${TAG_INFO}
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/kube-proxy:${TAG_INFO}
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/pause:3.1
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/etcd:3.3.15-0
docker rmi registry.cn-chengdu.aliyuncs.com/shixiong/coredns:1.6.2
kubeadm init --ignore-preflight-errors=Swap --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address 192.168.10.151
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
#install fannel
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml
上一篇: Win10电脑如何开启低电池电量通知提醒
下一篇: Java单例七种写法