Chapter 9. Configuring an egress IP address


As a cluster administrator, you can configure the OVN-Kubernetes Container Network Interface (CNI) network plugin to assign one or more egress IP addresses to a namespace, or to specific pods in a namespace.

By using the OpenShift Container Platform egress IP address functionality, you can ensure that the traffic from one or more pods in one or more namespaces has a consistent source IP address for services outside the cluster network.

For example, you might have a pod that periodically queries a database that is hosted on a server outside of your cluster. To enforce access requirements for the server, a packet filtering device is configured to allow traffic only from specific IP addresses.

To ensure that you can reliably allow access to the server from only that specific pod, you can configure a specific egress IP address for the pod that makes the requests to the server.

An egress IP address assigned to a namespace is different from an egress router, which is used to send traffic to specific destinations.

In some cluster configurations, application pods and ingress router pods run on the same node. If you configure an egress IP address for an application project in this scenario, the IP address is not used when you send a request to a route from the application project.

Important

Egress IP addresses must not be configured in any Linux network configuration files, such as ifcfg-eth0.

Important

The assignment of egress IP addresses to control plane nodes with the EgressIP feature is not supported on a cluster provisioned on Amazon Web Services (AWS). For more information, see "BZ#2039656" in the Additional resources section.

The following examples illustrate the annotation from nodes on several public cloud providers. The annotations are indented for readability.

Example cloud.network.openshift.io/egress-ipconfig annotation on AWS

cloud.network.openshift.io/egress-ipconfig: [
  {
    "interface":"eni-078d267045138e436",
    "ifaddr":{"ipv4":"10.0.128.0/18"},
    "capacity":{"ipv4":14,"ipv6":15}
  }
]

The following sections describe the IP address capacity for supported public cloud environments for use in your capacity calculation.

Amazon Web Services (AWS) IP address capacity limits
On AWS, constraints on IP address assignments depend on the instance type configured. For more information, see "IP addresses per network interface per instance type" in the Additional resources section.
Google Cloud IP address capacity limits
On Google Cloud, the networking model implements additional node IP addresses through IP address aliasing, rather than IP address assignments. However, IP address capacity maps directly to IP aliasing capacity.

The following capacity limits exist for IP aliasing assignment:

  • Per node, the maximum number of IP aliases, both IPv4 and IPv6, is 100.
  • Per VPC, the maximum number of IP aliases is unspecified, but OpenShift Container Platform scalability testing reveals the maximum to be approximately 15,000.

For more information, see "Per instance" quotas and "Alias IP ranges overview" in the Additional resources section.

Microsoft Azure IP address capacity limits

On Azure, the following capacity limits exist for IP address assignment:

  • Per NIC, the maximum number of assignable IP addresses, for both IPv4 and IPv6, is 256.
  • Per virtual network, the maximum number of assigned IP addresses cannot exceed 65,536.

For more information, see "Networking limits" in the Additional resources section.

9.3. EgressIP object

You can view YAML files to better understand how you can effectively configure an EgressIP object to better meet your needs.

When the EgressIP namespace selector matches the label on multiple namespaces, consider the following behaviors:

  • All traffic for selected pods must pass through a single node. During times of high traffic, the network interface of the node might experience performance issues.
  • An error in a label selector might change the outbound IP address for many cluster namespaces.
  • Only a cluster administrator can create or change cluster-scoped objects.
  • Packets must move from a pod that exists in a node to the named host node that is referenced in the EgressIP object. This approach adds a network hop.
Important

Do not create egress rules, such as a single label selector, that forces all namespaces that exist in a cluster to use the same outbound IP address. This configuration can cause the node that hosts the IP address to crash during times of high network traffic.

The following YAML describes the API for the EgressIP object. The scope of the object is cluster-wide and is not created in a namespace.

apiVersion: k8s.ovn.org/v1
kind: EgressIP
metadata:
  name: <name>
spec:
  egressIPs:
  - <ip_address>
  namespaceSelector:
    ...
  podSelector:
    ...

where:

<name>
Specifies the name for the EgressIPs object.
<egressIPs>
Specifies an array of one or more IP addresses.
<namespaceSelector>
Specifies one or more selectors for the namespaces to associate the egress IP addresses with.
<podSelector>
Optional parameter. Specifies one or more selectors for pods in the specified namespaces to associate egress IP addresses with. Applying these selectors allows for the selection of a subset of pods within a namespace.

The following YAML describes the stanza for the namespace selector:

Namespace selector stanza

namespaceSelector:
  matchLabels:
    <label_name>: <label_value>

where:

<namespaceSelector>
Specifies one or more matching rules for namespaces. If more than one match rule is provided, all matching namespaces are selected.

The following YAML describes the optional stanza for the pod selector:

Pod selector stanza

podSelector:
  matchLabels:
    <label_name>: <label_value>

where:

<podSelector>
Optional parameter. Specifies one or more matching rules for pods in the namespaces that match the specified namespaceSelector rules. If specified, only pods that match are selected. Others pods in the namespace are not selected.

In the following example, the EgressIP object associates the 192.168.126.11 and 192.168.126.102 egress IP addresses with pods that have the app label set to web and are in the namespaces that have the env label set to prod:

Example EgressIP object

apiVersion: k8s.ovn.org/v1
kind: EgressIP
metadata:
  name: egress-group1
spec:
  egressIPs:
  - 192.168.126.11
  - 192.168.126.102
  podSelector:
    matchLabels:
      app: web
  namespaceSelector:
    matchLabels:
      env: prod

In the following example, the EgressIP object associates the 192.168.127.30 and 192.168.127.40 egress IP addresses with any pods that do not have the environment label set to development:

Example EgressIP object

apiVersion: k8s.ovn.org/v1
kind: EgressIP
metadata:
  name: egress-group2
spec:
  egressIPs:
  - 192.168.127.30
  - 192.168.127.40
  namespaceSelector:
    matchExpressions:
    - key: environment
      operator: NotIn
      values:
      - development

To assign one or more egress IPs to a namespace or specific pods in a namespace, you must meet specific conditions.

  • At least one node in your cluster must have the k8s.ovn.org/egress-assignable: "" label.
  • An EgressIP object exists that defines one or more egress IP addresses to use as the source IP address for traffic leaving the cluster from pods in a namespace.
Important

If you create EgressIP objects prior to labeling any nodes in your cluster for egress IP assignment, OpenShift Container Platform might assign every egress IP address to the first node with the k8s.ovn.org/egress-assignable: "" label.

To ensure that egress IP addresses are widely distributed across nodes in the cluster, always apply the label to the nodes you intend to host the egress IP addresses before creating any EgressIP objects.

When creating an EgressIP object, the following conditions apply to nodes that are labeled with the k8s.ovn.org/egress-assignable: "" label:

  • An egress IP address is never assigned to more than one node at a time.
  • An egress IP address is equally balanced between available nodes that can host the egress IP address.
  • If the spec.EgressIPs array in an EgressIP object specifies more than one IP address, the following conditions apply:

    • No node will ever host more than one of the specified IP addresses.
    • Traffic is balanced roughly equally between the specified IP addresses for a given namespace.
  • If a node becomes unavailable, any egress IP addresses assigned to it are automatically reassigned, subject to the previously described conditions.
Important

If the number of nodes labeled with k8s.ovn.org/egress-assignable is less than the number of egress IP addresses specified in the EgressIP object, the additional egress IP addresses remain unassigned. To ensure all specified egress IP addresses are active and traffic is balanced as expected, verify that the number of egress-assignable nodes is equal to or greater than the number of egress IP addresses defined in the EgressIP object.

When a pod matches the selector for multiple EgressIP objects, there is no guarantee which of the egress IP addresses that are specified in the EgressIP objects is assigned as the egress IP address for the pod.

Additionally, if an EgressIP object specifies multiple egress IP addresses, there is no guarantee which of the egress IP addresses might be used. For example, if a pod matches a selector for an EgressIP object with two egress IP addresses, 10.10.20.1 and 10.10.20.2, either might be used for each TCP connection or UDP conversation.

9.5. 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.

Prerequisites

  • 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.

Procedure

  1. Create an EgressIP object.

    1. Create a <egressips_name>.yaml file where <egressips_name> is the name of the object.
    2. In the file that you created, define an EgressIP object, 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
      # ...
  2. To create the object, enter the following command.

    $ oc apply -f <egressips_name>.yaml

    where:

    <egressips_name>
    Replace <egressips_name> with the name of the object.

    Example output

    egressips.k8s.ovn.org/<egressips_name> created

  3. Optional: Store the <egressips_name>.yaml file so that you can make changes later.
  4. Add labels to the namespace that requires egress IP addresses. To add a label to the namespace of an EgressIP object defined in a previous step, run the following command:

    $ oc label ns <namespace> env=qa

    where:

    <namespace>
    Replace <namespace> with the namespace that requires egress IP addresses.

Verification

  • To show all egress IP addresses that are in use in your cluster, enter the following command:

    $ oc get egressip -o yaml
    Note

    The command oc get egressip only 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 yaml or -o json flags to return all egress IPs addresses in use.

    Example output

    # ...
    spec:
      egressIPs:
      - 192.168.127.10
      - 192.168.127.11
    # ...

9.6. Understanding EgressIP failover control

The reachabilityTotalTimeoutSeconds parameter controls how quickly the system detects a failing egressIP node and initiates a failover. This parameter directly determines the maximum time the platform waits before declaring a node unreachable.

Important

When you configure egressIP with multiple egress nodes, the complete failover time from node failure to recovery on a new node is expected to be on the order of seconds or longer. This is because the new IP assignment can only begin after the reachabilityTotalTimeoutSeconds period has fully elapsed without a successful check.

To ensure traffic uses the correct external path, egressIP traffic on a node will always egress through the network interface on which the egressIP address has been assigned.

You can configure the reachabilityTotalTimeoutSeconds parameter to control how quickly the system detects a failing egressIP node and initiates a failover.

Prerequisites

  • You installed the OpenShift CLI (oc).
  • You logged in to the cluster as a cluster administrator.

Procedure

  1. Edit the Network custom resource by running the following command:

    $ oc edit network.operator cluster
  2. Navigate to the egressIPConfig: {} section under spec:defaultNetwork:ovnKubernetesConfig:
  3. Modify the block to include the reachabilityTotalTimeoutSeconds parameter with your chosen value, 5 seconds for example. Make sure to use the correct indentation:

      defaultNetwork:
        ovnKubernetesConfig:
          egressIPConfig:
            reachabilityTotalTimeoutSeconds: 5
    Note

    The value must be an integer between 0 and 60. For details on possible values, see the "EgressIP failover settings" section.

  4. Save and exit the editor. The operator automatically applies the changes.

Verification

  1. Verify that the system correctly accepted the reachabilityTotalTimeoutSeconds parameter by running the following command:

    $ oc get network.operator cluster -o yaml
  2. Inspect the output and confirm that the reachabilityTotalTimeoutSeconds parameter is correctly nested under spec:defaultNetwork:ovnKubernetesConfig:egressIPConfig: with your intended value:

     # ...
      spec:
        # ...
        defaultNetwork:
          ovnKubernetesConfig:
            egressIPConfig:
              reachabilityTotalTimeoutSeconds: 5
            gatewayConfig:
      # ...

9.6.2. EgressIP failover settings

The reachabilityTotalTimeoutSeconds parameter defines the total time limit in seconds for the platform health check process before a node is declared down.

The following table summarizes the acceptable values and their implications:

Expand
Parameter Value (Seconds)Effect on reachability checkFailover impact and use case

0

Disables the reachability check.

No automatic failover: Use only if an external system handles node health monitoring and failover. The platform will not automatically react to node failures.

1 - 60

Sets the total time limit for reachability probing.

Directly controls detection time: This value defines the lower limit for your overall failover time. A smaller value leads to faster failover but might increase network traffic. Default: 1 second. The maximum accepted integer value is 60.

9.7. Labeling a node to host egress IP addresses

You can apply the k8s.ovn.org/egress-assignable="" label to a node in your cluster so that OpenShift Container Platform can assign one or more egress IP addresses to the node.

Prerequisites

  • You installed the OpenShift CLI (oc).
  • You logged in to the cluster as a cluster administrator.

Procedure

  • To label a node so that it can host one or more egress IP addresses, enter the following command:

    $ oc label nodes <node_name> k8s.ovn.org/egress-assignable=""
    <node_name>

    Specifies the name of the node to label.

    Tip

    You can alternatively apply the following YAML to add the label to a node:

    apiVersion: v1
    kind: Node
    metadata:
      labels:
        k8s.ovn.org/egress-assignable: ""
      name: <node_name>

For a cluster configured for dual-stack networking, you can apply dual-stack networking to a single EgressIP object. The EgressIP object can then extend dual-stack networking capabilities to a pod.

Important

Red Hat does not support creating two EgressIP objects to represent dual-stack networking capabilities. For example, specifying IPv4 addresses with one object and using another object to specify IPv6 addresses. This configuration limit impacts address-type assignments to pods.

Prerequisites

  • You created two egress nodes so that an EgressIP object can allocate IPv4 addresses to one node and IPv6 addresses to the other node. For more information, see "Assignment of egress IP addresses to nodes".

Procedure

  • Create an EgressIP object and configure IPv4 and IPv6 addresses for the object. The following example EgressIP object uses selectors to identify which pods use the specified egress IP addresses for their outbound traffic:

    kind: EgressIP
    metadata:
      name: egressip-dual
    spec:
      egressIPs:
        - 192.168.118.30
        - 2600:52:7:94::30
      namespaceSelector:
        matchLabels:
          env: qa
      podSelector:
        matchLabels:
          egressip: ds
    # ...

Verification

  1. Create a Pod manifest file to test and validate your EgressIP object. The pod serves as a client workload that sends outbound traffic to verify that your EgressIP policy works as expected.

    apiVersion: v1
    kind: Pod
    metadata:
      name: ubi-egressip-pod
      namespace: test
      labels:
        egressip: ds
    spec:
      containers:
      - name: fedora-curl
        image: registry.redhat.io/ubi9/ubi
        command: ["/bin/bash", "-c", "sleep infinity"]
    # ...

    where:

    <labels>
    Sets custom identifiers so that the EgressIP object can use these labels to apply egress IP address to target pods.
  2. Run a curl request from inside a pod to an external server. This action verifies that outbound traffic correctly uses an address that you specified in the EgressIP object.

    $ curl <ipv_address>

    where:

    <ipv_address>
    Depending on the EgressIP object, enter an IPv4 or IPv6 address.
Red Hat logoGithubredditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat Documentation

Legal Notice

Theme

© 2026 Red Hat
Back to top