问题:The connection to the server localhost:8080 was refused - did you specify the right host or port?

    情景

[jiayue@localhost ~]$ kubectl get nodes
The connection to the server localhost:8080 was refused - did you specify the right host or port?

    解决方案

由于发生的原因不同,网上有两种解决方案,本人出现的是第一种问题:

    方案1

没有启动k8s集群或启动顺序不对,重新按一下顺序启动所有服务

[root@localhost jiayue]# systemctl start etcd
[root@localhost jiayue]# systemctl start docker
[root@localhost jiayue]# systemctl start kube-apiserver
[root@localhost jiayue]# systemctl start kube-controller-manager
[root@localhost jiayue]# systemctl start kube-scheduler
[root@localhost jiayue]# systemctl start kubelet
[root@localhost jiayue]# systemctl start kube-proxy
[root@localhost jiayue]# kubectl get nodes
NAME        STATUS    AGE
127.0.0.1   Ready     43d
    方案2

原因:kubenetes master没有与本机绑定,集群初始化的时候没有设置
解决办法:执行以下命令 export KUBECONFIG=/etc/kubernetes/admin.conf
/etc/kubernetes/admin.conf这个文件主要是集群初始化的时候用来传递参数的

问题:新建rc成功却没创建pod

    情景

[root@localhost tomcat_mysql]# kubectl get rc
NAME      DESIRED   CURRENT   READY     AGE
mysql     1         0         0         23m
[root@localhost tomcat_mysql]# kubectl get pod
No resources found.

    解决方案

1、关闭ServiceAccount

具体为删除/etc/kubernetes/apiserver配置中,KUBE_ADMISSION_CONTROL 中的ServiceAccount字段,

KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"

2、重启kube-apiserver服务,

systemctl restart kube-apiserver

详细原理参考:https://blog.csdn.net/u010039418/article/details/86529053

问题:no nodes available to schedule pods

    情景

[root@localhost tomcat_mysql]# kubectl get pods
NAME          READY     STATUS    RESTARTS   AGE
mysql-grk4v   0/1       Pending   0          18m
[root@localhost tomcat_mysql]# kubectl describe pod mysql-grk4v
Name:           mysql-grk4v
Namespace:      default
Node:           /
Labels:         app=mysql
Status:         Pending
IP:
Controllers:    ReplicationController/mysql
Containers:
  mysql:
    Image:              docker.io/mysql:5.7
    Port:               3306/TCP
    Volume Mounts:      <none>
    Environment Variables:
      MYSQL_ROOT_PASSWORD:      123456
Conditions:
  Type          Status
  PodScheduled  False
No volumes.
QoS Class:      BestEffort
Tolerations:    <none>
Events:
  FirstSeen     LastSeen        Count   From                    SubObjectPath   Type            Reason                  Message
  ---------     --------        -----   ----                    -------------   --------        -------                 ------
  20m           9s              76      {default-scheduler }                    Warning         FailedScheduling        no nodes available to schedule pods

    问题解决

1、修改vim /etc/kubernetes/config中的KUBE_MASTER,将127.0.0.1改为自身的ip
2、重启所有服务

[root@localhost tomcat_mysql]# systemctl start etcd
[root@localhost tomcat_mysql]# systemctl start docker
[root@localhost tomcat_mysql]# systemctl start kube-apiserver
[root@localhost tomcat_mysql]# systemctl start kube-controller-manager
[root@localhost tomcat_mysql]# systemctl start kube-scheduler
[root@localhost tomcat_mysql]# systemctl start kubelet
[root@localhost tomcat_mysql]# systemctl start kube-proxy
[root@localhost tomcat_mysql]# kubectl get node
NAME        STATUS    AGE
127.0.0.1   Ready     43d

问题:Error syncing pod, skipping: failed to “StartContainer” for “POD” with ImagePullBackOff

    情景

[root@localhost tomcat_mysql]# kubectl get node
NAME        STATUS    AGE
127.0.0.1   Ready     43d
[root@localhost tomcat_mysql]# kubectl get rc
NAME      DESIRED   CURRENT   READY     AGE
mysql     1         1         0         29m
[root@localhost tomcat_mysql]# kubectl get pod
NAME          READY     STATUS              RESTARTS   AGE
mysql-grk4v   0/1       ContainerCreating   0          29m
[root@localhost tomcat_mysql]# kubectl describe pod
Name:           mysql-grk4v
Namespace:      default
Node:           127.0.0.1/127.0.0.1
Start Time:     Thu, 05 Dec 2019 09:18:54 +0800
Labels:         app=mysql
Status:         Pending
IP:
Controllers:    ReplicationController/mysql
Containers:
  mysql:
    Container ID:
    Image:              docker.io/mysql:5.7
    Image ID:
    Port:               3306/TCP
    State:              Waiting
      Reason:           ContainerCreating
    Ready:              False
    Restart Count:      0
    Volume Mounts:      <none>
    Environment Variables:
      MYSQL_ROOT_PASSWORD:      123456
Conditions:
  Type          Status
  Initialized   True
  Ready         False
  PodScheduled  True
No volumes.
QoS Class:      BestEffort
Tolerations:    <none>
Events:
  FirstSeen     LastSeen        Count   From                    SubObjectPath   Type            Reason                  Message
  ---------     --------        -----   ----                    -------------   --------        ------                  -------
  29m           51s             104     {default-scheduler }                    Warning         FailedScheduling        no nodes available to schedule pods
  35s           35s             1       {default-scheduler }                    Normal          Scheduled               Successfully assigned mysql-grk4v to 127.0.0.1
  32s           21s             2       {kubelet 127.0.0.1}                     Warning         FailedSync              Error syncing pod, skipping: failed to "StartContainer" for "POD" with ErrImagePull: "image pull failed for registry.access.redhat.com/rhel7/pod-infrastructure:latest, this may be because there are no credentials on this request.  details: (open /etc/docker/certs.d/registry.access.redhat.com/redhat-ca.crt: no such file or directory)"

  6s    6s      1       {kubelet 127.0.0.1}             Warning FailedSync      Error syncing pod, skipping: failed to "StartContainer" for "POD" with ImagePullBackOff: "Back-off pulling image \"registry.access.redhat.com/rhel7/pod-infrastructure:latest\""

    问题解决

yum install rhsm
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm
rpm2cpio python-rhsm-certificates-1.19.10-1.el7_4.x86_64.rpm | cpio -iv --to-stdout ./etc/rhsm/ca/redhat-uep.pem | tee /etc/rhsm/ca/redhat-uep.pem
docker pull registry.access.redhat.com/rhel7/pod-infrastructure:latest

执行完后生成/etc/rhsm/ca/redhat-uep.pem,然后删除resource,重新新建一次即可

[root@localhost tomcat_mysql]# kubectl get pod
NAME          READY     STATUS              RESTARTS   AGE
mysql-grk4v   0/1       ContainerCreating   0          34m
[root@localhost tomcat_mysql]# kubectl delete -f mysql-rc.yaml
replicationcontroller "mysql" deleted
[root@localhost tomcat_mysql]# kubectl create -f mysql-rc.yaml
replicationcontroller "mysql" created
[root@localhost tomcat_mysql]# kubectl get pod
NAME          READY     STATUS    RESTARTS   AGE
mysql-m2nc2   1/1       Running   0          1m
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐