无法通过Docker设置Kubernetes本地群集

时间:2016-06-09 17:22:22

标签: networking docker cluster-computing kubernetes kubectl

我跟着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烧瓶应用程序,所以我用我自己的图像和用['export DOCKER=True && cd commandcenter/ && python app.py']

的args替换图像

这是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:27017curl 10.0.0.167:27017访问mongo,因为如上所示,mongo0.0.0.0:27017->27017/tcp。但是,当我运行curl 10.0.0.119:3000时,它就像一个无限的循环,最终它说出来了。那是为什么?

因此,我的问题是:如何公开web以便它还有一个非空的PORTS字段?

我对网络知之甚少,所以非常感谢任何帮助。非常感谢你!

1 个答案:

答案 0 :(得分: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访问该服务。