嗯,看來我理解了它自己(我可能會發送一個PR太)
更主要的是,至少在Minikube設置中,kubectl
命令在Mac OS X上運行,但所有很酷的東西都發生在虛擬機器中。在我的情況下,它是一個VirtualBox虛擬機(我仍然在小牛隊)。
當kubectl
顯示了服務的地址,像在這種情況下:
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
這些地址是從節點中訪問,不一定是從外面。在我的情況下,他們是而不是從外面訪問。
那麼你能做些什麼呢?
首先,要覈對一下它的實際運行,您可以登錄到該節點,並從那裏捲曲運行:
# 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 [email protected]
[email protected]'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
[email protected]:~$ 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
耶!實際上,有這個運行在端口80
反正東西,這仍然是一個有點麻煩,我們希望看到這個在Mac OS X在瀏覽器中做到這一點是使用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/
(即http://<NODE-IP>:<EXTERNAL-PORT>/
),我們可以使用留言簿!
人們也可以使用'kubectl expose'命令以暴露端口,而不必修改服務YAML配置。通常情況下,我在集羣中查看事物的方式是使用busybox容器,如[此處]所示(http://blog.kubernetes.io/2015/10/some-things-you-didnt-know-about -kubectl_28.html)。如果這個例子沒有充分證明服務類型和使用各種效果的差異,請給我們一個PR。謝謝! –