ansible一键安装k8s1.10x_and_k8s1.11x

作者:xiaotian45123

1: 前置系统说明
1:主机系统:CentOS Linux release 7.5.1804 (Core)
2:系统只配置了IP,并且能联网,其他无任何配置
3ansible服务器已经和所有节点做了root用户免密码登陆
4: 所有执行均采用root用户
5github下载地址:https://github.com/xiaotian45123/ansible-k8s10x_and_k8s11x
6:安装测试通过的K8S版本有:1.10.31.10.41.10.51.11.01.11.1,其他版本请大家自行测试
7:在阿里云不能使用阿里云得SLB服务代替keepalived+haproxy,因为阿里云的SLB不支持后端真实服务器既做服务端又做客户端,我研究过阿里云K8S部署脚本,阿里云SLB只做node节点kebelet访问master的负载功能
8:本ansible一键安装可用于生产环境
9:同时欢迎大家改进并提交到github,这个我后期一直会维护,由于不太会用github,所以大家有问题也可以先留言

主机名称     	IP	                备注
node01	192.168.150.181	        master  and etcd
node02	192.168.150.182	        master  and etcd
node03	192.168.150.183	        master  and etcd
node04	192.168.150.184	        node
slb-179	192.168.150.179       	haproxy+keepalived
slb-180	192.168.150.180	        haproxy+keepalived
	    192.168.150.186	            VIP


2: /etc/ansible/hosts文件解释

[slb]
192.168.150.179 name=slb-179 type=MASTER priority=100
192.168.150.180 name=slb-180 type=BACKUP priority=90

[k8s-master]
192.168.150.181 name=node01 order=1
192.168.150.182 name=node02 order=2
192.168.150.183 name=node03 order=3

[k8s-node]
192.168.150.184 name=node04

[k8s-all:children]
k8s-master
k8s-node

[all:vars] 
local_images=registry.cn-hangzhou.aliyuncs.com/k8sth
k8s_version=1.11.0
vip=192.168.150.186

#type表示keepalived的类型是master或者backp
#priority代表权重,可以自行修改,但是不建议修改,直接修改IP为合适的就行
#name为主机名称,可以自行修改,在系统初始化时会以此添加并配置所有主机的/etc/hosts文件
#orderk8s初始化的顺序,不能修改
#local_images为镜像地址,本人镜像地址包含1.10.0--1.11.1所有的K8S镜像,所以可以不用修改,如果用局域网内部仓库,必须是https
#k8s_version为需要安装的kubernetes版本号

3: roles文件说明,

[root@ansible roles]# ll
total 16
drwxr-xr-x 7 root root  77 Aug  6 22:50 addnode
drwxr-xr-x 7 root root  77 Jul 31 16:40 basic
drwxr-xr-x 7 root root  77 Aug  6 17:59 docker_kubeadm
drwxr-xr-x 7 root root  77 Aug  6 11:49 etcd
-rw-r--r-- 1 root root 206 Aug  7 21:01 first.yaml
drwxr-xr-x 7 root root  77 Jul 31 16:40 flannel
drwxr-xr-x 7 root root  77 Jul 31 16:40 haproxy
drwxr-xr-x 7 root root  77 Aug  6 21:25 k8s10x
drwxr-xr-x 7 root root  77 Jul 31 16:40 k8s11x
drwxr-xr-x 7 root root  77 Jul 31 16:40 keepalived
drwxr-xr-x 7 root root  77 Aug  6 19:53 kernelup
-rw-r--r-- 1 root root 169 Aug  7 01:13 kernelup.yaml
-rw-r--r-- 1 root root 397 Aug  7 21:00 onekey.yaml
-rw-r--r-- 1 root root 222 Aug  7 21:02 two.yaml

#kernelup.yamlkernel升级的yaml文件,建议将需要安装k8s的所有节点内核都升级,避乱一些不必要的问题
#onekey.yaml是在所有节点只配置好IP的情况下,一键安装整个K8S集群(ansible控制节点免密码登陆所有节点必须提前配置好)
#first.yamltwo.yamlonekey.yaml的拆分文件,因为onekey.yaml运行输出信息太多,在定位问题时候不好排查,所以进行了拆分

4: 执行顺序说明

4.1: 升级K8S节点的kernel,非必须操作,但是建议
[root@ansible ~]# ansible-playbook /etc/ansible/roles/kernelup.yaml

#执行此命令后,结果会有个报错,这是正常的,因为在kernel升级完成后必须得重启系统才能使用新得kernerl,系统重启后ansible不能接收到init6得执行结果,所以会报错,大家此时可以看看k8s所有节点得kernel是不是最新的
4.2: first.yaml
执行如下命令

ansible-playbook /etc/ansible/roles/first.yaml  

#命令做了如下操作
#1:所有主机初始化系统,安装基本软件
#2:所有主机关闭selinuxfirewalld、关闭swap
#3:所有主机设置主机名称、分发/etc/hosts文件、设置ulimit、开发forward
#4: slb主机组安装配置haproxykeepalived
#5: master节点安装etcd集群,未采用https的集群

#执行结果如下:
PLAY RECAP *****************************************************************************************************************************
192.168.150.179            : ok=19   changed=18   unreachable=0    failed=0   
192.168.150.180            : ok=19   changed=18   unreachable=0    failed=0   
192.168.150.181            : ok=16   changed=15   unreachable=0    failed=0   
192.168.150.182            : ok=16   changed=15   unreachable=0    failed=0   
192.168.150.183            : ok=16   changed=15   unreachable=0    failed=0   
192.168.150.184            : ok=12   changed=11   unreachable=0    failed=0 

4.3: two.yaml

执行如下命令

ansible-playbook /etc/ansible/roles/two.yaml

#命令做了如下操作
#1:安装docker,版本为K8S官方推荐的17.3
#2:安装kubeadm版本根据/etc/ansible/hosts来定,yum源采用的是阿里云的
#3:根据k8s版本初始K8S集群,/etc/ansible/hostsorder变量决定初始化顺序,当初始化失败的时候整个初始化集群过程将终止
#4:添加flannel网络,需要使用其他网络的在two.yaml里面将flannel这个role注释掉,在集群安装完成后自行添加
#5:将node节点添加进集群

执行结果如下:
PLAY RECAP *****************************************************************************************************************************
192.168.150.181            : ok=23   changed=21   unreachable=0    failed=0   
192.168.150.182            : ok=18   changed=17   unreachable=0    failed=0   
192.168.150.183            : ok=18   changed=17   unreachable=0    failed=0   
192.168.150.184            : ok=13   changed=12   unreachable=0    failed=0 

在主机node01上面的结果如下:(由于网络下载速度的原因,可能得等个2分钟才能看到如下结果)

[root@node01 ~]# kubectl get pod --all-namespaces -o wide
NAMESPACE     NAME                             READY     STATUS    RESTARTS   AGE       IP                NODE
kube-system   coredns-86d9549d45-7fpsr         1/1       Running   0          9m        10.244.3.3        node04
kube-system   coredns-86d9549d45-l7w8x         1/1       Running   0          9m        10.244.3.2        node04
kube-system   kube-apiserver-node01            1/1       Running   0          8m        192.168.150.181   node01
kube-system   kube-apiserver-node02            1/1       Running   0          9m        192.168.150.182   node02
kube-system   kube-apiserver-node03            1/1       Running   0          9m        192.168.150.183   node03
kube-system   kube-controller-manager-node01   1/1       Running   0          9m        192.168.150.181   node01
kube-system   kube-controller-manager-node02   1/1       Running   0          9m        192.168.150.182   node02
kube-system   kube-controller-manager-node03   1/1       Running   0          9m        192.168.150.183   node03
kube-system   kube-flannel-ds-amd64-ht2dk      1/1       Running   0          9m        192.168.150.181   node01
kube-system   kube-flannel-ds-amd64-pjxvm      1/1       Running   0          9m        192.168.150.183   node03
kube-system   kube-flannel-ds-amd64-qsmql      1/1       Running   0          9m        192.168.150.184   node04
kube-system   kube-flannel-ds-amd64-wjv4g      1/1       Running   0          9m        192.168.150.182   node02
kube-system   kube-proxy-2z5rq                 1/1       Running   0          9m        192.168.150.181   node01
kube-system   kube-proxy-98scf                 1/1       Running   0          9m        192.168.150.183   node03
kube-system   kube-proxy-jx58c                 1/1       Running   0          9m        192.168.150.184   node04
kube-system   kube-proxy-vgzbj                 1/1       Running   0          9m        192.168.150.182   node02
kube-system   kube-scheduler-node01            1/1       Running   0          8m        192.168.150.181   node01
kube-system   kube-scheduler-node02            1/1       Running   0          9m        192.168.150.182   node02
kube-system   kube-scheduler-node03            1/1       Running   0          9m        192.168.150.183   node03
4.4:安装方法总结

一:拆分安装

ansible-playbook /etc/ansible/roles/kernelup.yaml
#kernel升级非必须,但是建议升级
ansible-playbook /etc/ansible/roles/first.yaml
ansible-playbook /etc/ansible/roles/two.yaml

二:一键安装

ansible-playbook /etc/ansible/roles/kernelup.yaml
#kernel升级非必须,但是建议升级
ansible-playbook /etc/ansible/roles/onekey.yaml
K8S中文社区微信公众号

评论 34

登录后评论

立即登录  

  1. #20

    牛,一大早就看到这样的文章,果断收藏下载研究研究。

    liudan1826年前 (2018-08-09)
  2. #19

    你好请问ansible文件在哪

    拖拉机6年前 (2018-08-10)
  3. #18

    你好,在执行脚本第二步的时候tar /etc/kubernetes/打包证书的时候找不到admin.conf等一系列证书

    ikube6年前 (2018-08-10)
    • 那就应该是初始化失败了,贴一下初始化信息

      test6年前 (2018-08-11)
  4. #17

    有没有ubuntu的一键安装啊?

    菜鸟专家6年前 (2018-08-14)
    • 我一直用的是centos,ubuntu没玩过,我都不想说我干这行7年了

      test6年前 (2018-08-15)
  5. #16

    没用过haproxy,请问可以用NGINX代替proxy么

    elysium_H6年前 (2018-08-16)
  6. #15

    您好,我设置master运行容器时成功,报“net/http: TLS handshake timeout”,您这有这样的错误输出过吗?

    jackchu6年前 (2018-08-16)
    • 你是用的阿里云吗?

      test6年前 (2018-08-16)
      • 不是的,我用的是本地KVM虚拟机,在KVM里面安装K8S.具体情况是这样。在ansible playbook执行roles/k8s11x/tasks/main.yaml中”设置master运行容器”项时,错误返回为“net/http: TLS handshake timeout”,此时我kubectl get pods 也是 timeout。message日志显示“Unable to update cni config: No networks found in /etc/cni/net.d 和Container runtime network not ready: NetworkReady=false”,网查得知是CNI网络插件的事,可是并没有到flannel网络安装这一步,所以想问您,麻烦了!

        jackchu6年前 (2018-08-16)
        • No networks found in /etc/cni/net.d 这个问题是因为没有部署flannel网络,这个是正常的,在部署完毕flannel后就不会报这个错了。
          kubectl get pods 也是 timeout这个一般是连接不上kube-apiserver导致,一般是kube-apiserver容器没起来,或者是keepalived+haproxy没装好导致不能使用VIP,ansible部署的时候报错信息上下文贴出来

          test6年前 (2018-08-20)
  7. #14

    vip 是阿里云的一个服务吗? 还是另一台机器的 ip?

    tobyfan6年前 (2018-08-17)
    • VIP是另外的IP,不是阿里云的SLB

      test6年前 (2018-08-20)
  8. #13

    你好,我这里只有一个节点有大网IP,且可以用代理访问阿里云。其他8个节点都是内网IP。这种情况下负载均衡的IP要如何配置

    码农白兰度6年前 (2018-08-20)
    • 这个负载均衡VIP是内网IP,只要这8个节点能联网下载镜像就可以正常安装成功,如果这8个节点不能联网下载镜像,你就只能自建镜像仓库了,但是镜像仓库必须是https得

      test6年前 (2018-08-21)
      • [root@master-etcd-01 docker.service.d]# kubeadm config images pull –config /root/kubeadm-config.yaml
        [endpoint] WARNING: port specified in api.controlPlaneEndpoint overrides api.bindPort in the controlplane address
        failed to pull image “registry.cn-hangzhou.aliyuncs.com/k8sth/kube-apiserver-amd64:v1.11.2”: exit status 1
        拉取镜像的时候有这个报错,所在节点无法直接访问外网,我做了代理,是否有影响?

        码农白兰度6年前 (2018-08-21)
        • 1.11.2镜像我还没添加进仓库

          test6年前 (2018-08-22)
  9. #12

    安装之后 master 节点 ok. worker 节点 status 是 notready. 我登录上去 用 journalctl -u kubelet 看到 错误 “Container runtime network not ready: NetworkReady=false reason:NetworkPluginNotReady” 我需要单独安装网络吗?

    tobyfan6年前 (2018-08-28)
    • 不用,worker节点是notready,是因为worker节点的flanal网络容器还没运行完,等几分钟就好了

      test6年前 (2018-09-04)
  10. #11

    你好,在执行脚本第二步的时候tar /etc/kubernetes/打包证书的时候找不到admin.conf等一系列证书,报错如下:fatal: [192.168.1.190]: FAILED! => {“changed”: true, “cmd”: “cd /etc/kubernetes && tar czf pki1.11.0.tgz admin.conf pki/ca.* pki/sa.* pki/front-proxy-ca.*”, “delta”: “0:00:00.080944”, “end”: “2018-09-04 01:57:04.769260”, “msg”: “non-zero return code”, “rc”: 2, “start”: “2018-09-04 01:57:04.688316”, “stderr”: “tar: admin.conf: Cannot stat: No such file or directory\ntar: pki/ca.*: Cannot stat: No such file or directory\ntar: pki/sa.*: Cannot stat: No such file or directory\ntar: pki/front-proxy-ca.*: Cannot stat: No such file or directory\ntar: Exiting with failure status due to previous errors”, “stderr_lines”: [“tar: admin.conf: Cannot stat: No such file or directory”, “tar: pki/ca.*: Cannot stat: No such file or directory”, “tar: pki/sa.*: Cannot stat: No such file or directory”, “tar: pki/front-proxy-ca.*: Cannot stat: No such file or directory”, “tar: Exiting with failure status due to previous errors”], “stdout”: “”, “stdout_lines”: []}

    tiger6年前 (2018-09-04)
    • 初始化失败才会出现找不到证书的情况

      test6年前 (2018-09-05)
  11. #10

    请问一下,为什么需要安装slb ?

    yangyang6年前 (2018-09-12)
  12. #9

    请教: k8s_version.startswith 这个变量是怎么来的啊? 如何判断1.10还是1.11版本呢?

    flj6年前 (2018-09-26)
  13. #8

    我执行ansible的时候报错,k8s_token异常,请大神指点,谢谢您了。
    TASK [addnode : add node to k8s cluster] **********************************************************************
    fatal: [192.168.10.16]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘k8s_token’\n\nThe error appears to have been in ‘/etc/ansible/roles/addnode/tasks/main.yaml’: line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: add node to k8s cluster\n ^ here\n\nexception type: \nexception: ‘dict object’ has no attribute ‘k8s_token'”}
    fatal: [192.168.10.17]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘k8s_token’\n\nThe error appears to have been in ‘/etc/ansible/roles/addnode/tasks/main.yaml’: line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: add node to k8s cluster\n ^ here\n\nexception type: \nexception: ‘dict object’ has no attribute ‘k8s_token'”}
    to retry, use: –limit @/etc/ansible/roles/onekey.retry

    k8sfins6年前 (2018-09-27)
  14. #7

    [root@node02 ~]# kubectl logs -f kubernetes-dashboard-6b69c77b8f-bfwft -n kube-system
    2018/10/12 08:49:45 Starting overwatch
    2018/10/12 08:49:45 Using apiserver-host location: http://10.192.61.186:58080
    2018/10/12 08:49:45 Skipping in-cluster config
    2018/10/12 08:49:45 Using random key for csrf signing
    2018/10/12 08:49:45 No request provided. Skipping authorization
    2018/10/12 08:49:45 Error while initializing connection to Kubernetes apiserver. This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service accounts configuration) or the –apiserver-host param points to a server that does not exist. Reason: an error on the server (“503 Service Unavailable\nNo server is available to handle this request.\n”) has prevented the request from succeeding

    peaoguoxu6年前 (2018-10-12)
  15. #6

    安装图形管理化界面的时候报错

    peaoguoxu6年前 (2018-10-12)
  16. #5

    这个VIP到底是啥,如果是自建机房,这里该如何设置?

    零零一6年前 (2018-10-13)
  17. #4

    [root@localhost ~]# ansible-playbook /etc/ansible/roles/two.yaml
    [DEPRECATION WARNING]: DEFAULT_SUDO_USER option, In favor of become which is a generic framework . This feature will be removed in
    version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

    PLAY [k8s-all] ********************************************************************************************************************

    TASK [Gathering Facts] ************************************************************************************************************
    ok: [192.168.150.181]
    ok: [192.168.150.184]
    ok: [192.168.150.182]
    ok: [192.168.150.183]

    TASK [docker_kubeadm : 下载docker-selinux] ******************************************************************************************
    changed: [192.168.150.184]
    changed: [192.168.150.181]
    changed: [192.168.150.183]
    changed: [192.168.150.182]

    TASK [docker_kubeadm : 下载docker] **************************************************************************************************
    changed: [192.168.150.181]
    changed: [192.168.150.183]
    changed: [192.168.150.182]
    changed: [192.168.150.184]

    TASK [docker_kubeadm : 安装docker17.3] **********************************************************************************************
    [WARNING]: Consider using yum module rather than running yum

    changed: [192.168.150.184]
    changed: [192.168.150.182]
    changed: [192.168.150.183]
    changed: [192.168.150.181]

    TASK [docker_kubeadm : 修改配置文件/usr/lib/systemd/system/docker.service] **************************************************************
    changed: [192.168.150.184]
    changed: [192.168.150.181]
    changed: [192.168.150.183]
    changed: [192.168.150.182]

    TASK [docker_kubeadm : 设置docker自启动] ***********************************************************************************************
    changed: [192.168.150.184]
    changed: [192.168.150.182]
    changed: [192.168.150.181]
    changed: [192.168.150.183]

    TASK [docker_kubeadm : 添加阿里云K8S源] *************************************************************************************************
    changed: [192.168.150.182]
    changed: [192.168.150.181]
    changed: [192.168.150.184]
    changed: [192.168.150.183]

    TASK [docker_kubeadm : 安装kubeadm1.11.1] *******************************************************************************************
    changed: [192.168.150.183] => (item=[u’kubeadm-1.11.1-0.x86_64′, u’kubectl-1.11.1-0.x86_64′, u’kubelet-1.11.1-0.x86_64′])
    changed: [192.168.150.184] => (item=[u’kubeadm-1.11.1-0.x86_64′, u’kubectl-1.11.1-0.x86_64′, u’kubelet-1.11.1-0.x86_64′])
    changed: [192.168.150.181] => (item=[u’kubeadm-1.11.1-0.x86_64′, u’kubectl-1.11.1-0.x86_64′, u’kubelet-1.11.1-0.x86_64′])
    changed: [192.168.150.182] => (item=[u’kubeadm-1.11.1-0.x86_64′, u’kubectl-1.11.1-0.x86_64′, u’kubelet-1.11.1-0.x86_64′])

    TASK [docker_kubeadm : kubectl命令补全] ***********************************************************************************************
    changed: [192.168.150.181]
    changed: [192.168.150.183]
    changed: [192.168.150.182]
    changed: [192.168.150.184]

    TASK [k8s10x : 修改10-kubeadm.conf的cgroupfs] ****************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 修改10-kubeadm.conf的cgroupfs] ****************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 设置kubelet自启动] ******************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 分发配置文件] ************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : pull pause-amd64:3.1] *********************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 初始化第一个master节点,如果失败会终止整个k8s集群的初始化] *********************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 证书打包] **************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 证书上传到/etc/ansible/roles/k8s/files/] ********************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 证书cp] **************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : 解压证书] **************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : kubeadm init] ******************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s10x : inited] ************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [k8s11x : 修改 /etc/sysconfig/kubelet] *****************************************************************************************
    changed: [192.168.150.181]
    changed: [192.168.150.184]
    changed: [192.168.150.182]
    changed: [192.168.150.183]

    TASK [k8s11x : 设置kubelet自启动] ******************************************************************************************************
    changed: [192.168.150.183]
    changed: [192.168.150.181]
    changed: [192.168.150.182]
    changed: [192.168.150.184]

    TASK [k8s11x : 配置文件分发] ************************************************************************************************************
    skipping: [192.168.150.184]
    changed: [192.168.150.183]
    changed: [192.168.150.182]
    changed: [192.168.150.181]

    TASK [k8s11x : 配置文件提前拉取镜像] ********************************************************************************************************
    skipping: [192.168.150.184]
    changed: [192.168.150.183]
    changed: [192.168.150.182]
    changed: [192.168.150.181]

    TASK [k8s11x : pause-amd64:3.1镜像bug处理] ********************************************************************************************
    changed: [192.168.150.181]
    changed: [192.168.150.183]
    changed: [192.168.150.182]
    changed: [192.168.150.184]

    TASK [k8s11x : pause-amd64:3.1镜像bug处理] ********************************************************************************************
    changed: [192.168.150.184]
    changed: [192.168.150.181]
    changed: [192.168.150.183]
    changed: [192.168.150.182]

    TASK [k8s11x : kubeadm初始化,如果失败会终止整个k8s集群的初始化] *************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    changed: [192.168.150.181]

    TASK [k8s11x : 证书打包] **************************************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    changed: [192.168.150.181]

    TASK [k8s11x : 证书上传到/etc/ansible/roles/k8s/files/] ********************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    changed: [192.168.150.181]

    TASK [k8s11x : 证书cp] **************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.184]
    changed: [192.168.150.182]
    changed: [192.168.150.183]

    TASK [k8s11x : 解压证书] **************************************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.184]
    changed: [192.168.150.182]
    changed: [192.168.150.183]

    TASK [k8s11x : kubeadm init其他master] **********************************************************************************************
    skipping: [192.168.150.181]
    skipping: [192.168.150.184]
    changed: [192.168.150.183]
    changed: [192.168.150.182]

    TASK [k8s11x : inited] ************************************************************************************************************
    skipping: [192.168.150.184]
    [WARNING]: Consider using file module with state=directory rather than running mkdir

    changed: [192.168.150.182]
    changed: [192.168.150.183]
    changed: [192.168.150.181]

    TASK [k8s11x : 设置master运行容器] ******************************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    changed: [192.168.150.181]

    TASK [flannel : down flannel.yaml] ************************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    changed: [192.168.150.181]

    TASK [flannel : deploy flannel] ***************************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    fatal: [192.168.150.181]: FAILED! => {“changed”: true, “cmd”: “kubectl apply -f /root/kube-flannel.yml”, “delta”: “0:00:52.136940”, “end”: “2018-11-02 11:28:07.527905”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2018-11-02 11:27:15.390965”, “stderr”: “error: error when creating \”/root/kube-flannel.yml\”: Post https://192.168.150.186:6443/apis/extensions/v1beta1/namespaces/kube-system/daemonsets: unexpected EOF; some request body already written”, “stderr_lines”: [“error: error when creating \”/root/kube-flannel.yml\”: Post https://192.168.150.186:6443/apis/extensions/v1beta1/namespaces/kube-system/daemonsets: unexpected EOF; some request body already written”], “stdout”: “clusterrole.rbac.authorization.k8s.io/flannel created\nclusterrolebinding.rbac.authorization.k8s.io/flannel created\nserviceaccount/flannel created\nconfigmap/kube-flannel-cfg created\ndaemonset.extensions/kube-flannel-ds-amd64 created\ndaemonset.extensions/kube-flannel-ds-arm64 created\ndaemonset.extensions/kube-flannel-ds-arm created\ndaemonset.extensions/kube-flannel-ds-ppc64le created”, “stdout_lines”: [“clusterrole.rbac.authorization.k8s.io/flannel created”, “clusterrolebinding.rbac.authorization.k8s.io/flannel created”, “serviceaccount/flannel created”, “configmap/kube-flannel-cfg created”, “daemonset.extensions/kube-flannel-ds-amd64 created”, “daemonset.extensions/kube-flannel-ds-arm64 created”, “daemonset.extensions/kube-flannel-ds-arm created”, “daemonset.extensions/kube-flannel-ds-ppc64le created”]}

    TASK [addnode : kubeadm token] ***************************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [addnode : 设置变量k8s_token为set_fact] *******************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]

    TASK [addnode : add node to k8s cluster] ******************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    fatal: [192.168.150.184]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘k8s_token’\n\nThe error appears to have been in ‘/etc/ansible/roles/addnode/tasks/main.yaml’: line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: add node to k8s cluster\n ^ here\n\nexception type: \nexception: ‘dict object’ has no attribute ‘k8s_token'”}
    to retry, use: –limit @/etc/ansible/roles/two.retry

    PLAY RECAP ************************************************************************************************************************
    192.168.150.181 : ok=21 changed=20 unreachable=0 failed=1
    192.168.150.182 : ok=19 changed=18 unreachable=0 failed=0
    192.168.150.183 : ok=19 changed=18 unreachable=0 failed=0
    192.168.150.184 : ok=13 changed=12 unreachable=0 failed=1
    这个是要怎么解决呢

    lucky6年前 (2018-11-02)
  18. #3

    TASK [flannel : deploy flannel] ***************************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    skipping: [192.168.150.184]
    fatal: [192.168.150.181]: FAILED! => {“changed”: true, “cmd”: “kubectl apply -f /root/kube-flannel.yml”, “delta”: “0:00:52.136940”, “end”: “2018-11-02 11:28:07.527905”, “msg”: “non-zero return code”, “rc”: 1, “start”: “2018-11-02 11:27:15.390965”, “stderr”: “error: error when creating \”/root/kube-flannel.yml\”: Post https://192.168.150.186:6443/apis/extensions/v1beta1/namespaces/kube-system/daemonsets: unexpected EOF; some request body already written”, “stderr_lines”: [“error: error when creating \”/root/kube-flannel.yml\”: Post https://192.168.150.186:6443/apis/extensions/v1beta1/namespaces/kube-system/daemonsets: unexpected EOF; some request body already written”], “stdout”: “clusterrole.rbac.authorization.k8s.io/flannel created\nclusterrolebinding.rbac.authorization.k8s.io/flannel created\nserviceaccount/flannel created\nconfigmap/kube-flannel-cfg created\ndaemonset.extensions/kube-flannel-ds-amd64 created\ndaemonset.extensions/kube-flannel-ds-arm64 created\ndaemonset.extensions/kube-flannel-ds-arm created\ndaemonset.extensions/kube-flannel-ds-ppc64le created”, “stdout_lines”: [“clusterrole.rbac.authorization.k8s.io/flannel created”, “clusterrolebinding.rbac.authorization.k8s.io/flannel created”, “serviceaccount/flannel created”, “configmap/kube-flannel-cfg created”, “daemonset.extensions/kube-flannel-ds-amd64 created”, “daemonset.extensions/kube-flannel-ds-arm64 created”, “daemonset.extensions/kube-flannel-ds-arm created”, “daemonset.extensions/kube-flannel-ds-ppc64le created”]}

    lucky6年前 (2018-11-02)
  19. #2

    TASK [addnode : add node to k8s cluster] ******************************************************************************************
    skipping: [192.168.150.182]
    skipping: [192.168.150.183]
    fatal: [192.168.150.184]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘k8s_token’\n\nThe error appears to have been in ‘/etc/ansible/roles/addnode/tasks/main.yaml’: line 11, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: add node to k8s cluster\n ^ here\n\nexception type: \nexception: ‘dict object’ has no attribute ‘k8s_token'”}
    to retry, use: –limit @/etc/ansible/roles/two.retry

    lucky6年前 (2018-11-02)
  20. #1

    我也遇到行脚本第二步的时候tar /etc/kubernetes/打包证书的时候找不到admin.conf等一系列证书,请问您说的初始化失败指的是文中哪一步呢

    gulf6年前 (2019-03-22)