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

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. 

主站蜘蛛池模板: 白城市| 江陵县| 江门市| 文登市| 蓬溪县| 剑河县| 长宁县| 老河口市| 台江县| 济宁市| 荣成市| 富平县| 新疆| 榆中县| 惠东县| 全椒县| 柳江县| 天祝| 房山区| 鄂托克前旗| 油尖旺区| 安乡县| 和平县| 珠海市| 公安县| 南安市| 嵊州市| 佛坪县| 大渡口区| 茶陵县| 固安县| 榆林市| 吴忠市| 霍山县| 平原县| 惠水县| 柘荣县| 涟水县| 东安县| 金平| 隆尧县|