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.15.5. Configuring ingress cluster traffic for a service external IP
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 复制链接链接已复制到粘贴板!
- Your cluster is configured with ExternalIPs enabled. For more information, read Configuring ExternalIPs for services.
15.5.2. Attaching an ExternalIP to a service 复制链接链接已复制到粘贴板!
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