-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-k8s.sh
88 lines (68 loc) · 2.71 KB
/
get-k8s.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
set -e
# 快速安装一个k8s,仅限测试使用
# 只试用于centos 7+
# 主节点: curl -fsSL https://zgfh.github.io/get-k8s.sh -o get-k8s.sh && bash get-k8s.sh
# 从节点: curl -fsSL https://zgfh.github.io/get-k8s.sh -o get-k8s.sh && bash get-k8s.sh join <master_ip>
# 网络: kubectl apply -f https://zgfh.github.io//calico-v3.10.yaml
# 如果只想初始化环境,手动通过kubeadm 安装 curl -fsSL https://zgfh.github.io/get-k8s.sh -o get-k8s.sh && bash get-k8s.sh init
K8S_VERSION=${K8S_VERSION-"v1.19.2"}
init_host(){
# 系统配置
setenforce 0 && sed -i '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config
systemctl stop firewalld || echo "no firewalld"
systemctl disable firewalld || echo "no firewalld"
sysctl vm.swappiness=0
sed -i 's/vm.swappiness/#vm.swappiness/g' /etc/sysctl.conf
echo "vm.swappiness = 0" >> /etc/sysctl.conf
swapoff -a
sed -i '/ swap / s/^/#/' /etc/fstab
cat >/etc/sysctl.d/k8s.conf <<EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward=1
EOF
#DEVICE=$(ls -l /sys/class/net | awk '$NF~/pci0/ { print $(NF-2); exit }')
#IPADDR=$(ip -br address show dev $DEVICE | awk '{print substr($3,1,index($3,"/")-1);}')
#ping -c `hostname` || echo '$IPADDR `hostname`' >>/etc/hosts
# 安装docker 和kubelet
docker version >/dev/null 2>&1 || (curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh && systemctl start docker && systemctl enable docker)
kubelet --version >/dev/null 2>&1 ||rm -rf /tmp/k8s
kubelet --version >/dev/null 2>&1 ||(docker run --rm -v /tmp:/tmp daocloud.io/daocloud/kube_binary:${K8S_VERSION} sh -c 'cp -rf /app /tmp/k8s')
kubelet --version >/dev/null 2>&1 ||(cd /tmp/k8s/;./install.sh)
yum install -y socat ebtables ethtool conntrack-tools
}
master_install(){
init_host
# 安装k8s
kubeadm --image-repository=daocloud.io/daocloud --kubernetes-version=${K8S_VERSION} init --pod-network-cidr=10.252.0.0/16 --token=vqheb6.vqheb6tdangerous
# 配置kubelet
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# 安装calico 网络
}
slave_install(){
init_host
kubeadm join $1:6443 --token=vqheb6.vqheb6tdangerous --discovery-token-unsafe-skip-ca-verification
echo "you need run (master print this): kubeadm join <masterip> --token xxx "
}
# 重置
reset_install(){
kubeadm reset -f
}
# 重置
init_install(){
init_host
echo "now,you can install k8s: "
echo " kubeadm --image-repository=daocloud.io/daocloud --kubernetes-version=${K8S_VERSION} init --pod-network-cidr=10.252.0.0/16 "
}
if [ "$1" == "join" ];then
slave_install $2
elif [ "$1" == "reset" ];then
reset_install
elif [ "$1" == "init" ];then
init_install
else
master_install
fi