Kubernetes docker示例不会暴露端口

时间:2015-08-08 18:28:41

标签: docker kubernetes

当我正在探索kubernetes时,我开始使用基于docker的入门指南,正如文档所建议的那样。该指南可在此处找到:https://github.com/GoogleCloudPlatform/kubernetes/blob/release-1.0/docs/getting-started-guides/docker.md

打破guid,它建议运行以下命令:

docker run --net=host -d gcr.io/google_containers/etcd:2.0.9 /usr/local/bin/etcd --addr=127.0.0.1:4001 --bind-addr=0.0.0.0:4001 --data-dir=/var/etcd/data
docker run --net=host -d -v /var/run/docker.sock:/var/run/docker.sock  gcr.io/google_containers/hyperkube:v0.21.2 /hyperkube kubelet --api_servers=http://localhost:8080 --v=2 --address=0.0.0.0 --enable_server --hostname_override=127.0.0.1 --config=/etc/kubernetes/manifests
docker run -d --net=host --privileged gcr.io/google_containers/hyperkube:v0.21.2 /hyperkube proxy --master=http://127.0.0.1:8080 --v=2

./kubectl -s http://localhost:8080 run-container nginx --image=nginx --port=80
./kubectl expose rc nginx --port=80

这些命令在我的机器上生成以下输出:

5a0993be2df88f9da448234490ce98f744a47d0ff3ec2e9b9ba76ff8c85eb600
0c9ab039e8024d5596b87eb294ad31538ba8864509d9886c4217e6fe47416f1a
d413be16d3f0167bbaacba7582d22a1752b2195fe8d7f7333bbcb5ce2d2a7b20

CONTROLLER   CONTAINER(S)   IMAGE(S)   SELECTOR    REPLICAS
nginx        nginx          nginx      run=nginx   1

NAME      LABELS      SELECTOR    IP(S)     PORT(S)
nginx     run=nginx   run=nginx             80/TCP

我现在想知道为什么" IP(S)"列不显示IP地址。 查看我的docker ps输出:

CONTAINER ID        IMAGE                                        COMMAND                CREATED             STATUS              PORTS               NAMES
4c5d8c790daa        nginx                                        "nginx -g 'daemon of   4 minutes ago       Up 4 minutes                            k8s_nginx.d7d3eb2f_nginx-em03c_default_c7d89937-3df9-11e5-b322-20689deb710c_b7323a43                     
cedfe5cf7841        gcr.io/google_containers/pause:0.8.0         "/pause"               4 minutes ago       Up 4 minutes                            k8s_POD.ef28e851_nginx-em03c_default_c7d89937-3df9-11e5-b322-20689deb710c_cf507bf9                       
a92be0abae29        gcr.io/google_containers/hyperkube:v0.21.2   "/hyperkube schedule   5 minutes ago       Up 5 minutes                            k8s_scheduler.b725e775_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_85e00e91            
7910edc79350        gcr.io/google_containers/hyperkube:v0.21.2   "/hyperkube apiserve   5 minutes ago       Up 5 minutes                            k8s_apiserver.70750283_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_03ed1050            
23d1d3f9eac0        gcr.io/google_containers/hyperkube:v0.21.2   "/hyperkube controll   5 minutes ago       Up 5 minutes                            k8s_controller-manager.aad1ee8f_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_17695204   
caccad2f2e68        gcr.io/google_containers/pause:0.8.0         "/pause"               5 minutes ago       Up 5 minutes                            k8s_POD.e4cc795_k8s-master-127.0.0.1_default_9b44830745c166dfc6d027b0fc2df36d_fb79862d                   
d413be16d3f0        gcr.io/google_containers/hyperkube:v0.21.2   "/hyperkube proxy --   5 minutes ago       Up 5 minutes                            nostalgic_colden                                                                                         
0c9ab039e802        gcr.io/google_containers/hyperkube:v0.21.2   "/hyperkube kubelet    5 minutes ago       Up 5 minutes                            suspicious_ritchie                                                                                       
5a0993be2df8        gcr.io/google_containers/etcd:2.0.9          "/usr/local/bin/etcd   5 minutes ago       Up 5 minutes                            loving_einstein2    

我想知道为什么nginx-container没有端口映射。

kubernetes服务如何将流量路由到不暴露任何端口的docker容器?自编写文档以来有什么变化吗?还是有什么我想念的?

使用的版本:

./kubectl version

Client Version: version.Info{Major:"0", Minor:"18", GitVersion:"v0.18.2", GitCommit:"1f12b893876ad6c41396222693e37061f6e80fe1", GitTreeState:"clean"}
Server Version: version.Info{Major:"0", Minor:"21", GitVersion:"v0.21.2", GitCommit:"4e89f2e6670b1662021a86ac42b99c5c50c37d05", GitTreeState:"clean"}

docker version

Client version: 1.7.0
Client API version: 1.19
Go version (client): go1.4.2
Git commit (client): 0baf609
OS/Arch (client): linux/amd64
Server version: 1.7.0
Server API version: 1.19
Go version (server): go1.4.2
Git commit (server): 0baf609
OS/Arch (server): linux/amd64

3 个答案:

答案 0 :(得分:0)

kubectl expose命令创建服务,但其选择器与创建的pod不匹配。

您可以使用./kubectl expose rc nginx -l run=nginx --port=80使用run=nginx作为选择器来创建服务。

然后运行kubectl describe service nginx显示:

W0809 14:05:26.337988    3423 request.go:291] field selector: v1beta3 - events - involvedObject.kind - Service: need to check if this is versioned correctly.
W0809 14:05:26.340098    3423 request.go:291] field selector: v1beta3 - events - involvedObject.uid - deb1c06e-3e8e-11e5-aa11-20689deb710c: need to check if this is versioned correctly.
W0809 14:05:26.340197    3423 request.go:291] field selector: v1beta3 - events - involvedObject.name - nginx: need to check if this is versioned correctly.
W0809 14:05:26.340243    3423 request.go:291] field selector: v1beta3 - events - involvedObject.namespace - default: need to check if this is versioned correctly.
Name:           nginx
Labels:         run=nginx
Selector:       run=nginx
Type:           ClusterIP
IP:         10.0.0.201
Port:           default 80/TCP
Endpoints:      172.17.0.29:80
Session Affinity:   None
No events.

当您现在导航到172.17.0.29:80处的端点时,您可以看到您的nginx正在运行。

答案 1 :(得分:0)

对我来说,原始样本工作正常(即使您没有在expose命令输出中列出IP)。但是我无法从外面访问它。我必须将--public-ip=添加到expose命令中,它就像一个魅力(即使我仍然没有在expose命令输出中打印出IP)。

答案 2 :(得分:0)

我注意到,如果您使用 x = [ [4,2,3,4,5,4,5,6,7,4,8,9,8,8,6,6,5,5,5,5,5,5,5], #<-specific column [4,1,2,3,4,5,6,7,5,8,7,8,7,8,7,8,7,7,7,7,7,6,5], #<-specific column [4,1,2,5,6,7,8,9,7,8,7,8,7,7,7,7,7,7,6,6,4,4,4] #<-specific column ] 而不是kubectl expose rc nginx --port=80,则会显示:

kubectl describe service nginx

但如果等待几秒钟再次运行... Endpoints: <none> ... ,它将显示如下内容:

kubectl describe service nginx

无论如何,它不会在expose命令输出中显示IP,您将需要... Endpoints: 172.17.0.7:80 ... 命令。也许指南应该更新。