- Getting Started with Kubernetes
- Jonathan Baier Jesse White
- 326字
- 2021-06-10 19:47:14
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:

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):

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.
- 輕松學C語言
- R Data Mining
- 機器人智能運動規(guī)劃技術(shù)
- JavaScript典型應用與最佳實踐
- Introduction to R for Business Intelligence
- WOW!Photoshop CS6完全自學寶典
- 簡明學中文版Flash動畫制作
- Microsoft System Center Data Protection Manager Cookbook
- Practical Network Automation
- 基于Quartus Ⅱ的數(shù)字系統(tǒng)Verilog HDL設計實例詳解
- OSGi原理與最佳實踐
- 計算機仿真技術(shù)
- ORACLE數(shù)據(jù)庫技術(shù)實用詳解
- Android High Performance Programming
- 中文版Photoshop CS6高手速成