-
Notifications
You must be signed in to change notification settings - Fork 2
/
5.add_node_start.sh
executable file
·36 lines (30 loc) · 1.72 KB
/
5.add_node_start.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
#!/bin/bash
# 此文件需要在 Vagrantfile 文件所在目录执行
# 虚拟机环境定义
HOSTNAME_WORKER=cka-3
BASE_DIR=$(cd "$(dirname "$0")";pwd)
BIN_PATH=$BASE_DIR/deploy_k8s_bin
REMOTE_NODE=tmp_add_node
SYSTEMD_DIR=$BASE_DIR/files/$REMOTE_NODE
# docker
scp -r $BIN_PATH/k8s_v1.21.4/ ${HOSTNAME_WORKER}:~/
ssh $HOSTNAME_WORKER "sudo chmod +x ~/ && sudo cp -rf ~/k8s_v1.21.4/* /usr/bin \
&& sudo apt update \
&& sudo apt install socat conntrack resolvconf ipvsadm ipset jq sysstat docker.io -y"
scp -r $SYSTEMD_DIR ${HOSTNAME_WORKER}:~/
ssh ${HOSTNAME_WORKER} "sudo mkdir -p /var/lib/kubelet /var/lib/kube-proxy /etc/kubernetes/config /etc/kubernetes/manifest /var/run/kubernetes \
&& sudo cp -rf ~/$REMOTE_NODE/ca.pem /etc/kubernetes/config \
&& sudo cp -rf ~/$REMOTE_NODE/${HOSTNAME_WORKER}-key.pem /var/lib/kubelet/ \
&& sudo cp -rf ~/$REMOTE_NODE/${HOSTNAME_WORKER}.pem /var/lib/kubelet/ \
&& sudo cp -rf ~/$REMOTE_NODE/${HOSTNAME_WORKER}.kubeconfig /var/lib/kubelet/kubeconfig \
&& sudo cp -rf ~/$REMOTE_NODE/kube-proxy.kubeconfig /var/lib/kube-proxy/kubeconfig"
# kubelet+kube-proxy
ssh ${HOSTNAME_WORKER} "sudo cp -rf ~/$REMOTE_NODE/kubelet-config-${HOSTNAME_WORKER}.yaml /var/lib/kubelet/kubelet-config.yaml \
&& sudo cp -rf ~/$REMOTE_NODE/kubelet-${HOSTNAME_WORKER}.service /etc/systemd/system/kubelet.service \
&& sudo cp -rf ~/$REMOTE_NODE/kube-proxy-config.yaml /var/lib/kube-proxy/ \
&& sudo cp -rf ~/$REMOTE_NODE/kube-proxy.service /etc/systemd/system/ \
&& sudo systemctl daemon-reload \
&& sudo systemctl restart docker \
&& sudo systemctl restart kubelet \
&& sudo systemctl restart kube-proxy \
&& sudo systemctl enable docker && sudo systemctl enable kubelet && sudo systemctl enable kube-proxy"