k8s部署比较复杂,有时候即使部署成功,后期运行也不太稳定。如果在部署过程中花费太多时间很容易打击学习k8s的积极性。现介绍一键部署k8s的安装过程,该安装包安装k8s之后,运行稳定,而且带有一些学习的案例,若可以深入读部署源码,学习到的知识会更多。
安装包下载地址:kube-install
本人也上传了安装包,kube-install-for-k8s1.21-v0.5.0.tgz
该安装包的源码大致了解了一下。采用Ansible自动化运维工具部署k8s,有兴趣的朋友可以自行研究一下ansible部署k8s的脚本,这里就不再拓开讲解了。
有资源的话,部署的服务器配置可以搞好一点的。我用自己的古董电脑做了三台虚拟机,配置比较低。
服务器配置:
kmaster79110 Centos7.4 192.168.79.110 4G/1核/100G
knodes79111 Centos7.4 192.168.79.111 4G/1核/100G
knodes79112 Centos7.4 192.168.79.112 4G/1核/100G
一、安装过程
[root@kmaster79110 ~]# tar -zxvf kube-install-for-k8s1.21-v0.5.0.tgz
[root@kmaster79110 ~]# cd kube-install/
[root@kmaster79110 kube-install]# ./kube-install --help
Usage of ./kube-install:
-master string
The IP address of k8s master server filled in for the first installation.
-node string
The IP address of k8s node server filled in for the first installation.
-opt string
Available options: init | install | addnode | delnode | rebuildmaster | delmaster | uninstall
-sshpwd string
The root password used to SSH login to each server.
[root@kmaster79110 kube-install]# ./kube-install
Version 0.5.0 (Creation Date: 5/10/2021)
Usage of kube-install: -opt [OPTIONS] COMMAND [ARGS]...
Options:
init Initialize the system environment.
install Install kubernetes cluster.
delnode Remove the k8s-node from the cluster.
addnode Add k8s-node to the cluster.
delmaster Remove the k8s-master from the cluster.
rebuildmaster Rebuild the damaged k8s-master.
uninstall Uninstall kubernetes cluster.
help Display help information.
Commands:
master The IP address of k8s-master server.
node The IP address of k8s-node server.
sshpwd The root password used to SSH login to each server.
For example:
Initialize the system environment:
kube-install -opt init
Install k8s cluster:
kube-install -opt install -master "192.168.1.11,192.168.1.12,192.168.1.13" -node "192.168.1.11,192.168.1.12,192.168.1.13,192.168.1.14" -sshpwd "cloudnativer"
Add k8s-node to the cluster:
kube-install -opt addnode -node "192.168.1.15,192.168.1.16" -sshpwd "cloudnativer"
Remove the k8s-node from the cluster:
kube-install -opt delnode -node "192.168.1.13,192.168.1.15" -sshpwd "cloudnativer"
Remove the k8s-master from the cluster:
kube-install -opt delmaster -master "192.168.1.13" -sshpwd "cloudnativer"
Rebuild the damaged k8s-master:
kube-install -opt rebuildmaster -master "192.168.1.13" -sshpwd "cloudnativer"
Uninstall k8s cluster:
kube-install -opt uninstall -master "192.168.1.11,192.168.1.12,192.168.1.13" -node "192.168.1.11,192.168.1.12,192.168.1.13,192.168.1.14" -sshpwd "cloudnativer"
Display help information:
kube-install -opt help
kube-install help
[root@kmaster79110 kube-install]#./kube-install -opt install -master "192.168.79.110" -node "192.168.79.110,192.168.79.111,192.168.79.112" -sshpwd "123456"
从上面的安装记录可以看到,该安装包支持增加节点,删除节点,修复主节点的功能。
二、效果展示
- 获取登录token:
[root@kmaster79110 kube-install]# cat /opt/kube-install/loginkey.txt
---------------------------------------------------------------
[1] Container image center address: 192.168.79.112:5000
usage method:
docker pull 192.168.79.112:5000/Your-image-name:Version
docker push 192.168.79.112:5000/Your-image-name:Version
---------------------------------------------------------------
[2] k8s dashboard console: https://192.168.79.110:50000
usage method:
Use the browser to log in and access. The token is as follows:
eyJhbGciOiJSUzI1NiIsImtpZCI6Imw4eHk2bndsSkc1dHRDdWloQ0NsZ3NJWnk0MHpBNU03THN6WmNuampXaE0ifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2Ui
OiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbi10b2tlbi13ajc2ZCIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50Lm5hbWUiOiJrdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjY3MTRlM2VmLWYwZDctNDc0My1hZTVmLWRhODE3NGUwMjk3NSIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDprdWJlLXN5c3RlbTprdWJlcm5ldGVzLWRhc2hib2FyZC1hZG1pbiJ9.JKtvuzCUO_htO8LIPTOxi5E2CVosk_Ia_cQEp1OvoGLbxEbP2nJ3ZkyBagAQJI46DoIx-OflhxDbWNHqmm9r1h93JLh8crQGWe5dQKZQ27P7PFw2AHv23nCfa-yP9woRvEmVKu2Y5IRqtcE1okykSbekOBJlRFTGnmz0Ef-W6qno1XP4orPYF93tiQUXESwiQiweJQpxJS_oaejuFEhHCHjr-u1jYjqzLV2BE-boVYjgg4GLzck3NIJBJustKjgkzHvktPoKN86Ryffc-IkaKbtsLl2C1XbcCDe3s3C4flsPMJW1NI0AP_MKUEBvIBmPnjAraG48hOL3WGoItJNZEg[root@kmaster79110 kube-install]#
登录:
若k8s界面不能打开,可以重新部署下界面:
[root@kmaster79110 dashboard]# kubectl apply -f kubernetes-dashboard-admin-rbac.yaml,kubernetes-dashboard-deployment.yaml,kubernetes-dashboard-rbac-minimal.yaml,kubernetes-dashboard-service.y
aml
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-admin unchanged
serviceaccount/kubernetes-dashboard-admin unchanged
deployment.apps/kube-dashboard unchanged
secret/kubernetes-dashboard-certs unchanged
serviceaccount/kubernetes-dashboard unchanged
role.rbac.authorization.k8s.io/kubernetes-dashboard-minimal unchanged
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard-minimal unchanged
service/kube-dashboard unchanged
[root@kmaster79110 dashboard]#
[root@kmaster79110 dashboard]# pwd
/opt/kube-install/addons/dashboard
[root@kmaster79110 dashboard]#
k8s部署就介绍到这里了,有什么不足之处请各位博主指出,一起交流学习。欢迎评论,转发,点赞~