在集群中部署了Pod, Deployment,Replicasets后, 每个Pod都会生成一个Endpoints,是一个IP:Port形式, 这时候,可以为这些Pods生成一个service, 类型是NodePort,NodePort意思是,通过Pod所在的Node的端口访问此服务:
kubectl describe services example-service
得到如下信息:
Name: example-service
Namespace: default
Labels: run=load-balancer-example
Annotations: <none>
Selector: run=load-balancer-example
Type: NodePort
IP: 10.32.0.16
Port: <unset> 8080/TCP
TargetPort: 8080/TCP
NodePort: <unset> 31496/TCP
Endpoints: 10.200.1.4:8080,10.200.2.5:8080
Session Affinity: None
Events: <none>
其中NodePort说明通过Node哪个端口访问。
获取集群的任何一个运行你的业务的Node的IP地址:
kubectl cluster-info
CODE
然后通过
http://<public-node-ip>:<node-port>
访问