簡體   English   中英

Kubernetes / kubectl:無法連接到服務器來處理“ pods”

[英]Kubernetes/kubectl: unable to connect to a server to handle “pods”

我是Kubernetes的新手,所以遇到了以下問題。 這些是我的步驟:

1)我跑了etcd

docker run --volume=/var/etcd:/var/etcd --net=host -d gcr.io/google_containers/etcd:2.0.12 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data

2)我運行了主容器:

docker run \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:ro \
--volume=/dev:/dev \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
--pid=host \
--privileged=true \
-d gcr.io/google_containers/hyperkube:v1.0.1 \
/hyperkube kubelet --containerized --hostname-override="127.0.0.1" --address="0.0.0.0" --api-servers=http://localhost:8080 --config=/etc/kubernetes/manifests

3)我運行了代理:

docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v1.0.1 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2

4)我安裝了kubectl

5)我創建了這個簡單的pod-file.yml

apiVersion: v1
kind: Pod
metadata:
  name: two-containers
spec:

  restartPolicy: Never

  volumes:
  - name: shared-data
    emptyDir: {}

  containers:

  - name: nginx-container
    image: nginx
    volumeMounts:
    - name: shared-data
      mountPath: /usr/share/nginx/html

  - name: debian-container
    image: debian
    volumeMounts:
    - name: shared-data
      mountPath: /pod-data
    command: ["/bin/sh"]
    args: ["-c", "echo Hello from the debian container > /pod-data/index.html"]

並嘗試通過運行以下命令創建pod:

kubectl create -f pod-file.yml

我得到:

ubuntu@ubuntu:~$ kubectl create -f pod-file.yml
error: could not read an encoded object from pod-file.yml: unable to connect to a server to handle "pods": couldn't read version from server: Get http://localhost:8080/api: dial tcp 127.0.0.1:8080: connection refused

我發現這很奇怪,所以我檢查了之前運行的容器:

ubuntu@ubuntu:~$ docker ps
CONTAINER ID        IMAGE                                       COMMAND                  CREATED             STATUS                                                                           PORTS               NAMES
3ae7f094bb01        gcr.io/google_containers/hyperkube:v1.0.1   "/hyperkube proxy ..."   55 minutes ago      Up 55 minutes                                                                                        suspicious_ramanujan
ed841bc6ef26        gcr.io/google_containers/hyperkube:v1.0.1   "/hyperkube kubele..."   57 minutes ago      Up 57 minutes                                                                                        competent_mclean
7408c640a2c8        gcr.io/google_containers/etcd:2.0.12        "/usr/local/bin/et..."   About an hour ago   Up About an hour                                                                                     elated_shaw

因此看起來一切正常,因為所有容器都已啟動並正在運行。 好的,我檢查了系統中打開的端口( ubuntu 16.04 ):

ubuntu@ubuntu:~$ sudo netstat -nautp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1315/sshd
tcp        0      0 127.0.0.1:7001          0.0.0.0:*               LISTEN      3209/etcd
tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      3324/hyperkube
tcp        0      0 127.0.0.1:10249         0.0.0.0:*               LISTEN      3399/hyperkube
tcp        0      0 127.0.0.1:2380          0.0.0.0:*               LISTEN      3209/etcd
tcp        0    524 172.30.3.114:22         212.98.179.158:35900    ESTABLISHED 3087/sshd: ubuntu [
tcp6       0      0 :::10255                :::*                    LISTEN      3324/hyperkube
tcp6       0      0 :::22                   :::*                    LISTEN      1315/sshd
tcp6       0      0 :::4001                 :::*                    LISTEN      3209/etcd
tcp6       0      0 :::10250                :::*                    LISTEN      3324/hyperkube
udp        0      0 0.0.0.0:68              0.0.0.0:*                           959/dhclient
udp        0      0 0.0.0.0:68              0.0.0.0:*                           796/dhclient

而且我發現kubectl嘗試沒有達到8080開放的TCP端口。 所以這就是我問題的原因。

所以我的問題是我應該運行/啟動哪個容器/服務/守護程序來打開此端口並為其分配Web服務,以便讓kubectl將此端口用於此GET請求http://localhost:8080/api

任何幫助,將不勝感激。

從頭開始創建kubernetes集群要復雜一些。 kubelet運行許多吊艙以使其全部運轉。

如果您正在尋找一種全能的解決方案,請使用minikube在VM中運行。 否則,如果要查看每個組件的設置方式,請使用kubeadm設置您的母版,然后從那里進行工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM