Docker sample Kubernete does not expose port
Since I am learning Kubernetes, I started with a docker getting started guide as suggested by the docs. The guide can be found here: https://github.com/GoogleCloudPlatform/kubernetes/blob/release-1.0/docs/getting-started-guides/docker.md
Destroying the pointer, he suggests executing the following commands:
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
These commands generate the following output on my machine:
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
Now I'm wondering why the "IP (S)" column doesn't show the ip address. Looking at my output 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
I'm wondering why nginx-container doesn't have port mappings.
How can kubernetes route traffic traffic to a docker container that doesn't expose any ports? Is there anything that has changed since the documentation was written? Or am I not losing anything?
Versions used:
./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
source to share
The command kubectl expose
creates a service, but its selector does not match the generated modules.
You can use ./kubectl expose rc nginx -l run=nginx --port=80
to create a service using run=nginx
as a selector.
Then the launch kubectl describe service nginx
shows:
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.
When you now navigate to the endpoint at 172.17.0.29:80
, you can see how your nginx works.
source to share
For me, the original sample worked correctly (although you didn't get the IP listed in the output of the expose command). But I couldn't access it from outside. I had to add --public-ip=
to the expose command and it worked like a charm (although I still don't get the IP printed in the output of the expose command).
source to share
I notice that if you use kubectl expose rc nginx --port=80
than kubectl describe service nginx
, it shows:
...
Endpoints: <none>
...
But if you wait a few seconds and run again kubectl describe service nginx
it will show something like:
...
Endpoints: 172.17.0.7:80
...
Anyway, it doesn't show the IP address in the output of the expose command, and you need the command kubectl describe service nginx
. Perhaps the manual needs to be updated.
source to share