我很难确定Guestbook示例是否在Minikube中运行。我的主要问题可能是示例说明here详述了所有步骤,但没有任何关于如何从默认YAML文件运行时连接到Web应用程序的说明。
我在Mac OS X 10.9.5(Mavericks)中使用Minikube v。0.10.0
,这是我最终得到的结果(根据我从示例文档中读到的内容,这似乎相当不错):
PolePro:all-in-one poletti$ kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend 10.0.0.140 <none> 80/TCP 8s
kubernetes 10.0.0.1 <none> 443/TCP 2h
redis-master 10.0.0.165 <none> 6379/TCP 53m
redis-slave 10.0.0.220 <none> 6379/TCP 37m
PolePro:all-in-one poletti$ kubectl get deployments
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
frontend 3 3 3 3 20s
redis-master 1 1 1 1 42m
redis-slave 2 2 2 2 37m
PolePro:all-in-one poletti$ kubectl get pods
NAME READY STATUS RESTARTS AGE
frontend-708336848-0h2zj 1/1 Running 0 29s
frontend-708336848-ds8pn 1/1 Running 0 29s
frontend-708336848-v8wp9 1/1 Running 0 29s
redis-master-2093957696-or5iu 1/1 Running 0 43m
redis-slave-109403812-12k68 1/1 Running 0 37m
redis-slave-109403812-c7zmo 1/1 Running 0 37m
我以为我可以连接到http://10.0.0.140:80/
(即上面frontend
返回的kubectl get svc
地址和端口)并看到应用程序正在运行,但我得到了一个{{ 1}}:
Connection refused
虽然示例描述错过了如此重要的一步,但却有些怀疑。我错过了什么?
答案 0 :(得分:1)
嗯,好像我自己想出来了(我也可能发一个PR)
主要的是,至少在Minikube设置中,PolePro:all-in-one poletti$ curl -v http://10.0.0.140:80
* About to connect() to 10.0.0.140 port 80 (#0)
* Trying 10.0.0.140...
* Adding handle: conn: 0x7fb0f9803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fb0f9803a00) send_pipe: 1, recv_pipe: 0
* Failed connect to 10.0.0.140:80; Connection refused
* Closing connection 0
curl: (7) Failed connect to 10.0.0.140:80; Connection refused
命令在Mac OS X中运行,但所有很酷的东西都发生在虚拟机中。就我而言,它是一个VirtualBox虚拟机(我还在小牛队)。
当kubectl
显示服务的地址时,例如:
kubectl
这些地址可以从节点内访问,不一定是从外部访问。就我而言,他们不可以从外面访问。
那么你能做些什么呢?
首先,要检查它是否实际运行,您可以登录节点并从那里运行curl:
PolePro:all-in-one poletti$ kubectl get svc
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
frontend 10.0.0.140 <none> 80/TCP 8s
kubernetes 10.0.0.1 <none> 443/TCP 2h
redis-master 10.0.0.165 <none> 6379/TCP 53m
redis-slave 10.0.0.220 <none> 6379/TCP 37m
耶!实际上有一些东西在80端口运行。
无论如何,这仍然有点麻烦,我们希望在Mac OS X的浏览器中看到这一点。一种方法是使用# get the list of nodes, to get the name of the node we're interested into
PolePro:all-in-one poletti$ kubectl get nodes
NAME STATUS AGE
minikube Ready 3h
# that was easy. Now we can get the address of the node
PolePro:all-in-one poletti$ kubectl describe node/minikube | grep '^Address'
Addresses: 192.168.99.100,192.168.99.100
# now we can log into the node. The username is "docker", the password is "tcuser"
# by default (without quotes):
PolePro:all-in-one poletti$ ssh docker@192.168.99.100
docker@192.168.99.100's password:
## .
## ## ## ==
## ## ## ## ## ===
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ / ===- ~~~
\______ o __/
\ \ __/
\____\_______/
_ _ ____ _ _
| |__ ___ ___ | |_|___ \ __| | ___ ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__| < __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.11.1, build master : 901340f - Fri Jul 1 22:52:19 UTC 2016
Docker version 1.11.1, build 5604cbe
docker@minikube:~$ curl -v http://10.0.0.140/
* Trying 10.0.0.140...
* Connected to 10.0.0.140 (10.0.0.140) port 80 (#0)
> GET / HTTP/1.1
> Host: 10.0.0.140
> User-Agent: curl/7.49.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 19 Sep 2016 13:37:56 GMT
< Server: Apache/2.4.10 (Debian) PHP/5.6.20
< Last-Modified: Wed, 09 Sep 2015 18:35:04 GMT
< ETag: "399-51f54bdb4a600"
< Accept-Ranges: bytes
< Content-Length: 921
< Vary: Accept-Encoding
< Content-Type: text/html
<
<html ng-app="redis">
<head>
<title>Guestbook</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.12/angular.min.js"></script>
<script src="controllers.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.13.0/ui-bootstrap-tpls.js"></script>
</head>
<body ng-controller="RedisCtrl">
<div style="width: 50%; margin-left: 20px">
<h2>Guestbook</h2>
<form>
<fieldset>
<input ng-model="msg" placeholder="Messages" class="form-control" type="text" name="input"><br>
<button type="button" class="btn btn-primary" ng-click="controller.onRedis()">Submit</button>
</fieldset>
</form>
<div>
<div ng-repeat="msg in messages track by $index">
{{msg}}
</div>
</div>
</div>
</body>
</html>
* Connection #0 to host 10.0.0.140 left intact
使节点将服务的端口映射到Node的港口;完成后,在NodePort
服务定义中添加以下行,该行变为:
frontend
根据您使用的文件,可能会在apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
app: guestbook
tier: frontend
spec:
# if your cluster supports it, uncomment the following to automatically create
# an external load-balanced IP for the frontend service.
# type: LoadBalancer
type: NodePort
ports:
# the port that this service should serve on
- port: 80
selector:
app: guestbook
tier: frontend
,frontend-service.yaml
或all-in-one/frontend.yaml
中请求此更改。
如果您重新创建整个留言簿(我不知道是否有必要,但我会保持安全),您将收到有关端口和防火墙的消息,如下所示:
all-in-one/guestbook-all-in-one.yaml
现在,节点上的端口# delete previous instance to start from "scratch"
PolePro:all-in-one poletti$ kubectl delete deployments,svc -l 'app in (redis, guestbook)'
deployment "frontend" deleted
deployment "redis-master" deleted
deployment "redis-slave" deleted
service "frontend" deleted
service "redis-master" deleted
service "redis-slave" deleted
# we'll use the all-in-one here to get quickly to the point
PolePro:all-in-one poletti$ vi guestbook-all-in-one.yaml
# with the new NodePort change in place, we're ready to start again
PolePro:all-in-one poletti$ kubectl create -f guestbook-all-in-one.yaml
service "redis-master" created
deployment "redis-master" created
service "redis-slave" created
deployment "redis-slave" created
You have exposed your service on an external port on all nodes in your
cluster. If you want to expose this service to the external internet, you may
need to set up firewall rules for the service port(s) (tcp:30559) to serve traffic.
See http://releases.k8s.io/release-1.3/docs/user-guide/services-firewalls.md for more details.
service "frontend" created
deployment "frontend" created
映射到前端端口30559
,因此我们可以在地址80
(即http://192.168.99.100:30559/
)打开浏览器,我们可以使用留言簿!
答案 1 :(得分:1)
快速而肮脏:
kubectl port-forward frontend-708336848-0h2zj 80:80