For non-cloud environments, OpenShift Container Platform supports the assignment of external IP addresses to a Service spec.externalIPs
field through the ExternalIP facility.
This exposes an additional virtual IP address, assigned to the Service, that can be outside the service network defined for the cluster.
A Service configured with an external IP functions similarly to a Service with type=NodePort
, allowing you to direct traffic to a local node for load balancing.
You must configure your networking infrastructure to ensure that the external IP address blocks that you define are routed to the cluster.
OpenShift Container Platform extends the ExternalIP functionality in Kubernetes by adding the following capabilities:
By default, only a user with cluster-admin
privileges can create a Service with spec.externalIPs[]
set to IP addresses defined within an external IP address block.
|
Disabled by default, use of ExternalIP functionality can be a security risk, because in-cluster traffic to an external IP address is directed to that Service.
This could allow cluster users to intercept sensitive traffic destined for external resources.
|
|
This feature is supported only in non-cloud deployments.
For cloud deployments, use the load balancer services for automatic deployment of a cloud load balancer to target the endpoints of a service.
|
You can assign an external IP address in the following ways:
- Automatic assignment of an external IP
-
OpenShift Container Platform automatically assigns an IP address from the autoAssignCIDRs
CIDR block to the spec.externalIPs[]
array when you create a Service with spec.type=LoadBalancer
set.
In this case, OpenShift Container Platform implements a non-cloud version of the load balancer Service type and assigns IP addresses to the services.
Automatic assignment is disabled by default and must be configured by a cluster administrator as described in the following section.
- Manual assignment of an external IP
-
OpenShift Container Platform uses the IP addresses assigned to the spec.externalIPs[]
array when you create a Service. You cannot specify an IP address that is already in use by another Service.
Configuration for ExternalIP
Use of an external IP address in OpenShift Container Platform is governed by the following fields in the Network.config.openshift.io
CR named cluster
:
-
spec.externalIP.autoAssignCIDRs
defines an IP address block used by the load balancer when choosing an external IP address for the service. OpenShift Container Platform supports only a single IP address block for automatic assignment. This can be simpler than having to manage the port space of a limited number of shared IP addresses when manually assigning ExternalIPs to services. If automatic assignment is enabled, a Service with spec.type=LoadBalancer
is allocated an external IP address.
-
spec.externalIP.policy
defines the permissible IP address blocks when manually specifying an IP address. OpenShift Container Platform does not apply policy rules to IP address blocks defined by spec.externalIP.autoAssignCIDRs
.
If routed correctly, external traffic from the configured external IP address block can reach service endpoints through any TCP or UDP port that the service exposes.
|
You must ensure that the IP address block you assign terminates at one or more nodes in your cluster.
|
OpenShift Container Platform supports both the automatic and manual assignment of IP
addresses, and each address is guaranteed to be assigned to a maximum of one
service. This ensures that each service can expose its chosen ports regardless
of the ports exposed by other services.
|
To use IP address blocks defined by autoAssignCIDRs in OpenShift Container Platform, you must configure the necessary IP address assignment and routing for your host network.
|
The following YAML describes a Service with an external IP configured:
Example Service object with spec.externalIPs[]
set
apiVersion: v1
kind: Service
metadata:
name: http-service
spec:
clusterIP: 172.30.163.110
externalIPs:
- 192.168.132.253
externalTrafficPolicy: Cluster
ports:
- name: highport
nodePort: 31903
port: 30102
protocol: TCP
targetPort: 30102
selector:
app: web
sessionAffinity: None
type: LoadBalancer
status:
loadBalancer:
ingress:
- ip: 192.168.132.253
Restrictions on the assignment of an external IP address
As a cluster administrator, you can specify IP address blocks to allow and to reject.
You configure IP address policy with a policy
object defined by specifying the spec.ExternalIP.policy
field.
The policy object has the following shape:
{
"policy": {
"allowedCIDRs": [],
"rejectedCIDRs": []
}
}
When configuring policy restrictions, the following rules apply:
-
If policy={}
is set, then creating a Service with spec.ExternalIPs[]
set will fail. This is the default for OpenShift Container Platform.
-
If policy=null
is set, then creating a Service with spec.ExternalIPs[]
set to any IP address is allowed.
-
If policy
is set and either policy.allowedCIDRs[]
or policy.rejectedCIDRs[]
is set, the following rules apply:
-
If allowedCIDRs[]
and rejectedCIDRs[]
are both set, then rejectedCIDRs[]
has precedence over allowedCIDRs[]
.
-
If allowedCIDRs[]
is set, creating a Service with spec.ExternalIPs[]
will succeed only if the specified IP addresses are allowed.
-
If rejectedCIDRs[]
is set, creating a Service with spec.ExternalIPs[]
will succeed only if the specified IP addresses are not rejected.
Example policy objects
The examples that follow demonstrate several different policy configurations.
-
In the following example, the policy prevents OpenShift Container Platform from creating any Service with an external IP address specified:
Example policy to reject any value specified for Service spec.externalIPs[]
apiVersion: config.openshift.io/v1
kind: Network
metadata:
name: cluster
spec:
externalIP:
policy: {}
...
-
In the following example, both the allowedCIDRs
and rejectedCIDRs
fields are set.
Example policy that includes both allowed and rejected CIDR blocks
apiVersion: config.openshift.io/v1
kind: Network
metadata:
name: cluster
spec:
externalIP:
policy:
allowedCIDRs:
- 172.16.66.10/23
rejectedCIDRs:
- 172.16.66.10/24
...
-
In the following example, policy
is set to null
.
If set to null
, when inspecting the configuration object by entering oc get networks.config.openshift.io -o yaml
, the policy
field will not appear in the output.
Example policy to allow any value specified for Service spec.externalIPs[]
apiVersion: config.openshift.io/v1
kind: Network
metadata:
name: cluster
spec:
externalIP:
policy: null
...