Configuring an egress IP address

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

Egress IP address architectural design and implementation

The OKD egress IP address functionality allows you to 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 is implemented as an additional IP address on the primary network interface of a node and must be in the same subnet as the primary IP address of the node. The additional IP address must not be assigned to any other node in the cluster.

Platform support

Support for the egress IP address functionality on various platforms is summarized in the following table:

The egress IP address implementation is not compatible with Amazon Web Services (AWS), Azure Cloud, or any other public cloud platform incompatible with the automatic layer 2 network manipulation required by the egress IP feature.

PlatformSupported

Bare metal

Yes

vSphere

Yes

Red Hat OpenStack Platform (RHOSP)

No

Public cloud

No

Assignment of egress IPs to pods

To assign one or more egress IPs to a namespace or specific pods in a namespace, the following conditions must be satisfied:

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

If you create EgressIP objects prior to labeling any nodes in your cluster for egress IP assignment, OKD 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 intent to host the egress IP addresses before creating any EgressIP objects.

Assignment of egress IPs to nodes

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, no node will ever host more than one of the specified addresses.

  • If a node becomes unavailable, any egress IP addresses assigned to it are automatically reassigned, subject to the previously described conditions.

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.

Architectural diagram of an egress IP address configuration

The following diagram depicts an egress IP address configuration. The diagram describes four pods in two different namespaces running on three nodes in a cluster. The nodes are assigned IP addresses from the 192.168.126.0/18 CIDR block on the host network.

Architectural diagram for the egress IP feature.

Both Node 1 and Node 3 are labeled with k8s.ovn.org/egress-assignable: "" and thus available for the assignment of egress IP addresses.

The dashed lines in the diagram depict the traffic flow from pod1, pod2, and pod3 traveling through the pod network to egress the cluster from Node 1 and Node 3. When an external service receives traffic from any of the pods selected by the example EgressIP object, the source IP address is either 192.168.126.10 or 192.168.126.102.

The following resources from the diagram are illustrated in detail:

Namespace objects

The namespaces are defined in the following manifest:

Namespace objects

  1. apiVersion: v1
  2. kind: Namespace
  3. metadata:
  4. name: namespace1
  5. labels:
  6. env: prod
  7. ---
  8. apiVersion: v1
  9. kind: Namespace
  10. metadata:
  11. name: namespace2
  12. labels:
  13. env: prod

EgressIP object

The following EgressIP object describes a configuration that selects all pods in any namespace with the env label set to prod. The egress IP addresses for the selected pods are 192.168.126.10 and 192.168.126.102.

EgressIP object

  1. apiVersion: k8s.ovn.org/v1
  2. kind: EgressIP
  3. metadata:
  4. name: egressips-prod
  5. spec:
  6. egressIPs:
  7. - 192.168.126.10
  8. - 192.168.126.102
  9. namespaceSelector:
  10. matchLabels:
  11. env: prod
  12. status:
  13. assignments:
  14. - node: node1
  15. egressIP: 192.168.126.10
  16. - node: node3
  17. egressIP: 192.168.126.102

For the configuration in the previous example, OKD assigns both egress IP addresses to the available nodes. The status field reflects whether and where the egress IP addresses are assigned.

EgressIP object

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

  1. apiVersion: k8s.ovn.org/v1
  2. kind: EgressIP
  3. metadata:
  4. name: <name> (1)
  5. spec:
  6. egressIPs: (2)
  7. - <ip_address>
  8. namespaceSelector: (3)
  9. ...
  10. podSelector: (4)
  11. ...
1The name for the EgressIPs object.
2An array of one or more IP addresses.
3One or more selectors for the namespaces to associate the egress IP addresses with.
4Optional: 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

  1. namespaceSelector: (1)
  2. matchLabels:
  3. <label_name>: <label_value>
1One 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

  1. podSelector: (1)
  2. matchLabels:
  3. <label_name>: <label_value>
1Optional: 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

  1. apiVersion: k8s.ovn.org/v1
  2. kind: EgressIP
  3. metadata:
  4. name: egress-group1
  5. spec:
  6. egressIPs:
  7. - 192.168.126.11
  8. - 192.168.126.102
  9. podSelector:
  10. matchLabels:
  11. app: web
  12. namespaceSelector:
  13. matchLabels:
  14. 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

  1. apiVersion: k8s.ovn.org/v1
  2. kind: EgressIP
  3. metadata:
  4. name: egress-group2
  5. spec:
  6. egressIPs:
  7. - 192.168.127.30
  8. - 192.168.127.40
  9. namespaceSelector:
  10. matchExpressions:
  11. - key: environment
  12. operator: NotIn
  13. values:
  14. - development

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 OKD can assign one or more egress IP addresses to the node.

Prerequisites

  • Install the OpenShift CLI (oc).

  • Log 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:

    1. $ oc label nodes <node_name> k8s.ovn.org/egress-assignable="" (1)
    1The name of the node to label.

Next steps

Additional resources