Assigning an egress IP address to a namespace
You can assign one or more egress IP addresses to a namespace or to specific pods in a namespace.
-
The OpenShift CLI (
oc) is installed. -
You are logged in to the cluster as a cluster administrator.
-
At least one node is configured to host an egress IP address.
-
Create an
EgressIPobject.-
Create a
<egressips_name>.yamlfile where<egressips_name>is the name of the object. -
In the file that you created, define an
EgressIPobject, as in the following example:apiVersion: k8s.ovn.org/v1 kind: EgressIP metadata: name: egress-project1 spec: egressIPs: - 192.168.127.10 - 192.168.127.11 namespaceSelector: matchLabels: env: qa # ...
-
-
To create the object, enter the following command.
$ oc apply -f <egressips_name>.yamlwhere:
<egressips_name>-
Replace
<egressips_name>with the name of the object.
Example outputegressips.k8s.ovn.org/<egressips_name> created -
Optional: Store the
<egressips_name>.yamlfile so that you can make changes later. -
Add labels to the namespace that requires egress IP addresses. To add a label to the namespace of an
EgressIPobject defined in a previous step, run the following command:$ oc label ns <namespace> env=qawhere:
<namespace>-
Replace
<namespace>with the namespace that requires egress IP addresses.
-
To show all egress IP addresses that are in use in your cluster, enter the following command:
$ oc get egressip -o yamlThe command
oc get egressiponly returns one egress IP address regardless of how many are configured. This is not a bug and is a limitation of Kubernetes. As a workaround, you can pass in the-o yamlor-o jsonflags to return all egress IPs addresses in use.Example output# ... spec: egressIPs: - 192.168.127.10 - 192.168.127.11 # ...