我正在尝试使用三个VM(Master-10.xx4,Node1-10.xx150,Node2-10.xx160)创建Kubernetes集群。
我可以通过以下链接成功创建留言簿应用程序:http : //kubernetes.io/v1.0/examples/guestbook/。我对frontend-service.yaml进行的一项更改是:使用NodePort。我可以使用节点IP和端口号(10.xx150:30724或10.xx160:30724)访问前端服务。因此,一切都按预期工作,但是我无法使用ClusterIP地址(在我的情况下为10.xx79)访问前端服务。
我对NodePort的理解是,可以通过群集IP以及群集每个节点上的端口访问该服务。如何通过ClusterIP访问服务,而不必访问每个节点?我在这里想念什么吗?
服务和吊舱详细信息
$ sudo kubectl描述服务前端
Name: frontend
Namespace: default
Labels: name=frontend
Selector: name=frontend
Type: NodePort
IP: 10.x.x.79
Port: <unnamed> 80/TCP
NodePort: <unnamed> 30724/TCP
Endpoints: 172.x.x.13:80,172.x.x.14:80,172.x.x.11:80
Session Affinity: None
No events.
Run Code Online (Sandbox Code Playgroud)
$ sudo kubectl描述pod frontend-2b5us
Name: frontend-2b5us
Namespace: default
Image(s): gcr.io/google_samples/gb-frontend:v3
Node: 10.x.x.150/10.x.x.150
Labels: name=frontend
Status: Running
Reason:
Message:
IP: 172.x.x.11
Replication Controllers: frontend (3/3 replicas created)
Containers:
php-redis:
Image: gcr.io/google_samples/gb-frontend:v3
State: Running
Started: Fri, 30 Oct 2015 04:00:40 -0500
Ready: True
Restart Count: 0
Run Code Online (Sandbox Code Playgroud)
我尝试搜索,但没有找到针对我确切问题的任何解决方案,但我确实找到了类似GCE的类似问题。
您没有ClusterIP服务。您确实有一个NodePort服务。要访问它,您已经连接到集群中任何节点上的NodePort。您在这里确实获得了负载平衡。即使您连接到群集节点,获得的Pod也不一定在该特定节点上运行。
在https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services---service-types中阅读文档中的相关部分,以了解其他服务类型。您可能不希望在GCP上使用NodePort。
谈论ClusterIP。要访问用于调试目的的ClusterIP服务,可以运行kubectl port-forward。您实际上将不会访问该服务,但是您将直接连接到其中一个Pod。
例如
kubectl port-forward frontend-2b5us 80 8080
Run Code Online (Sandbox Code Playgroud)
现在连接到本地主机:8080
更复杂的命令,它可以在给定名称空间-n weave和选择器的情况下自行发现端口。取自https://www.weave.works/docs/scope/latest/installing/
kubectl port-forward -n weave \
"$(kubectl get -n weave pod \
--selector=weave-scope-component=app \
-o jsonpath='{.items..metadata.name}')" \
4040
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3988 次 |
| 最近记录: |