
Egress provides a way for an application deployed on OpenShift to access an external URL, such as http://www.example.com.
There are two common types of network types using by OpenShift
- OpenShiftSDN
- OVNKubernetes
The following command can be used to determine if your OpenShift cluster is using OpenShiftSDN or OVNKubernetes.
oc get network.config/cluster --output jsonpath="{.spec.networkType}"
- If your OpenShift cluster is using OpenShiftSDN, then NetNamespace is used to assign an egress IP address to one or more namespaces.
- If your OpenShift cluster is using OVNKubernetes, then EgressIP (this article) is used to assign an egress IP address to one or more namespaces.
EgressIP is used to assign an egress IP address to one or more namespaces, so that all egress traffic from the namespace is using a dedicated IP address. By assigning a specific egress IP address to a namespace, all outbound (egress) requests from applications in the project will come from the dedicated egress IP address, making it easier to find the requests that came from applications in the project. This also makes it possible to have two (or more) different projects share the same egress IP address, as a way to group similar projects together.
An OpenShift route or an Ingress route will provide a URL such as http://route001-project001.apps.openshift.example.com:8080 which is used to route a request onto a service, which is then routed onto a pod, and then to the container in the pod, and finally to the application running in the container.
If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.
The oc get egressip command can be used to list the egress IP addresses associated with a project / namespace. By default, a project will not have a dedicated egress IP address.
~]$ oc get egressip
NAME EGRESSIPS ASSIGNED NODE ASSIGNED EGRESSIPS
egressip-my-project 10.11.12.13 edge-78v55 10.11.12.13
egressip-foo-project 10.11.12.14 edge-78v55 10.11.12.14
egressip-bar-project 10.11.12.15 edge-78v55 10.11.12.13
AVOID TROUBLE
The egress IP address must be in the same subnet as the nodes primary IP address. For example, if the node's primary IP address is 10.7.1.2/8 then the egress IP adress would need to be in the 10.x.x.x/8 subnet.
Let's say you have the following YAML file. This will create the egressip resource mapping IP address 10.11.12.13 to namespace my-project.
apiVersion: k8s.ovn.org/v1
kind: EgressIP
metadata:
name: my-project
spec:
egressIPs:
- 10.11.12.13
namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: my-project
The oc apply command can be used to create the egressip resource.
oc apply --filename egress.yml
Did you find this article helpful?
If so, consider buying me a coffee over at