Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
tingweiwang
/
k8s
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 34145b56
authored
Aug 29, 2020
by
tingweiwang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去除冗余代码
1 parent
61df46cb
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
42 deletions
script/k8s/add_node.sh
script/k8s/add_node.sh
View file @
34145b5
...
@@ -50,16 +50,15 @@ ansible new_node -m shell -a "systemctl daemon-reload"
...
@@ -50,16 +50,15 @@ ansible new_node -m shell -a "systemctl daemon-reload"
ansible new_node -m shell -a
"service flanneld restart"
ansible new_node -m shell -a
"service flanneld restart"
ansible new_node -m shell -a
"service flanneld status"
ansible new_node -m shell -a
"service flanneld status"
ansible new_node -m shell -a
"systemctl enable flanneld.service"
ansible new_node -m shell -a
"systemctl enable flanneld.service"
##############################
######################
################################################
##############################
安装node节点所需基础软件
################################################
ansible new_node -m shell -a
"apt update --allow-insecure-repositories && apt install nfs-common unzip conntrack --allow-unauthenticated -y"
ansible new_node -m shell -a
"apt update --allow-insecure-repositories && apt install nfs-common unzip conntrack --allow-unauthenticated -y"
#############################安装docker#############################################################
#############################
根据不同节点类型
安装docker#############################################################
echo
"提前渲染各个类型的daemon.json,为分发做准备"
&&
sleep 2
echo
"提前渲染各个类型的daemon.json,为分发做准备"
&&
sleep 2
sed -i s/harbor_host/
$harbor_host
/g /root/k8s/config/daemon.json_gpu
sed -i s/harbor_host/
$harbor_host
/g /root/k8s/config/daemon.json_gpu
sed -i s/harbor_host/
$harbor_host
/g /root/k8s/config/daemon.json_cpu
sed -i s/harbor_host/
$harbor_host
/g /root/k8s/config/daemon.json_cpu
echo
"两种类型的daemon.json全部分发到所有节点的/tmp目录"
echo
"两种类型的daemon.json全部分发到所有节点的/tmp目录"
ansible new_node -m copy -a
"src=/root/k8s/config/daemon.json_gpu dest=/tmp/"
ansible new_node -m copy -a
"src=/root/k8s/config/daemon.json_gpu dest=/tmp/"
ansible new_node -m copy -a
"src=/root/k8s/config/daemon.json_cpu dest=/tmp/"
ansible new_node -m copy -a
"src=/root/k8s/config/daemon.json_cpu dest=/tmp/"
################################################################################
echo
"判断当前节点是gpu,还是cpu节点,根据节点不同,完成不同操作&& sleep 2"
echo
"判断当前节点是gpu,还是cpu节点,根据节点不同,完成不同操作&& sleep 2"
ansible new_node -m shell -a
'if [ `lspci |grep -i nvidia|wc -l` -gt 0 ]; then echo "gpu节点安装docker" && apt install nvidia-docker2 docker-ce --allow-unauthenticated -y; else echo "cpu节点安装docker"&& apt install docker-ce --allow-unauthenticated -y ; fi'
ansible new_node -m shell -a
'if [ `lspci |grep -i nvidia|wc -l` -gt 0 ]; then echo "gpu节点安装docker" && apt install nvidia-docker2 docker-ce --allow-unauthenticated -y; else echo "cpu节点安装docker"&& apt install docker-ce --allow-unauthenticated -y ; fi'
ansible new_node -m shell -a
'if [ `lspci |grep -i nvidia|wc -l` -gt 0 ]; then echo "gpu节点分发自己节点tmp目录下的daemon.json" && mv /tmp/daemon.json_gpu /etc/docker/daemon.json; else echo "cpu节点分发自己节点tmp目录下的daemon.json"&& mv /tmp/daemon.json_cpu /etc/docker/daemon.json; fi'
ansible new_node -m shell -a
'if [ `lspci |grep -i nvidia|wc -l` -gt 0 ]; then echo "gpu节点分发自己节点tmp目录下的daemon.json" && mv /tmp/daemon.json_gpu /etc/docker/daemon.json; else echo "cpu节点分发自己节点tmp目录下的daemon.json"&& mv /tmp/daemon.json_cpu /etc/docker/daemon.json; fi'
...
@@ -69,45 +68,6 @@ ansible new_node -m shell -a "cat /etc/docker/daemon.json"
...
@@ -69,45 +68,6 @@ ansible new_node -m shell -a "cat /etc/docker/daemon.json"
echo
"还原两种类型的daemon.json模板"
&&
sleep 2
echo
"还原两种类型的daemon.json模板"
&&
sleep 2
sed -i s/
$harbor_host
/harbor_host/g /root/k8s/config/daemon.json_gpu
sed -i s/
$harbor_host
/harbor_host/g /root/k8s/config/daemon.json_gpu
sed -i s/
$harbor_host
/harbor_host/g /root/k8s/config/daemon.json_cpu
sed -i s/
$harbor_host
/harbor_host/g /root/k8s/config/daemon.json_cpu
:
<<
test=`lspci |grep -i nvidia`
if [ $test -ep 0 ];then
echo "当前节点是GPU节点,开始配置gpu类型docker" && sleep 2 && apt install nvidia-docker2 --allow-unauthenticated -y
echo "当前harbor仓库地址为$harbor_host"
sed -i s/harbor_host/$harbor_host/g /root/k8s/config/daemon.json_gpu
echo "开始安装docker"
ansible new_node -m shell -a "apt update --allow-insecure-repositories"
ansible new_node -m shell -a "apt install docker-ce -y --allow-unauthenticated"
echo "分发已修改的gpu daemon.json文件"
ansible new_node -m copy -a "src=/root/k8s/config/daemon.json_gpu dest=/etc/docker/daemon.json"
ansible new_node -m copy -a "src=/root/k8s/service/docker.service dest=/lib/systemd/system/docker.service mode=755"
ansible new_node -m shell -a "service docker restart"
ansible new_node -m shell -a "service docker status"
ansible new_node -m shell -a "cat /etc/docker/daemon.json"
echo "还原daemon.json模板文件"
sed -i s/$harbor_host/harbor_host/g /root/k8s/config/daemon.json_gpu
else
echo "当前节点是CPU节点,开始安装配置cpu 类型docker && sleep 2"
echo "当前harbor仓库地址为$harbor_host,"
sed -i s/harbor_host/$harbor_host/g /root/k8s/config/daemon.json_cpu
echo "开始安装docker"
ansible new_node -m shell -a "apt update --allow-insecure-repositories"
ansible new_node -m shell -a "apt install conntrack unzip nfs-common docker-ce -y --allow-unauthenticated"
echo "分发已修改的daemon.json文件"
ansible new_node -m copy -a "src=/root/k8s/config/daemon.json_cpu dest=/etc/docker/daemon.json"
ansible new_node -m copy -a "src=/root/k8s/service/docker.service dest=/lib/systemd/system/docker.service mode=755"
ansible new_node -m shell -a "service docker restart"
ansible new_node -m shell -a "service docker status"
ansible new_node -m shell -a "cat /etc/docker/daemon.json"
echo "还原daemon.json模板文件"
sed -i s/$harbor_host/harbor_host/g /root/k8s/config/daemon.json_cpu
fi
!
###########################################################################################
###########################################################################################
ansible new_node -m copy -a
"src=/root/k8s/bin/kube-proxy dest=/opt/kubernetes/bin/ mode=777"
ansible new_node -m copy -a
"src=/root/k8s/bin/kube-proxy dest=/opt/kubernetes/bin/ mode=777"
ansible new_node -m copy -a
"src=/root/k8s/bin/kubelet dest=/opt/kubernetes/bin/ mode=777"
ansible new_node -m copy -a
"src=/root/k8s/bin/kubelet dest=/opt/kubernetes/bin/ mode=777"
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment