@@ -593,21 +593,18 @@ For some parts of your application (for example, frontends) you may want to expo
593
593
Service onto an external IP address, that's outside of your cluster.
594
594
595
595
Kubernetes `ServiceTypes` allow you to specify what kind of Service you want.
596
- The default is `ClusterIP`.
597
596
598
597
`Type` values and their behaviors are :
599
598
600
599
* `ClusterIP`: Exposes the Service on a cluster-internal IP. Choosing this value
601
600
makes the Service only reachable from within the cluster. This is the
602
- default `ServiceType` .
601
+ default that is used if you don't explicitly specify a `type` for a Service .
603
602
* [`NodePort`](#type-nodeport): Exposes the Service on each Node's IP at a static port
604
- (the `NodePort`). A `ClusterIP` Service, to which the `NodePort` Service
605
- routes, is automatically created. You'll be able to contact the `NodePort` Service,
606
- from outside the cluster,
607
- by requesting `<NodeIP>:<NodePort>`.
603
+ (the `NodePort`).
604
+ To make the node port available, Kubernetes sets up a cluster IP address,
605
+ the same as if you had requested a Service of `type : ClusterIP`.
608
606
* [`LoadBalancer`](#loadbalancer): Exposes the Service externally using a cloud
609
- provider's load balancer. `NodePort` and `ClusterIP` Services, to which the external
610
- load balancer routes, are automatically created.
607
+ provider's load balancer.
611
608
* [`ExternalName`](#externalname): Maps the Service to the contents of the
612
609
` externalName` field (e.g. `foo.bar.example.com`), by returning a `CNAME` record
613
610
with its value. No proxying of any kind is set up.
@@ -627,20 +624,18 @@ allocates a port from a range specified by `--service-node-port-range` flag (def
627
624
Each node proxies that port (the same port number on every Node) into your Service.
628
625
Your Service reports the allocated port in its `.spec.ports[*].nodePort` field.
629
626
630
- If you want to specify particular IP(s) to proxy the port, you can set the
631
- ` --nodeport-addresses` flag for kube-proxy or the equivalent `nodePortAddresses`
632
- field of the
633
- [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
634
- to particular IP block(s).
627
+ Using a NodePort gives you the freedom to set up your own load balancing solution,
628
+ to configure environments that are not fully supported by Kubernetes, or even
629
+ to expose one or more nodes' IP addresses directly.
635
630
636
- This flag takes a comma-delimited list of IP blocks (e.g. `10.0.0.0/8`, `192.0.2.0/25`)
637
- to specify IP address ranges that kube-proxy should consider as local to this node.
631
+ For a node port Service, Kubernetes additionally allocates a port (TCP, UDP or
632
+ SCTP to match the protocol of the Service). Every node in the cluster configures
633
+ itself to listen on that assigned port and to forward traffic to one of the ready
634
+ endpoints associated with that Service. You'll be able to contact the `type : NodePort`
635
+ Service, from outside the cluster, by connecting to any node using the appropriate
636
+ protocol (for example : TCP), and the appropriate port (as assigned to that Service).
638
637
639
- For example, if you start kube-proxy with the `--nodeport-addresses=127.0.0.0/8` flag,
640
- kube-proxy only selects the loopback interface for NodePort Services.
641
- The default for `--nodeport-addresses` is an empty list.
642
- This means that kube-proxy should consider all available network interfaces for NodePort.
643
- (That's also compatible with earlier Kubernetes releases).
638
+ # ### Choosing your own port {#nodeport-custom-port}
644
639
645
640
If you want a specific port number, you can specify a value in the `nodePort`
646
641
field. The control plane will either allocate you that port or report that
@@ -649,16 +644,8 @@ This means that you need to take care of possible port collisions yourself.
649
644
You also have to use a valid port number, one that's inside the range configured
650
645
for NodePort use.
651
646
652
- Using a NodePort gives you the freedom to set up your own load balancing solution,
653
- to configure environments that are not fully supported by Kubernetes, or even
654
- to expose one or more nodes' IPs directly.
655
-
656
- Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
657
- and `.spec.clusterIP:spec.ports[*].port`.
658
- If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
659
- in the kube-proxy configuration file is set, `<NodeIP>` would be filtered node IP(s).
660
-
661
- For example :
647
+ Here is an example manifest for a Service of `type : NodePort` that specifies
648
+ a NodePort value (30007, in this example).
662
649
663
650
` ` ` yaml
664
651
apiVersion: v1
@@ -678,6 +665,33 @@ spec:
678
665
nodePort : 30007
679
666
` ` `
680
667
668
+ #### Custom IP address configuration for ` type: NodePort` Services {#service-nodeport-custom-listen-address}
669
+
670
+ You can set up nodes in your cluster to use a particular IP address for serving node port
671
+ services. You might want to do this if each node is connected to multiple networks (for example :
672
+ one network for application traffic, and another network for traffic between nodes and the
673
+ control plane).
674
+
675
+ If you want to specify particular IP address(es) to proxy the port, you can set the
676
+ ` --nodeport-addresses` flag for kube-proxy or the equivalent `nodePortAddresses`
677
+ field of the
678
+ [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
679
+ to particular IP block(s).
680
+
681
+ This flag takes a comma-delimited list of IP blocks (e.g. `10.0.0.0/8`, `192.0.2.0/25`)
682
+ to specify IP address ranges that kube-proxy should consider as local to this node.
683
+
684
+ For example, if you start kube-proxy with the `--nodeport-addresses=127.0.0.0/8` flag,
685
+ kube-proxy only selects the loopback interface for NodePort Services.
686
+ The default for `--nodeport-addresses` is an empty list.
687
+ This means that kube-proxy should consider all available network interfaces for NodePort.
688
+ (That's also compatible with earlier Kubernetes releases.)
689
+ Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
690
+ and `.spec.clusterIP:spec.ports[*].port`.
691
+ If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
692
+ in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered node IP address (or possibly IP addresses).
693
+
694
+
681
695
# ## Type LoadBalancer {#loadbalancer}
682
696
683
697
On cloud providers which support external load balancers, setting the `type`
@@ -716,6 +730,16 @@ the loadBalancer is set up with an ephemeral IP address. If you specify a `loadB
716
730
but your cloud provider does not support the feature, the `loadbalancerIP` field that you
717
731
set is ignored.
718
732
733
+ To implement a Service of `type : LoadBalancer`, Kubernetes typically starts off
734
+ by making the changes that are equivalent to you requesting a Service of
735
+ `type : NodePort`. The cloud-controller-manager component then configures the external load balancer to
736
+ forward traffic to that assigned node port.
737
+
738
+ _As an alpha feature_, you can configure a load balanced Service to
739
+ [omit](#load-balancer-nodeport-allocation) assigning a node port, provided that the
740
+ cloud provider implementation supports this.
741
+
742
+
719
743
{{< note >}}
720
744
721
745
On **Azure**, if you want to use a user-specified public type `loadBalancerIP`, you first need
@@ -1292,7 +1316,7 @@ a load balancer or node-port.
1292
1316
The `Type` field is designed as nested functionality - each level adds to the
1293
1317
previous. This is not strictly required on all cloud providers (e.g. Google Compute Engine does
1294
1318
not need to allocate a `NodePort` to make `LoadBalancer` work, but AWS does)
1295
- but the current API requires it.
1319
+ but the Kubernetes API design for Service requires it anyway .
1296
1320
1297
1321
# # Virtual IP implementation {#the-gory-details-of-virtual-ips}
1298
1322
0 commit comments