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 896e5757
authored
Aug 15, 2020
by
tingweiwang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update add_node.sh
1 parent
2c93de0f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
18 deletions
script/k8s/add_node.sh
script/k8s/add_node.sh
View file @
896e575
...
@@ -6,24 +6,26 @@ new_node=(
...
@@ -6,24 +6,26 @@ new_node=(
192.168.1.58
192.168.1.58
)
#可以写多个node。每行一个。
)
#可以写多个node。每行一个。
interface
=
eno1
interface
=
eno1
###############配置节点免密###########
###############配置节点免密###########
################################################
port
=
22
port
=
22
password
=
seetatech
password
=
seetatech
for
ip
in
${
new_node
[@]
}
for
ip
in
${
new_node
[@]
}
do
do
sshpass -p
$password
ssh-copy-id -i ~/.ssh/id_rsa.pub -p
$port
-o
StrictHostKeyChecking
=
no root@
$ip
sshpass -p
$password
ssh-copy-id -i ~/.ssh/id_rsa.pub -p
$port
-o
StrictHostKeyChecking
=
no root@
$ip
done
done
##############根据new_node节点清单自动配置ansible hosts########
##############根据new_node节点清单自动配置ansible hosts########
########################
for
ansible_new_node
in
${
new_node
[@]
}
for
ansible_new_node
in
${
new_node
[@]
}
do
do
if
! grep -qF
"
$ansible_new_node
"
/etc
/hosts;
then
if
! grep -qF
"
$ansible_new_node
"
/etc/ansible
/hosts;
then
cat >>.
/hosts
<<EOF
cat >>/etc/ansible
/hosts
<<EOF
$ip
$ansible_new_node
EOF
EOF
else
echo
"您已配置该node:
$ip
信息到ansible hosts文件,已跳过该步骤"
else
echo
"您已配置该node:
$ansible_new_node
信息到ansible hosts文件,已跳过该步骤"
fi
fi
done
done
########################################
echo
"您有6s的时间,请确认当前ansible hosts为: "
cat /etc/ansible/hosts
&&
sleep 6
########################执行初始化脚本以及配置##########################################
ansible new_node -m script -a
"/root/k8s/script/k8s/backup/1-init.sh"
ansible new_node -m script -a
"/root/k8s/script/k8s/backup/1-init.sh"
ansible new_node -m shell -a
"mkdir /opt/kubernetes/{cfg,bin,ssl,log} -pv"
ansible new_node -m shell -a
"mkdir /opt/kubernetes/{cfg,bin,ssl,log} -pv"
scp /opt/kubernetes/ssl/ca
*
$new_node
:/opt/kubernetes/ssl/
scp /opt/kubernetes/ssl/ca
*
$new_node
:/opt/kubernetes/ssl/
...
@@ -70,10 +72,6 @@ ansible new_node -m copy -a "src=/root/k8s/service/kubelet.service dest=/lib/sys
...
@@ -70,10 +72,6 @@ ansible new_node -m copy -a "src=/root/k8s/service/kubelet.service dest=/lib/sys
ansible new_node -m copy -a
"src=/root/k8s/service/kubelet.service dest=/etc/systemd/system/ mode=777"
ansible new_node -m copy -a
"src=/root/k8s/service/kubelet.service dest=/etc/systemd/system/ mode=777"
ansible new_node -m copy -a
"src=/root/k8s/service/kube-proxy.service dest=/lib/systemd/system/ mode=777"
ansible new_node -m copy -a
"src=/root/k8s/service/kube-proxy.service dest=/lib/systemd/system/ mode=777"
ansible new_node -m shell -a
"systemctl daemon-reload"
ansible new_node -m shell -a
"systemctl daemon-reload"
#ansible new_node -m shell -a "systemctl enable kube-proxy.service"
#######################################anonyous权限#########################################
#kubectl create clusterrolebinding system:anonymous --clusterrole=cluster-admin --user=system:anonymous #如果不创建 执行Kubectl exec -it 没权限
#############################################################################################################
#根据你自己的token.csv中的token值进行设定,切记该文件中只有前面内容是token。
#根据你自己的token.csv中的token值进行设定,切记该文件中只有前面内容是token。
kubectl create clusterrolebinding kubelet-bootstrap --clusterrole
=
system:node-bootstrapper --user
=
kubelet-bootstrap
kubectl create clusterrolebinding kubelet-bootstrap --clusterrole
=
system:node-bootstrapper --user
=
kubelet-bootstrap
BOOTSTRAP_TOKEN
=
`
cat /opt/kubernetes/cfg/token.csv |awk -F
','
'{print $1}'
`
BOOTSTRAP_TOKEN
=
`
cat /opt/kubernetes/cfg/token.csv |awk -F
','
'{print $1}'
`
...
@@ -140,11 +138,8 @@ scp /opt/kubernetes/cfg/kube-proxy.$new_node_ip $new_node_ip:/opt/kubernetes/cfg
...
@@ -140,11 +138,8 @@ scp /opt/kubernetes/cfg/kube-proxy.$new_node_ip $new_node_ip:/opt/kubernetes/cfg
done
done
##################################################################################
##################################################################################
#ansible new_node -m shell -a "apt install -y ipvsadm ipset conntrack"
ansible new_node -m copy -a
"src=/root/k8s/ssl/kube-proxy.pem dest=/opt/kubernetes/ssl/"
ansible new_node -m copy -a
"src=/root/k8s/ssl/kube-proxy.pem dest=/opt/kubernetes/ssl/"
ansible new_node -m copy -a
"src=/root/k8s/ssl/kube-proxy-key.pem dest=/opt/kubernetes/ssl/"
ansible new_node -m copy -a
"src=/root/k8s/ssl/kube-proxy-key.pem dest=/opt/kubernetes/ssl/"
kubectl config
set
-cluster kubernetes
\
kubectl config
set
-cluster kubernetes
\
--certificate-authority
=
/opt/kubernetes/ssl/ca.pem
\
--certificate-authority
=
/opt/kubernetes/ssl/ca.pem
\
--embed-certs
=
true
\
--embed-certs
=
true
\
...
@@ -161,9 +156,7 @@ kubectl config set-context default \
...
@@ -161,9 +156,7 @@ kubectl config set-context default \
--cluster
=
kubernetes
\
--cluster
=
kubernetes
\
--user
=
kube-proxy
\
--user
=
kube-proxy
\
--kubeconfig
=
kube-proxy.kubeconfig
--kubeconfig
=
kube-proxy.kubeconfig
kubectl config use-context default --kubeconfig
=
kube-proxy.kubeconfig
kubectl config use-context default --kubeconfig
=
kube-proxy.kubeconfig
ansible new_node -m copy -a
"src=/root/k8s/script/k8s/kube-proxy.kubeconfig dest=/opt/kubernetes/cfg/"
ansible new_node -m copy -a
"src=/root/k8s/script/k8s/kube-proxy.kubeconfig dest=/opt/kubernetes/cfg/"
ansible new_node -m shell -a
"service kube-proxy restart"
ansible new_node -m shell -a
"service kube-proxy restart"
ansible new_node -m shell -a
"service kubelet restart"
ansible new_node -m shell -a
"service kubelet restart"
...
@@ -171,6 +164,6 @@ ansible new_node -m shell -a "service kubelet status"
...
@@ -171,6 +164,6 @@ ansible new_node -m shell -a "service kubelet status"
sleep 5
sleep 5
kubectl get csr
kubectl get csr
kubectl get csr|grep
'Pending'
| awk
'NR>0{print $1}'
| xargs kubectl certificate approve
kubectl get csr|grep
'Pending'
| awk
'NR>0{print $1}'
| xargs kubectl certificate approve
#######################开机启动################################
#######################开机启动################################
#############################
ansible new_node -m shell -a
"systemctl enable kubelet.service"
ansible new_node -m shell -a
"systemctl enable kubelet.service"
ansible new_node -m shell -a
"systemctl enable kube-proxy.service"
ansible new_node -m shell -a
"systemctl enable kube-proxy.service"
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