This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.Chapter 15. Configuring ingress cluster traffic
15.1. Configuring ingress cluster traffic overview Copy linkLink copied to clipboard!
OpenShift Container Platform provides the following methods for communicating from outside the cluster with services running in the cluster.
The methods are recommended, in order or preference:
- If you have HTTP/HTTPS, use an Ingress Controller.
- If you have a TLS-encrypted protocol other than HTTPS. For example, for TLS with the SNI header, use an Ingress Controller.
-
Otherwise, use a Load Balancer, an External IP, or a
NodePort
.
Method | Purpose |
---|---|
Allows access to HTTP/HTTPS traffic and TLS-encrypted protocols other than HTTPS (for example, TLS with the SNI header). | |
Automatically assign an external IP using a load balancer service | Allows traffic to non-standard ports through an IP address assigned from a pool. |
Allows traffic to non-standard ports through a specific IP address. | |
Expose a service on all nodes in the cluster. |
15.2. Configuring ExternalIPs for services Copy linkLink copied to clipboard!
As a cluster administrator, you can designate an IP address block that is external to the cluster that can send traffic to services in the cluster.
This functionality is generally most useful for clusters installed on bare-metal hardware.
15.2.1. Prerequisites Copy linkLink copied to clipboard!
- Your network infrastructure must route traffic for the external IP addresses to your cluster.
15.2.2. About ExternalIP Copy linkLink copied to clipboard!
For non-cloud environments, OpenShift Container Platform supports the assignment of external IP addresses to a Service
object spec.externalIPs[]
field through the ExternalIP facility. By setting this field, OpenShift Container Platform assigns an additional virtual IP address to the service. The IP address can be outside the service network defined for the cluster. A service configured with an ExternalIP 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:
- Restrictions on the use of external IP addresses by users through a configurable policy
- Allocation of an external IP address automatically to a service upon request
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 thespec.externalIPs[]
array when you create aService
object withspec.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 aService
object. You cannot specify an IP address that is already in use by another service.
15.2.2.1. Configuration for ExternalIP Copy linkLink copied to clipboard!
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, aService
object withspec.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 byspec.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 address configured:
Example Service
object with spec.externalIPs[]
set
15.2.2.2. Restrictions on the assignment of an external IP address Copy linkLink copied to clipboard!
As a cluster administrator, you can specify IP address blocks to allow and to reject.
Restrictions apply only to users without cluster-admin
privileges. A cluster administrator can always set the service spec.externalIPs[]
field to any IP address.
You configure IP address policy with a policy
object defined by specifying the spec.ExternalIP.policy
field. The policy object has the following shape:
When configuring policy restrictions, the following rules apply:
-
If
policy={}
is set, then creating aService
object withspec.ExternalIPs[]
set will fail. This is the default for OpenShift Container Platform. -
If
policy=null
is set, then creating aService
object withspec.ExternalIPs[]
set to any IP address is allowed. If
policy
is set and eitherpolicy.allowedCIDRs[]
orpolicy.rejectedCIDRs[]
is set, the following rules apply:-
If
allowedCIDRs[]
andrejectedCIDRs[]
are both set, thenrejectedCIDRs[]
has precedence overallowedCIDRs[]
. -
If
allowedCIDRs[]
is set, creating aService
object withspec.ExternalIPs[]
will succeed only if the specified IP addresses are allowed. -
If
rejectedCIDRs[]
is set, creating aService
object withspec.ExternalIPs[]
will succeed only if the specified IP addresses are not rejected.
-
If
15.2.2.3. Example policy objects Copy linkLink copied to clipboard!
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
objectspec.externalIPs[]
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the following example, both the
allowedCIDRs
andrejectedCIDRs
fields are set.Example policy that includes both allowed and rejected CIDR blocks
Copy to Clipboard Copied! Toggle word wrap Toggle overflow In the following example,
policy
is set tonull
. If set tonull
, when inspecting the configuration object by enteringoc get networks.config.openshift.io -o yaml
, thepolicy
field will not appear in the output.Example policy to allow any value specified for
Service
objectspec.externalIPs[]
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.2.3. ExternalIP address block configuration Copy linkLink copied to clipboard!
The configuration for ExternalIP address blocks is defined by a Network custom resource (CR) named cluster
. The Network CR is part of the config.openshift.io
API group.
During cluster installation, the Cluster Version Operator (CVO) automatically creates a Network CR named cluster
. Creating any other CR objects of this type is not supported.
The following YAML describes the ExternalIP configuration:
Network.config.openshift.io CR named cluster
- 1
- Defines the IP address block in CIDR format that is available for automatic assignment of external IP addresses to a service. Only a single IP address range is allowed.
- 2
- Defines restrictions on manual assignment of an IP address to a service. If no restrictions are defined, specifying the
spec.externalIP
field in aService
object is not allowed. By default, no restrictions are defined.
The following YAML describes the fields for the policy
stanza:
Network.config.openshift.io policy
stanza
policy: allowedCIDRs: [] rejectedCIDRs: []
policy:
allowedCIDRs: []
rejectedCIDRs: []
Example external IP configurations
Several possible configurations for external IP address pools are displayed in the following examples:
The following YAML describes a configuration that enables automatically assigned external IP addresses:
Example configuration with
spec.externalIP.autoAssignCIDRs
setCopy to Clipboard Copied! Toggle word wrap Toggle overflow The following YAML configures policy rules for the allowed and rejected CIDR ranges:
Example configuration with
spec.externalIP.policy
setCopy to Clipboard Copied! Toggle word wrap Toggle overflow
15.2.4. Configure external IP address blocks for your cluster Copy linkLink copied to clipboard!
As a cluster administrator, you can configure the following ExternalIP settings:
-
An ExternalIP address block used by OpenShift Container Platform to automatically populate the
spec.clusterIP
field for aService
object. -
A policy object to restrict what IP addresses may be manually assigned to the
spec.clusterIP
array of aService
object.
Prerequisites
-
Install the OpenShift CLI (
oc
). -
Access to the cluster as a user with the
cluster-admin
role.
Procedure
Optional: To display the current external IP configuration, enter the following command:
oc describe networks.config cluster
$ oc describe networks.config cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To edit the configuration, enter the following command:
oc edit networks.config cluster
$ oc edit networks.config cluster
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Modify the ExternalIP configuration, as in the following example:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
- Specify the configuration for the
externalIP
stanza.
To confirm the updated ExternalIP configuration, enter the following command:
oc get networks.config cluster -o go-template='{{.spec.externalIP}}{{"\n"}}'
$ oc get networks.config cluster -o go-template='{{.spec.externalIP}}{{"\n"}}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.2.5. Next steps Copy linkLink copied to clipboard!
15.3. Configuring ingress cluster traffic using an Ingress Controller Copy linkLink copied to clipboard!
OpenShift Container Platform provides methods for communicating from outside the cluster with services running in the cluster. This method uses an Ingress Controller.
15.3.1. Using Ingress Controllers and routes Copy linkLink copied to clipboard!
The Ingress Operator manages Ingress Controllers and wildcard DNS.
Using an Ingress Controller is the most common way to allow external access to an OpenShift Container Platform cluster.
An Ingress Controller is configured to accept external requests and proxy them based on the configured routes. This is limited to HTTP, HTTPS using SNI, and TLS using SNI, which is sufficient for web applications and services that work over TLS with SNI.
Work with your administrator to configure an Ingress Controller to accept external requests and proxy them based on the configured routes.
The administrator can create a wildcard DNS entry and then set up an Ingress Controller. Then, you can work with the edge Ingress Controller without having to contact the administrators.
By default, every ingress controller in the cluster can admit any route created in any project in the cluster.
The Ingress Controller:
- Has two replicas by default, which means it should be running on two worker nodes.
- Can be scaled up to have more replicas on more nodes.
The procedures in this section require prerequisites performed by the cluster administrator.
15.3.2. Prerequisites Copy linkLink copied to clipboard!
Before starting the following procedures, the administrator must:
- Set up the external port to the cluster networking environment so that requests can reach the cluster.
Make sure there is at least one user with cluster admin role. To add this role to a user, run the following command:
oc adm policy add-cluster-role-to-user cluster-admin username
$ oc adm policy add-cluster-role-to-user cluster-admin username
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Have an OpenShift Container Platform cluster with at least one master and at least one node and a system outside the cluster that has network access to the cluster. This procedure assumes that the external system is on the same subnet as the cluster. The additional networking required for external systems on a different subnet is out-of-scope for this topic.
15.3.3. Creating a project and service Copy linkLink copied to clipboard!
If the project and service that you want to expose do not exist, first create the project, then the service.
If the project and service already exist, skip to the procedure on exposing the service to create a route.
Prerequisites
-
Install the
oc
CLI and log in as a cluster administrator.
Procedure
Create a new project for your service:
oc new-project <project_name>
$ oc new-project <project_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc new-project myproject
$ oc new-project myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc new-app
command to create a service. For example:oc new-app \ -e MYSQL_USER=admin \ -e MYSQL_PASSWORD=redhat \ -e MYSQL_DATABASE=mysqldb \ registry.redhat.io/rhscl/mysql-80-rhel7
$ oc new-app \ -e MYSQL_USER=admin \ -e MYSQL_PASSWORD=redhat \ -e MYSQL_DATABASE=mysqldb \ registry.redhat.io/rhscl/mysql-80-rhel7
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to see that the new service is created:
oc get svc -n myproject
$ oc get svc -n myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.63.31 <none> 3306/TCP 4m55s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.63.31 <none> 3306/TCP 4m55s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow By default, the new service does not have an external IP address.
15.3.4. Exposing the service by creating a route Copy linkLink copied to clipboard!
You can expose the service as a route by using the oc expose
command.
Procedure
To expose the service:
- Log in to OpenShift Container Platform.
Log in to the project where the service you want to expose is located:
oc project myproject
$ oc project myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to expose the route:
oc expose service <service_name>
$ oc expose service <service_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc expose service mysql-80-rhel7
$ oc expose service mysql-80-rhel7
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
route "mysql-80-rhel7" exposed
route "mysql-80-rhel7" exposed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use a tool, such as cURL, to make sure you can reach the service using the cluster IP address for the service:
curl <pod_ip>:<port>
$ curl <pod_ip>:<port>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
curl 172.30.131.89:3306
$ curl 172.30.131.89:3306
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The examples in this section uses a MySQL service, which requires a client application. If you get a string of characters with the
Got packets out of order
message, you are connected to the service.If you have a MySQL client, log in with the standard CLI command:
mysql -h 172.30.131.89 -u admin -p
$ mysql -h 172.30.131.89 -u admin -p
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. MySQL [(none)]>
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. MySQL [(none)]>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.3.5. Configuring Ingress Controller sharding by using route labels Copy linkLink copied to clipboard!
Ingress Controller sharding by using route labels means that the Ingress Controller serves any route in any namespace that is selected by the route selector.
Ingress Controller sharding is useful when balancing incoming traffic load among a set of Ingress Controllers and when isolating traffic to a specific Ingress Controller. For example, company A goes to one Ingress Controller and company B to another.
Procedure
Edit the
router-internal.yaml
file:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the Ingress Controller
router-internal.yaml
file:oc apply -f router-internal.yaml
# oc apply -f router-internal.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The Ingress Controller selects routes in any namespace that have the label
type: sharded
.
15.3.6. Configuring Ingress Controller sharding by using namespace labels Copy linkLink copied to clipboard!
Ingress Controller sharding by using namespace labels means that the Ingress Controller serves any route in any namespace that is selected by the namespace selector.
Ingress Controller sharding is useful when balancing incoming traffic load among a set of Ingress Controllers and when isolating traffic to a specific Ingress Controller. For example, company A goes to one Ingress Controller and company B to another.
Procedure
Edit the
router-internal.yaml
file:cat router-internal.yaml
# cat router-internal.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the Ingress Controller
router-internal.yaml
file:oc apply -f router-internal.yaml
# oc apply -f router-internal.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The Ingress Controller selects routes in any namespace that is selected by the namespace selector that have the label
type: sharded
.
15.3.7. Additional resources Copy linkLink copied to clipboard!
- The Ingress Operator manages wildcard DNS. For more information, see Ingress Operator in OpenShift Container Platform, Installing a cluster on bare metal, and Installing a cluster on vSphere.
15.4. Configuring ingress cluster traffic using a load balancer Copy linkLink copied to clipboard!
OpenShift Container Platform provides methods for communicating from outside the cluster with services running in the cluster. This method uses a load balancer.
15.4.1. Using a load balancer to get traffic into the cluster Copy linkLink copied to clipboard!
If you do not need a specific external IP address, you can configure a load balancer service to allow external access to an OpenShift Container Platform cluster.
A load balancer service allocates a unique IP. The load balancer has a single edge router IP, which can be a virtual IP (VIP), but is still a single machine for initial load balancing.
If a pool is configured, it is done at the infrastructure level, not by a cluster administrator.
The procedures in this section require prerequisites performed by the cluster administrator.
15.4.2. Prerequisites Copy linkLink copied to clipboard!
Before starting the following procedures, the administrator must:
- Set up the external port to the cluster networking environment so that requests can reach the cluster.
Make sure there is at least one user with cluster admin role. To add this role to a user, run the following command:
oc adm policy add-cluster-role-to-user cluster-admin username
$ oc adm policy add-cluster-role-to-user cluster-admin username
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Have an OpenShift Container Platform cluster with at least one master and at least one node and a system outside the cluster that has network access to the cluster. This procedure assumes that the external system is on the same subnet as the cluster. The additional networking required for external systems on a different subnet is out-of-scope for this topic.
15.4.3. Creating a project and service Copy linkLink copied to clipboard!
If the project and service that you want to expose do not exist, first create the project, then the service.
If the project and service already exist, skip to the procedure on exposing the service to create a route.
Prerequisites
-
Install the
oc
CLI and log in as a cluster administrator.
Procedure
Create a new project for your service:
oc new-project <project_name>
$ oc new-project <project_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc new-project myproject
$ oc new-project myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc new-app
command to create a service. For example:oc new-app \ -e MYSQL_USER=admin \ -e MYSQL_PASSWORD=redhat \ -e MYSQL_DATABASE=mysqldb \ registry.redhat.io/rhscl/mysql-80-rhel7
$ oc new-app \ -e MYSQL_USER=admin \ -e MYSQL_PASSWORD=redhat \ -e MYSQL_DATABASE=mysqldb \ registry.redhat.io/rhscl/mysql-80-rhel7
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to see that the new service is created:
oc get svc -n myproject
$ oc get svc -n myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.63.31 <none> 3306/TCP 4m55s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.63.31 <none> 3306/TCP 4m55s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow By default, the new service does not have an external IP address.
15.4.4. Exposing the service by creating a route Copy linkLink copied to clipboard!
You can expose the service as a route by using the oc expose
command.
Procedure
To expose the service:
- Log in to OpenShift Container Platform.
Log in to the project where the service you want to expose is located:
oc project myproject
$ oc project myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to expose the route:
oc expose service <service_name>
$ oc expose service <service_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc expose service mysql-80-rhel7
$ oc expose service mysql-80-rhel7
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
route "mysql-80-rhel7" exposed
route "mysql-80-rhel7" exposed
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use a tool, such as cURL, to make sure you can reach the service using the cluster IP address for the service:
curl <pod_ip>:<port>
$ curl <pod_ip>:<port>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
curl 172.30.131.89:3306
$ curl 172.30.131.89:3306
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The examples in this section uses a MySQL service, which requires a client application. If you get a string of characters with the
Got packets out of order
message, you are connected to the service.If you have a MySQL client, log in with the standard CLI command:
mysql -h 172.30.131.89 -u admin -p
$ mysql -h 172.30.131.89 -u admin -p
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. MySQL [(none)]>
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. MySQL [(none)]>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.4.5. Creating a load balancer service Copy linkLink copied to clipboard!
Use the following procedure to create a load balancer service.
Prerequisites
- Make sure that the project and service you want to expose exist.
Procedure
To create a load balancer service:
- Log in to OpenShift Container Platform.
Load the project where the service you want to expose is located.
oc project project1
$ oc project project1
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Open a text file on the master node and paste the following text, editing the file as needed:
Sample load balancer configuration file
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Save and exit the file.
Run the following command to create the service:
oc create -f <file-name>
$ oc create -f <file-name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc create -f mysql-lb.yaml
$ oc create -f mysql-lb.yaml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Execute the following command to view the new service:
oc get svc
$ oc get svc
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE egress-2 LoadBalancer 172.30.22.226 ad42f5d8b303045-487804948.example.com 3306:30357/TCP 15m
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE egress-2 LoadBalancer 172.30.22.226 ad42f5d8b303045-487804948.example.com 3306:30357/TCP 15m
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The service has an external IP address automatically assigned if there is a cloud provider enabled.
On the master, use a tool, such as cURL, to make sure you can reach the service using the public IP address:
curl <public-ip>:<port>
$ curl <public-ip>:<port>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
curl 172.29.121.74:3306
$ curl 172.29.121.74:3306
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The examples in this section use a MySQL service, which requires a client application. If you get a string of characters with the
Got packets out of order
message, you are connecting with the service:If you have a MySQL client, log in with the standard CLI command:
mysql -h 172.30.131.89 -u admin -p
$ mysql -h 172.30.131.89 -u admin -p
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. MySQL [(none)]>
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. MySQL [(none)]>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.5. Configuring ingress cluster traffic for a service external IP Copy linkLink copied to clipboard!
You can attach an external IP address to a service so that it is available to traffic outside the cluster. This is generally useful only for a cluster installed on bare metal hardware. The external network infrastructure must be configured correctly to route traffic to the service.
15.5.1. Prerequisites Copy linkLink copied to clipboard!
- Your cluster is configured with ExternalIPs enabled. For more information, read Configuring ExternalIPs for services.
15.5.2. Attaching an ExternalIP to a service Copy linkLink copied to clipboard!
You can attach an ExternalIP to a service. If your cluster is configured to allocate an ExternalIP automatically, you might not need to manually attach an ExternalIP to the service.
Procedure
Optional: To confirm what IP address ranges are configured for use with ExternalIP, enter the following command:
oc get networks.config cluster -o jsonpath='{.spec.externalIP}{"\n"}'
$ oc get networks.config cluster -o jsonpath='{.spec.externalIP}{"\n"}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow If
autoAssignCIDRs
is set, OpenShift Container Platform automatically assigns an ExternalIP to a newService
object if thespec.externalIPs
field is not specified.Attach an ExternalIP to the service.
If you are creating a new service, specify the
spec.externalIPs
field and provide an array of one or more valid IP addresses. For example:Copy to Clipboard Copied! Toggle word wrap Toggle overflow If you are attaching an ExternalIP to an existing service, enter the following command. Replace
<name>
with the service name. Replace<ip_address>
with a valid ExternalIP address. You can provide multiple IP addresses separated by commas.Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc patch svc mysql-55-rhel7 -p '{"spec":{"externalIPs":["192.174.120.10"]}}'
$ oc patch svc mysql-55-rhel7 -p '{"spec":{"externalIPs":["192.174.120.10"]}}'
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
"mysql-55-rhel7" patched
"mysql-55-rhel7" patched
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
To confirm that an ExternalIP address is attached to the service, enter the following command. If you specified an ExternalIP for a new service, you must create the service first.
oc get svc
$ oc get svc
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-55-rhel7 172.30.131.89 192.174.120.10 3306/TCP 13m
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-55-rhel7 172.30.131.89 192.174.120.10 3306/TCP 13m
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
15.5.3. Additional resources Copy linkLink copied to clipboard!
15.6. Configuring ingress cluster traffic using a NodePort Copy linkLink copied to clipboard!
OpenShift Container Platform provides methods for communicating from outside the cluster with services running in the cluster. This method uses a NodePort
.
15.6.1. Using a NodePort to get traffic into the cluster Copy linkLink copied to clipboard!
Use a NodePort
-type Service
resource to expose a service on a specific port on all nodes in the cluster. The port is specified in the Service
resource’s .spec.ports[*].nodePort
field.
Using a node port requires additional port resources.
A NodePort
exposes the service on a static port on the node’s IP address. NodePort
s are in the 30000
to 32767
range by default, which means a NodePort
is unlikely to match a service’s intended port. For example, port 8080
may be exposed as port 31020
on the node.
The administrator must ensure the external IP addresses are routed to the nodes.
NodePort
s and external IPs are independent and both can be used concurrently.
The procedures in this section require prerequisites performed by the cluster administrator.
15.6.2. Prerequisites Copy linkLink copied to clipboard!
Before starting the following procedures, the administrator must:
- Set up the external port to the cluster networking environment so that requests can reach the cluster.
Make sure there is at least one user with cluster admin role. To add this role to a user, run the following command:
oc adm policy add-cluster-role-to-user cluster-admin <user_name>
$ oc adm policy add-cluster-role-to-user cluster-admin <user_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Have an OpenShift Container Platform cluster with at least one master and at least one node and a system outside the cluster that has network access to the cluster. This procedure assumes that the external system is on the same subnet as the cluster. The additional networking required for external systems on a different subnet is out-of-scope for this topic.
15.6.3. Creating a project and service Copy linkLink copied to clipboard!
If the project and service that you want to expose do not exist, first create the project, then the service.
If the project and service already exist, skip to the procedure on exposing the service to create a route.
Prerequisites
-
Install the
oc
CLI and log in as a cluster administrator.
Procedure
Create a new project for your service:
oc new-project <project_name>
$ oc new-project <project_name>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
oc new-project myproject
$ oc new-project myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Use the
oc new-app
command to create a service. For example:oc new-app \ -e MYSQL_USER=admin \ -e MYSQL_PASSWORD=redhat \ -e MYSQL_DATABASE=mysqldb \ registry.redhat.io/rhscl/mysql-80-rhel7
$ oc new-app \ -e MYSQL_USER=admin \ -e MYSQL_PASSWORD=redhat \ -e MYSQL_DATABASE=mysqldb \ registry.redhat.io/rhscl/mysql-80-rhel7
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following command to see that the new service is created:
oc get svc -n myproject
$ oc get svc -n myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.63.31 <none> 3306/TCP 4m55s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.63.31 <none> 3306/TCP 4m55s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow By default, the new service does not have an external IP address.
15.6.4. Exposing the service by creating a route Copy linkLink copied to clipboard!
You can expose the service as a route by using the oc expose
command.
Procedure
To expose the service:
- Log in to OpenShift Container Platform.
Log in to the project where the service you want to expose is located:
oc project myproject
$ oc project myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow To expose a node port for the application, enter the following command. OpenShift Container Platform automatically selects an available port in the
30000-32767
range.oc expose dc mysql-80-rhel7 --type=NodePort --name=mysql-ingress
$ oc expose dc mysql-80-rhel7 --type=NodePort --name=mysql-ingress
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To confirm the service is available with a node port exposed, enter the following command:
oc get svc -n myproject
$ oc get svc -n myproject
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.217.127 <none> 3306/TCP 9m44s mysql-ingress NodePort 172.30.107.72 <none> 3306:31345/TCP 39s
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql-80-rhel7 ClusterIP 172.30.217.127 <none> 3306/TCP 9m44s mysql-ingress NodePort 172.30.107.72 <none> 3306:31345/TCP 39s
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To remove the service created automatically by the
oc new-app
command, enter the following command:oc delete svc mysql-80-rhel7
$ oc delete svc mysql-80-rhel7
Copy to Clipboard Copied! Toggle word wrap Toggle overflow