官术网_书友最值得收藏!

Custom load balancing

A third type of service that K8s allows is the NodePort type. This type allows us to expose a service through the host or node (minion) on a specific port. In this way, we can use the IP address of any node (minion) and access our service on the assigned node port. Kubernetes will assign a node port by default in the range of 3000-32767, but you can also specify your own custom port. In the example in the following listing nodejs-service-nodeport.yaml, we choose port 30001, as follows:

apiVersion: v1 
kind: Service
metadata:
name: node-js-nodeport
labels:
name: node-js-nodeport
spec:
ports:
- port: 80
nodePort: 30001
selector:
name: node-js
type: NodePort

Once again, create this YAML definition file and create your service, as follows:

$ kubectl create -f nodejs-service-nodeport.yaml

The output should have a message like this:

New GCP firewall rule

Note message about opening firewall ports. Similar to the external load balancer type, NodePort is exposing your service externally using ports on the nodes. This could be useful if, for example, you want to use your own load balancer in front of the nodes. Let's make sure that we open those ports on GCP before we test our new service.

From the GCE VM instance console, click on the details for any of your nodes (minions). Then, click on the network, which is usually the default unless otherwise specified during creation. In Firewall rules, we can add a rule by clicking on Add firewall rule.

Create a rule like the one shown in the following screenshot (tcp:30001 on the 0.0.0.0/0 IP range):

Create a new firewall rule page

We can now test our new service by opening a browser and using an IP address of any node (minion) in your cluster. The format to test the new service is as follows:

http://<Minoion IP Address>:<NodePort>/

Finally, the latest version has added an ExternalName type, which maps a CNAME to the service. 

主站蜘蛛池模板: 扶绥县| 浦北县| 通渭县| 宁国市| 禹城市| 金乡县| 饶平县| 醴陵市| 遂溪县| 漳州市| 安图县| 黄浦区| 沙河市| 高雄县| 岳阳市| 静安区| 红原县| 沈丘县| 保定市| 南华县| 新泰市| 洪洞县| 洛川县| 常熟市| 通州市| 潮安县| 教育| 华安县| 龙门县| 达孜县| 天津市| 衢州市| 东方市| 台南县| 山东| 泰来县| 固始县| 荥经县| 长顺县| 东平县| 衢州市|