利用kubeadm-ansible创建kubernetes集群出错

  • 系统版本:CentOS7.5

  • 运行环境:localhost

  • 遇到问题时的前置条件:
    执行命令:
    ansible-playbook -i inventory/hosts -e @inventory/vars cluster.yml

  • 问题描述:

    在利用kubeadm-ansible部署单节点的k&s时遇到了请求打开8080端口的请求,但在利用kubectl代理打开8080端口后却又显示连接不上8080端口。

  • 修改的数据:

在使用kubeadm-ansible的过程中仅对路径/inventory/下的hosts文件进行了修改。修改内容如下:

kubectl打开8080端口命令:kubectl proxy --port=8080 &
(开启后已确认端口是打开的,部署过程中8080端口为打开的错误提示也没有出现了,但部署过程中会卡死,最后端口会被关闭)
打开端口后再次执行部署命令则出现以下失败信息,最后卡死:

* 报错信息(请尽量使用代码块的形式展现):
在未使用kubectl代理打开8080端口时部署会报以下错误:

TASK [master : kubeadm | delete old kube-dns service] ******************************************************************************************************************************************
Thursday 11 April 2019  06:35:49 +0800 (0:00:01.075)       0:02:05.070 ********
fatal: [node1]: FAILED! => {"changed": true, "cmd": ["kubectl", "delete", "svc", "kube-dns", "-n", "kube-system"], "delta": "0:00:00.576634", "end": "2019-04-11 06:35:50.287956", "msg": "non-zero return code", "rc": 1, "start": "2019-04-11 06:35:49.711322", "stderr": "The connection to the server localhost:8080 was refused - did you specify the right host or port?", "stderr_lines": ["The connection to the server localhost:8080 was refused - did you specify the right host or port?"], "stdout": "", "stdout_lines": []}
...ignoring

TASK [master : kubeadm | create kube-dns service] **********************************************************************************************************************************************
Thursday 11 April 2019  06:35:50 +0800 (0:00:01.239)       0:02:06.310 ********
fatal: [node1]: FAILED! => {"changed": true, "cmd": ["kubectl", "apply", "-f", "/etc/kubernetes/kube-dns-service.yml"], "delta": "0:00:00.185081", "end": "2019-04-11 06:35:51.210215", "msg": "non-zero return code", "rc": 1, "start": "2019-04-11 06:35:51.025134", "stderr": "error: unable to recognize \"/etc/kubernetes/kube-dns-service.yml\": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused", "stderr_lines": ["error: unable to recognize \"/etc/kubernetes/kube-dns-service.yml\": Get http://localhost:8080/api?timeout=32s: dial tcp 127.0.0.1:8080: connect: connection refused"], "stdout": "", "stdout_lines": []}
...ignoring

TASK [master : Update kube-proxy command args] *************************************************************************************************************************************************
Thursday 11 April 2019  06:35:51 +0800 (0:00:00.937)       0:02:07.247 ********
fatal: [node1]: FAILED! => {"changed": true, "cmd": "kubectl -n kube-system get ds -l 'k8s-app=kube-proxy' -o json | jq '.items[0].spec.template.spec.containers[0].command += [\"--masquerade-all\"]' | kubectl apply -f - && kubectl delete pods -n kube-system -l 'k8s-app=kube-proxy'", "delta": "0:00:00.267196", "end": "2019-04-11 06:35:52.171277", "msg": "non-zero return code", "rc": 1, "start": "2019-04-11 06:35:51.904081", "stderr": "The connection to the server localhost:8080 was refused - did you specify the right host or port?\nerror: no objects passed to apply", "stderr_lines": ["The connection to the server localhost:8080 was refused - did you specify the right host or port?", "error: no objects passed to apply"], "stdout": "", "stdout_lines": []}

NO MORE HOSTS LEFT *****************************************************************************************************************************************************************************
 to retry, use: --limit @/usr/kubeadm-ansible/cluster.retry

PLAY RECAP *************************************************************************************************************************************************************************************
node1                      : ok=73   changed=14   unreachable=0    failed=1



* 疑问:
> 请问是否有人在利用kubeadm-ansible部署k&s集群或者单节点时遇过以上问题,请问是否有较好的解决方法?

你好,建议你执行集群重置操作后再次进行安装,安装时不需要 “kubectl打开8080端口”

# 重置集群命令
ansible-playbook -i inventory/hosts reset.yml

谢谢,问题解决了!