0

我关注了 http://kubernetes.io/docs/getting-started-guides/docker/。以下是我实际运行的命令:

export K8S_VERSION=$(curl -sS https://storage.googleapis.com/kubernetes-release/release/stable.txt)
export ARCH=amd64
docker run -d \
--volume=/:/rootfs:ro \
--volume=/sys:/sys:rw \
--volume=/var/lib/docker/:/var/lib/docker:rw \
--volume=/var/lib/kubelet/:/var/lib/kubelet:rw \
--volume=/var/run:/var/run:rw \
--net=host \
--pid=host \
--privileged \
gcr.io/google_containers/hyperkube-${ARCH}:${K8S_VERSION} \
/hyperkube kubelet \
    --containerized \
    --hostname-override=127.0.0.1 \
    --api-servers=http://localhost:8080 \
    --config=/etc/kubernetes/manifests \
    --cluster-dns=10.0.0.10 \
    --cluster-domain=cluster.local \
    --allow-privileged --v=2
curl -sSL "http://storage.googleapis.com/kubernetes-release/release/v1.2.0/bin/linux/amd64/kubectl" > /usr/bin/kubectl
chmod +x /usr/bin/kubectl
kubectl config set-cluster test-doc --server=http://localhost:8080
kubectl config set-context test-doc --cluster=test-doc
kubectl config use-context test-doc

然后我跟着https://github.com/kubernetes/kubernetes/tree/release-1.2/examples/nodesjs-mongodb

kubectl create -f web-service.yaml
kubectl create -f web-controller.yaml
kubectl create -f mongo-service.yaml
kubectl create -f mongo-controller.yaml

我有一个 Python 烧瓶应用程序,所以我用我自己的图像和 args 替换图像['export DOCKER=True && cd commandcenter/ && python app.py']

这是结果kubectl get services

NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
kubernetes   10.0.0.1     <none>        443/TCP     3d
mongo        10.0.0.167   <none>        27017/TCP   14m
web          10.0.0.119                 80/TCP      6m

结果kubectl get pods

NAME                     READY     STATUS    RESTARTS   AGE
k8s-etcd-127.0.0.1       1/1       Running   0          3d
k8s-master-127.0.0.1     4/4       Running   0          3d
k8s-proxy-127.0.0.1      1/1       Running   0          3d
mongo-controller-3b8q5   1/1       Running   0          5m
nginx-198147104-9w444    1/1       Running   0          25m
web-controller-6nzpn     1/1       Running   3          2m
web-controller-uot1s     1/1       Running   3          2m

结果kubectl logs web-controller-6nzpn

DEBUG 2016-06-09 17:57:49,279 Starting up server 
INFO 2016-06-09 17:57:49,285  * Running on http://0.0.0.0:3000/ (Press CTRL+C to quit)

结果kubectl get nodes

NAME        STATUS    AGE
127.0.0.1   Ready     3d

结果docker ps

CONTAINER ID        IMAGE                                             COMMAND                  CREATED             STATUS              PORTS                      NAMES
78330abb3cbc        gcr.io/google_containers/pause:2.0                "/pause"                 5 minutes ago       Up 5 minutes                                   k8s_POD.6079054c_web-controller-6nzpn_default_208f7237-2e65-11e6-98e4-f80f41fc0776_e72a59d6
8f41e68e0dbb        gcr.io/google_containers/pause:2.0                "/pause"                 5 minutes ago       Up 5 minutes                                   k8s_POD.6079054c_web-controller-uot1s_default_208f587f-2e65-11e6-98e4-    f80f41fc0776_6861905a
d0d8696f8757        mongo                                             "/entrypoint.sh mongo"   8 minutes ago       Up 8 minutes                                   k8s_mongo.a8042bbb_mongo-controller-3b8q5_default_b21552c0-2e64-11e6-98e4-f80f41fc0776_835c7956
83701f56b225        gcr.io/google_containers/pause:2.0                "/pause"                 9 minutes ago       Up 9 minutes        0.0.0.0:27017->27017/tcp   k8s_POD.683503f7_mongo-controller-3b8q5_default_b21552c0-2e64-11e6-98e4-f80f41fc0776_a07aaf2b
bdf64b18dbf0        nginx                                             "nginx -g 'daemon off"   29 minutes ago      Up 29 minutes                                  k8s_nginx.cd4c2839_nginx-198147104-9w444_default_dab5019f-2e61-11e6-98e4-f80f41fc0776_04c0a7dc
15cfd30b3280        gcr.io/google_containers/pause:2.0                "/pause"                 29 minutes ago      Up 29 minutes                                  k8s_POD.cf58006d_nginx-198147104-9w444_default_dab5019f-2e61-11e6-98e4-f80f41fc0776_aae25ba3
4409962a7123        gcr.io/google_containers/hyperkube:v0.21.2        "/hyperkube proxy --m"   44 minutes ago      Up 44 minutes                                  stupefied_yonath
0a8b91c41e68        gcr.io/google_containers/hyperkube-amd64:v1.2.4   "/setup-files.sh IP:1"   49 minutes ago      Up 49 minutes                                  k8s_setup.eb843218_k8s-master-127.0.0.1_default_721118f359852533089009890ac21208_22bec1b0
6a91a6e7620c        gcr.io/google_containers/hyperkube-amd64:v1.2.4   "/hyperkube scheduler"   49 minutes ago      Up 49 minutes                                  k8s_scheduler.dbfcc0_k8s-master-127.0.0.1_default_721118f359852533089009890ac21208_feeb19b7
4ca45bc03c89        gcr.io/google_containers/hyperkube-amd64:v1.2.4   "/hyperkube apiserver"   49 minutes ago      Up 49 minutes                                  k8s_apiserver.1082c1e0_k8s-master-127.0.0.1_default_721118f359852533089009890ac21208_16592f39
a5a4cf124d74        gcr.io/google_containers/hyperkube-amd64:v1.2.4   "/hyperkube controlle"   49 minutes ago      Up 49 minutes                                  k8s_controller-manager.76914b67_k8s-master-127.0.0.1_default_721118f359852533089009890ac21208_d2dffc43
3f0c3c342a12        gcr.io/google_containers/etcd:2.2.1               "/usr/local/bin/etcd "   49 minutes ago      Up 49 minutes                                  k8s_etcd.7e452b0b_k8s-etcd-127.0.0.1_default_1df6a8b4d6e129d5ed8840e370203c11_82b244e9
3bca02d310dc        gcr.io/google_containers/hyperkube-amd64:v1.2.4   "/hyperkube proxy --m"   49 minutes ago      Up 49 minutes                                  k8s_kube-proxy.a1014855_k8s-proxy-127.0.0.1_default_0cda4a663a246109121ac68b3c7e82b7_c610ef5f
cf83efe4cf4e        gcr.io/google_containers/pause:2.0                "/pause"                 49 minutes ago      Up 49 minutes                                  k8s_POD.6059dfa2_k8s-master-127.0.0.1_default_721118f359852533089009890ac21208_2864939a
51b02dab5bcd        gcr.io/google_containers/pause:2.0                "/pause"                 49 minutes ago      Up 49 minutes                                  k8s_POD.6059dfa2_k8s-etcd-127.0.0.1_default_1df6a8b4d6e129d5ed8840e370203c11_9cf2fc4d
5256fcfbd3d2        gcr.io/google_containers/pause:2.0                "/pause"                 49 minutes ago      Up 49 minutes                                  k8s_POD.6059dfa2_k8s-proxy-127.0.0.1_default_0cda4a663a246109121ac68b3c7e82b7_86be1d4f
b41dfb03d56d        gcr.io/google_containers/hyperkube-amd64:v1.2.4   "/hyperkube kubelet -"   50 minutes ago      Up 50 minutes                                  kickass_fermat

这台机器有一个公共IP地址,我的目标是从外部访问演示网站。我可以通过http://public_IP_address:27017and访问 mongo curl 10.0.0.167:27017,因为如上所示,mongo有。0.0.0.0:27017->27017/tcp但是,当我运行时curl 10.0.0.119:3000,它就像一个无限循环,最终它说超时。这是为什么?

因此,我的问题是:如何公开web以使其也具有非空PORTS字段?

我对网络了解不多,因此非常感谢任何帮助。非常感谢!

4

1 回答 1

0

如果您查看https://github.com/kubernetes/kubernetes/blob/release-1.2/examples/nodesjs-mongodb/web-service.yaml,您会看到服务类型是LoadBalancer. 这旨在与 AWS 和 GCE 等云提供商合作。

在您的情况下,您需要使用NodePorts公开服务。指定type: NodePortnodePort: 3xxxx(某些端口大于 30000),您可以访问服务<NodeIP>:NodePort

于 2016-06-09T20:07:06.420 回答