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

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. 

主站蜘蛛池模板: 兴安县| 呼玛县| 同心县| 宁明县| 闻喜县| 贵州省| 阜平县| 嵊州市| 林甸县| 保山市| 内江市| 广宗县| 嵊泗县| 昌黎县| 平乡县| 陆良县| 大石桥市| 浠水县| 阳西县| 保定市| 霍邱县| 昭苏县| 蚌埠市| 本溪| 景洪市| 遂溪县| 芜湖县| 集安市| 齐齐哈尔市| 水富县| 隆安县| 淳化县| 湘潭市| 个旧市| 贡嘎县| 涞源县| 廊坊市| 集贤县| 海阳市| 梧州市| 乳山市|