nidr 发表于 2018-1-4 19:32:33

【kubernetes】kubectl logs connection refused

  因为启动dashboard报CrashLoopBackOff错误,尝试使用logs去查看日志,结果报错,错误如下:
  

# kubectl -s http://192.168.37.130:8080 logs kubernetes-dashboard-v1.4.0-vceyf --namespace=kube-system  
Using HTTP port: 9090
  
Using apiserver-host location: http://127.0.0.1:8080
  
Creating API server client for http://127.0.0.1:8080
  
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: Get http://127.0.0.1:8080/version: dial tcp 127.0.0.1:8080: getsockopt: connection refused
  

  但是使用curlhttp://192.168.37.130:8080却是可以访问通的
  

# curlhttp://192.168.37.130:8080  
{
  "paths": [
  "/api",
  "/api/v1",
  ...."/version"
  ]
  
}#
  

  实在很奇怪,
  首先怀疑是不是因为IPV6的原因导致,关闭IPV6
  

编辑文件/etc/sysctl.conf,  

vi /etc/sysctl.conf  
添加下面的行:
  
net.ipv6.conf.all.disable_ipv6
=1  
net.ipv6.conf.default.disable_ipv6
=1  
如果你想要为特定的网卡禁止IPv6,比如,对于enp0s3,添加下面的行。
  
net.ipv6.conf.enp0s3.disable_ipv6
=1  
保存并退出文件。
  
执行下面的命令来使设置生效。
  
sysctl
-p  

  但再次重启服务,也还是无法访问,原因不在此。
  从网上看这篇文章:http://blog.csdn.net/qingchi0/article/details/42538549,说

  监听的接口,如果配置为127.0.0.1则只监听localhost,配置为0.0.0.0会监听所有接口,这里配置为0.0.0.0。

  尝试进行修改
  把前文安装kube-apiserver的配置文件/etc/sysconfig/kubernets/kube-apiserver修改为

  INSECURE_BIND_ADDRESS="--insecure-bind-address=0.0.0.0"

  重启服务,发现这次连本来能访问的localhost:8080都访问不通了,说明无效,再次尝试将INSECURE_BIND_ADDRESS改为

  INSECURE_BIND_ADDRESS="--address=0.0.0.0"

  重启服务,

  curl 127.0.0.1:8080
  curl localhost:8080
  curl 192.168.37.130:8080
  三种方式访问都么有问题。
  本以为按照127.0.0.1能够访问通了,kubectl -s http://192.168.37.130:8080 logs kubernetes-dashboard-v1.4.0-vceyf --namespace=kube-system就能看到结果了,但结果依旧,那么就应该是提示中的另外一个问题了,

  This most likely means that the cluster is misconfigured (e.g., it has invalid apiserver certificates or service accounts configuration)

  这个就应该是证书的问题了,这个问题比较复杂,后面在系统的去研究下
页: [1]
查看完整版本: 【kubernetes】kubectl logs connection refused