[英]Kubernetes/kubectl: unable to connect to a server to handle “pods”
I'm new to Kubernetes so I encountered the following issue. 我是Kubernetes的新手,所以遇到了以下问题。 These are my steps:
这些是我的步骤:
1) I ran etcd
: 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) I ran the master container: 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) I ran the proxy: 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) I installed kubectl
4)我安装了
kubectl
5) I created this simple pod-file.yml
: 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"]
and tried to create pod by running: 并尝试通过运行以下命令创建pod:
kubectl create -f pod-file.yml
And I got: 我得到:
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
I found it pretty odd so I checked containers I ran earlier: 我发现这很奇怪,所以我检查了之前运行的容器:
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
So looks like all is ok because all containers are up and running. 因此看起来一切正常,因为所有容器都已启动并正在运行。 Okay, I checked open ports in my system (
ubuntu 16.04
): 好的,我检查了系统中打开的端口(
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
And I found that there is no 8080
open TCP port that kubectl
tried to reach. 而且我发现
kubectl
尝试没有达到8080
开放的TCP端口。 So this is the cause of my issue. 所以这就是我问题的原因。
So my question is what container/service/daemon I should run/launch to open this port and to assign web service to it in order to let kubectl use it for this GET request http://localhost:8080/api
? 所以我的问题是我应该运行/启动哪个容器/服务/守护程序来打开此端口并为其分配Web服务,以便让kubectl将此端口用于此GET请求
http://localhost:8080/api
?
Any help would be appreciated. 任何帮助,将不胜感激。
Creating a kubernetes cluster from scratch is a little more complicated. 从头开始创建kubernetes集群要复杂一些。 The master
kubelet
runs a number of pods to make it all go. 主
kubelet
运行许多吊舱以使其全部运转。
If you're looking for an all in one solution use minikube to run in a VM. 如果您正在寻找一种全能的解决方案,请使用minikube在VM中运行。 Otherwise use
kubeadm
to setup your master and work back from there if you want to see how each component is setup. 否则,如果要查看每个组件的设置方式,请使用
kubeadm
设置您的母版,然后从那里进行工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.