@@ -647,21 +647,18 @@ For some parts of your application (for example, frontends) you may want to expo
647
647
Service onto an external IP address, that's outside of your cluster.
648
648
649
649
Kubernetes `ServiceTypes` allow you to specify what kind of Service you want.
650
- The default is `ClusterIP`.
651
650
652
651
`Type` values and their behaviors are :
653
652
654
653
* `ClusterIP`: Exposes the Service on a cluster-internal IP. Choosing this value
655
654
makes the Service only reachable from within the cluster. This is the
656
- default `ServiceType` .
655
+ default that is used if you don't explicitly specify a `type` for a Service .
657
656
* [`NodePort`](#type-nodeport): Exposes the Service on each Node's IP at a static port
658
- (the `NodePort`). A `ClusterIP` Service, to which the `NodePort` Service
659
- routes, is automatically created. You'll be able to contact the `NodePort` Service,
660
- from outside the cluster,
661
- by requesting `<NodeIP>:<NodePort>`.
657
+ (the `NodePort`).
658
+ To make the node port available, Kubernetes sets up a cluster IP address,
659
+ the same as if you had requested a Service of `type : ClusterIP`.
662
660
* [`LoadBalancer`](#loadbalancer): Exposes the Service externally using a cloud
663
- provider's load balancer. `NodePort` and `ClusterIP` Services, to which the external
664
- load balancer routes, are automatically created.
661
+ provider's load balancer.
665
662
* [`ExternalName`](#externalname): Maps the Service to the contents of the
666
663
` externalName` field (e.g. `foo.bar.example.com`), by returning a `CNAME` record
667
664
with its value. No proxying of any kind is set up.
@@ -681,20 +678,18 @@ allocates a port from a range specified by `--service-node-port-range` flag (def
681
678
Each node proxies that port (the same port number on every Node) into your Service.
682
679
Your Service reports the allocated port in its `.spec.ports[*].nodePort` field.
683
680
684
- If you want to specify particular IP(s) to proxy the port, you can set the
685
- ` --nodeport-addresses` flag for kube-proxy or the equivalent `nodePortAddresses`
686
- field of the
687
- [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
688
- to particular IP block(s).
681
+ Using a NodePort gives you the freedom to set up your own load balancing solution,
682
+ to configure environments that are not fully supported by Kubernetes, or even
683
+ to expose one or more nodes' IP addresses directly.
689
684
690
- This flag takes a comma-delimited list of IP blocks (e.g. `10.0.0.0/8`, `192.0.2.0/25`)
691
- to specify IP address ranges that kube-proxy should consider as local to this node.
685
+ For a node port Service, Kubernetes additionally allocates a port (TCP, UDP or
686
+ SCTP to match the protocol of the Service). Every node in the cluster configures
687
+ itself to listen on that assigned port and to forward traffic to one of the ready
688
+ endpoints associated with that Service. You'll be able to contact the `type : NodePort`
689
+ Service, from outside the cluster, by connecting to any node using the appropriate
690
+ protocol (for example : TCP), and the appropriate port (as assigned to that Service).
692
691
693
- For example, if you start kube-proxy with the `--nodeport-addresses=127.0.0.0/8` flag,
694
- kube-proxy only selects the loopback interface for NodePort Services.
695
- The default for `--nodeport-addresses` is an empty list.
696
- This means that kube-proxy should consider all available network interfaces for NodePort.
697
- (That's also compatible with earlier Kubernetes releases).
692
+ # ### Choosing your own port {#nodeport-custom-port}
698
693
699
694
If you want a specific port number, you can specify a value in the `nodePort`
700
695
field. The control plane will either allocate you that port or report that
@@ -703,16 +698,8 @@ This means that you need to take care of possible port collisions yourself.
703
698
You also have to use a valid port number, one that's inside the range configured
704
699
for NodePort use.
705
700
706
- Using a NodePort gives you the freedom to set up your own load balancing solution,
707
- to configure environments that are not fully supported by Kubernetes, or even
708
- to expose one or more nodes' IPs directly.
709
-
710
- Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
711
- and `.spec.clusterIP:spec.ports[*].port`.
712
- If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
713
- in the kube-proxy configuration file is set, `<NodeIP>` would be filtered node IP(s).
714
-
715
- For example :
701
+ Here is an example manifest for a Service of `type : NodePort` that specifies
702
+ a NodePort value (30007, in this example).
716
703
717
704
` ` ` yaml
718
705
apiVersion: v1
@@ -732,6 +719,33 @@ spec:
732
719
nodePort : 30007
733
720
` ` `
734
721
722
+ #### Custom IP address configuration for ` type: NodePort` Services {#service-nodeport-custom-listen-address}
723
+
724
+ You can set up nodes in your cluster to use a particular IP address for serving node port
725
+ services. You might want to do this if each node is connected to multiple networks (for example :
726
+ one network for application traffic, and another network for traffic between nodes and the
727
+ control plane).
728
+
729
+ If you want to specify particular IP address(es) to proxy the port, you can set the
730
+ ` --nodeport-addresses` flag for kube-proxy or the equivalent `nodePortAddresses`
731
+ field of the
732
+ [kube-proxy configuration file](/docs/reference/config-api/kube-proxy-config.v1alpha1/)
733
+ to particular IP block(s).
734
+
735
+ This flag takes a comma-delimited list of IP blocks (e.g. `10.0.0.0/8`, `192.0.2.0/25`)
736
+ to specify IP address ranges that kube-proxy should consider as local to this node.
737
+
738
+ For example, if you start kube-proxy with the `--nodeport-addresses=127.0.0.0/8` flag,
739
+ kube-proxy only selects the loopback interface for NodePort Services.
740
+ The default for `--nodeport-addresses` is an empty list.
741
+ This means that kube-proxy should consider all available network interfaces for NodePort.
742
+ (That's also compatible with earlier Kubernetes releases.)
743
+ Note that this Service is visible as `<NodeIP>:spec.ports[*].nodePort`
744
+ and `.spec.clusterIP:spec.ports[*].port`.
745
+ If the `--nodeport-addresses` flag for kube-proxy or the equivalent field
746
+ in the kube-proxy configuration file is set, `<NodeIP>` would be a filtered node IP address (or possibly IP addresses).
747
+
748
+
735
749
# ## Type LoadBalancer {#loadbalancer}
736
750
737
751
On cloud providers which support external load balancers, setting the `type`
@@ -770,6 +784,16 @@ the loadBalancer is set up with an ephemeral IP address. If you specify a `loadB
770
784
but your cloud provider does not support the feature, the `loadbalancerIP` field that you
771
785
set is ignored.
772
786
787
+ To implement a Service of `type : LoadBalancer`, Kubernetes typically starts off
788
+ by making the changes that are equivalent to you requesting a Service of
789
+ `type : NodePort`. The cloud-controller-manager component then configures the external load balancer to
790
+ forward traffic to that assigned node port.
791
+
792
+ _As an alpha feature_, you can configure a load balanced Service to
793
+ [omit](#load-balancer-nodeport-allocation) assigning a node port, provided that the
794
+ cloud provider implementation supports this.
795
+
796
+
773
797
{{< note >}}
774
798
775
799
On **Azure**, if you want to use a user-specified public type `loadBalancerIP`, you first need
@@ -1346,7 +1370,7 @@ a load balancer or node-port.
1346
1370
The `Type` field is designed as nested functionality - each level adds to the
1347
1371
previous. This is not strictly required on all cloud providers (e.g. Google Compute Engine does
1348
1372
not need to allocate a `NodePort` to make `LoadBalancer` work, but AWS does)
1349
- but the current API requires it.
1373
+ but the Kubernetes API design for Service requires it anyway .
1350
1374
1351
1375
# # Virtual IP implementation {#the-gory-details-of-virtual-ips}
1352
1376
0 commit comments