小言_互联网的博客

离线方式部署kubernetes 1.16.0

243人阅读  评论(0)

Kubernetes在2019年9月18日发布了年度的第三个版本1.16,这篇文章介绍一下如何使用Easypack的Ansible脚本方式在CentOS7上完成Kubernetes的一键安装。

环境构成说明

设定项 详细信息
构成 一主一从(同一台机器)
IP 192.168.163.132
网卡名称 enp0s3
Kubernetes 1.16.0
Docker 18.09.7
ETCD 3.3.13
FLANNEL 0.10.0

安装步骤

步骤1:下载easypack

[root@host132 tmp]# git clone https://github.com/liumiaocn/easypack.git
Cloning into ‘easypack’…
…省略
[root@host132 tmp]#

步骤2: 下载相关离线二进制文件

详细可参看:

  • https://liumiaocn.blog.csdn.net/article/details/96421940

注:目前直接使用download的role,会下载并打包生成1.15的kubernetes相关的二进制文件,然后手动下载kubernetes的二进制文件进行替换即可,下载目录为:

  • https://dl.k8s.io/v1.16.0/kubernetes-server-linux-amd64.tar.gz

步骤3: 调整配置

只需要修改common_vars.yml的如下两处设定即可

设定项 设定参数 设定值
var_all_in_one_hostip Master节点IP地址 192.168.163.132
var_flannel_opt_iface 网卡名称 enp0s3

步骤4: 一键安装

前提条件

  • 条件1: 安装ansible,建议版本2.4.2.0或以上
  • 条件2: 本机连接的ssh设定完毕,简单来说ssh-copy-id 192.168.163.132(请使用本机IP)执行完成

安装命令:
ansible-playbook 10.all-in-one.yml

安装示例

[root@host132 ansible]# ansible-playbook 10.all-in-one.yml 

PLAY [all-in-one] **********************************************************************************************************************

TASK [clean : stop etcd service] *******************************************************************************************************
...省略
TASK [dashboard : create clusterrolebinding for dashboard] *****************************************************************************
changed: [localhost]

PLAY RECAP *****************************************************************************************************************************
localhost                  : ok=103  changed=95   unreachable=0    failed=0   

[root@host132 ansible]#

结果确认

版本确认

[root@host132 ansible]# kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:36:53Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.0", GitCommit:"2bd9643cee5b3b3a5ecbd3af49d09018f0773c77", GitTreeState:"clean", BuildDate:"2019-09-18T14:27:17Z", GoVersion:"go1.12.9", Compiler:"gc", Platform:"linux/amd64"}
[root@host132 ansible]#

节点确认

[root@host132 ansible]# kubectl get node -o wide
NAME              STATUS   ROLES    AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE                KERNEL-VERSION          CONTAINER-RUNTIME
192.168.163.132   Ready    <none>   81s   v1.16.0   192.168.163.132   <none>        CentOS Linux 7 (Core)   3.10.0-957.el7.x86_64   docker://18.9.7
[root@host132 ansible]# 

coredns与dashboard服务确认

[root@host132 ansible]# kubectl get services -n kube-system
NAME                   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)         AGE
kube-dns               ClusterIP   10.254.0.2     <none>        53/UDP,53/TCP   2m15s
kubernetes-dashboard   NodePort    10.254.28.13   <none>        443:33307/TCP   110s
[root@host132 ansible]# 
[root@host132 ansible]# kubectl get pods -n kube-system
NAME                                    READY   STATUS    RESTARTS   AGE
coredns-59db588569-mx6vw                1/1     Running   0          2m24s
kubernetes-dashboard-7c54d59f66-l2pqx   1/1     Running   0          119s
[root@host132 ansible]# 

dashboard的token确认

[root@host132 ansible]# dashboard_secret=`kubectl get secrets -n kube-system | grep dashboard-admin | awk '{print $1}'`
[root@host132 ansible]# kubectl describe secret -n kube-system ${dashboard_secret} | grep -E '^token' | awk '{print $2}'
eyJhbGciOiJSUzI1NiIsImtpZCI6Imt2OG1UdHFzT0t5Tnp6VjRtNlZORmt6Tk5LRzhFRG01WTlXaU16LUVZNFkifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJkYXNoYm9hcmQtYWRtaW4tdG9rZW4tNzdsbDgiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoiZGFzaGJvYXJkLWFkbWluIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiZDk1NmJjYzItN2ZiNS00NDdmLThlNWEtNjM3ZTQ2NmNkOTc3Iiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50Omt1YmUtc3lzdGVtOmRhc2hib2FyZC1hZG1pbiJ9.sImW-gcsHr7NJjEbIOOO1TRB0ZlF-CFRb9AXq8O38qf9E0xSZPUXeRFf8i9AST1HDZn8ugAv77TVtzj8AJaL4hxz6LylQpjhkpBxkpRMA7A7V8nhaYPxSvZUJBSpj_h2NcXNrpj7m0_V0axk9VguE_kcuTWlr2sR7x35Xmf-lxWS0yQAUkvaX26F59IBVCXZ2_A5cHWbfBvufBcGPrhKuVfJiHTUyDLha37Ze1OCCsPJP-HDnwniJsdIac89M9w9QZ1qNrtRXAlKLN24pXg_Ki5dkmYU4ImkF4YRsHAfzqkmaYHc-UoKUzJET1UqjHyqKoK64JuNHeer4RwADBF7CQ
[root@host132 ansible]#

dashboard确认

使用https://localhost:33307登陆dashboard界面,选择token方式,并粘贴上述token信息

登陆之后即可看到dashboard可视化界面展示的Kubernetes相关的信息

常见问题

  • https://liumiaocn.blog.csdn.net/article/details/101028946

转载:https://blog.csdn.net/liumiaocn/article/details/101034161
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场