$ oc get networks.config cluster -o jsonpath='{.spec.externalIP}{"\n"}'
You can use either a MetalLB implementation or an IP failover deployment to attach an ExternalIP resource to a service so that the service is available to traffic outside your OKD cluster. Hosting an external IP address in this way is only applicable for a cluster installed on bare-metal hardware.
You must ensure that you correctly configure the external network infrastructure to route traffic to the service.
Your cluster is configured with ExternalIPs enabled. For more information, read Configuring ExternalIPs for services.
Do not use the same ExternalIP for the egress IP. |
You can attach an ExternalIP resource to a service. If you configured your cluster to automatically attach the resource to a service, you might not need to manually attach an ExternalIP to the service.
The examples in the procedure use a scenario that manually attaches an ExternalIP resource to a service in a cluster with an IP failover configuration.
Confirm compatible IP address ranges for the ExternalIP resource by entering the following command in your CLI:
$ oc get networks.config cluster -o jsonpath='{.spec.externalIP}{"\n"}'
If |
Choose one of the following options to attach an ExternalIP resource to the service:
If you are creating a new service, specify a value in the spec.externalIPs
field and array of one or more valid IP addresses in the allowedCIDRs
parameter.
apiVersion: v1
kind: service
metadata:
name: svc-with-externalip
spec:
externalIPs:
policy:
allowedCIDRs:
- 192.168.123.0/28
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.
$ oc patch svc <name> -p \
'{
"spec": {
"externalIPs": [ "<ip_address>" ]
}
}'
For example:
$ oc patch svc mysql-55-rhel7 -p '{"spec":{"externalIPs":["192.174.120.10"]}}'
"mysql-55-rhel7" patched
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
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysql-55-rhel7 172.30.131.89 192.174.120.10 3306/TCP 13m