Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.
Chapter 12. Tutorial: Assigning a consistent egress IP for external traffic
You can assign a consistent IP address for traffic that leaves your cluster such as security groups which require an IP-based configuration to meet security standards.
By default, Red Hat OpenShift Service on AWS uses the OVN-Kubernetes container network interface (CNI) to assign random IP addresses from a pool. This can make configuring security lockdowns unpredictable or open.
See Configuring an egress IP address for more information.
Objectives
- Learn how to configure a set of predictable IP addresses for egress cluster traffic.
Prerequisites
- A Red Hat OpenShift Service on AWS cluster deployed with OVN-Kubernetes
-
The OpenShift CLI (
oc
) -
The ROSA CLI (
rosa
) -
jq
12.1. Setting your environment variables Link kopierenLink in die Zwischenablage kopiert!
Set your environment variables by running the following command:
NoteReplace the value of the
ROSA_MACHINE_POOL_NAME
variable to target a different machine pool.export ROSA_CLUSTER_NAME=$(oc get infrastructure cluster -o=jsonpath="{.status.infrastructureName}" | sed 's/-[a-z0-9]\{5\}$//') export ROSA_MACHINE_POOL_NAME=worker
$ export ROSA_CLUSTER_NAME=$(oc get infrastructure cluster -o=jsonpath="{.status.infrastructureName}" | sed 's/-[a-z0-9]\{5\}$//') $ export ROSA_MACHINE_POOL_NAME=worker
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.2. Ensuring capacity Link kopierenLink in die Zwischenablage kopiert!
The number of IP addresses assigned to each node is limited for each public cloud provider.
Verify sufficient capacity by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.3. Creating the egress IP rules Link kopierenLink in die Zwischenablage kopiert!
Before creating the egress IP rules, identify which egress IPs you will use.
NoteThe egress IPs that you select should exist as a part of the subnets in which the worker nodes are provisioned.
Optional: Reserve the egress IPs that you requested to avoid conflicts with the AWS Virtual Private Cloud (VPC) Dynamic Host Configuration Protocol (DHCP) service.
Request explicit IP reservations on the AWS documentation for CIDR reservations page.
12.4. Assigning an egress IP to a namespace Link kopierenLink in die Zwischenablage kopiert!
Create a new project by running the following command:
oc new-project demo-egress-ns
$ oc new-project demo-egress-ns
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the egress rule for all pods within the namespace by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.5. Assigning an egress IP to a pod Link kopierenLink in die Zwischenablage kopiert!
Create a new project by running the following command:
oc new-project demo-egress-pod
$ oc new-project demo-egress-pod
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the egress rule for the pod by running the following command:
Notespec.namespaceSelector
is a mandatory field.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.5.1. Labeling the nodes Link kopierenLink in die Zwischenablage kopiert!
Obtain your pending egress IP assignments by running the following command:
oc get egressips
$ oc get egressips
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME EGRESSIPS ASSIGNED NODE ASSIGNED EGRESSIPS demo-egress-ns 10.10.100.253 demo-egress-pod 10.10.100.254
NAME EGRESSIPS ASSIGNED NODE ASSIGNED EGRESSIPS demo-egress-ns 10.10.100.253 demo-egress-pod 10.10.100.254
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The egress IP rule that you created only applies to nodes with the
k8s.ovn.org/egress-assignable
label. Make sure that the label is only on a specific machine pool.Assign the label to your machine pool using the following command:
WarningIf you rely on node labels for your machine pool, this command will replace those labels. Be sure to input your desired labels into the
--labels
field to ensure your node labels remain.rosa update machinepool ${ROSA_MACHINE_POOL_NAME} \ --cluster="${ROSA_CLUSTER_NAME}" \ --labels "k8s.ovn.org/egress-assignable="
$ rosa update machinepool ${ROSA_MACHINE_POOL_NAME} \ --cluster="${ROSA_CLUSTER_NAME}" \ --labels "k8s.ovn.org/egress-assignable="
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.5.2. Reviewing the egress IPs Link kopierenLink in die Zwischenablage kopiert!
Review the egress IP assignments by running the following command:
oc get egressips
$ oc get egressips
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
NAME EGRESSIPS ASSIGNED NODE ASSIGNED EGRESSIPS demo-egress-ns 10.10.100.253 ip-10-10-156-122.ec2.internal 10.10.150.253 demo-egress-pod 10.10.100.254 ip-10-10-156-122.ec2.internal 10.10.150.254
NAME EGRESSIPS ASSIGNED NODE ASSIGNED EGRESSIPS demo-egress-ns 10.10.100.253 ip-10-10-156-122.ec2.internal 10.10.150.253 demo-egress-pod 10.10.100.254 ip-10-10-156-122.ec2.internal 10.10.150.254
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.6. Verification Link kopierenLink in die Zwischenablage kopiert!
12.6.1. Deploying a sample application Link kopierenLink in die Zwischenablage kopiert!
To test the egress IP rule, create a service that is restricted to the egress IP addresses which we have specified. This simulates an external service that is expecting a small subset of IP addresses.
Run the
echoserver
command to replicate a request:oc -n default run demo-service --image=gcr.io/google_containers/echoserver:1.4
$ oc -n default run demo-service --image=gcr.io/google_containers/echoserver:1.4
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Expose the pod as a service and limit the ingress to the egress IP addresses you specified by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Retrieve the load balancer hostname and save it as an environment variable by running the following command:
export LOAD_BALANCER_HOSTNAME=$(oc get svc -n default demo-service -o json | jq -r '.status.loadBalancer.ingress[].hostname')
$ export LOAD_BALANCER_HOSTNAME=$(oc get svc -n default demo-service -o json | jq -r '.status.loadBalancer.ingress[].hostname')
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.6.2. Testing the namespace egress Link kopierenLink in die Zwischenablage kopiert!
Start an interactive shell to test the namespace egress rule:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a request to the load balancer and ensure that you can successfully connect:
curl -s http://$LOAD_BALANCER_HOSTNAME
$ curl -s http://$LOAD_BALANCER_HOSTNAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the output for a successful connection:
NoteThe
client_address
is the internal IP address of the load balancer not your egress IP. You can verify that you have configured the client address correctly by connecting with your service limited to.spec.loadBalancerSourceRanges
.Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Exit the pod by running the following command:
exit
$ exit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.6.3. Testing the pod egress Link kopierenLink in die Zwischenablage kopiert!
Start an interactive shell to test the pod egress rule:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a request to the load balancer by running the following command:
curl -s http://$LOAD_BALANCER_HOSTNAME
$ curl -s http://$LOAD_BALANCER_HOSTNAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Check the output for a successful connection:
NoteThe
client_address
is the internal IP address of the load balancer not your egress IP. You can verify that you have configured the client address correctly by connecting with your service limited to.spec.loadBalancerSourceRanges
.Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Exit the pod by running the following command:
exit
$ exit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.6.4. Optional: Testing blocked egress Link kopierenLink in die Zwischenablage kopiert!
Optional: Test that the traffic is successfully blocked when the egress rules do not apply by running the following command:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Send a request to the load balancer by running the following command:
curl -s http://$LOAD_BALANCER_HOSTNAME
$ curl -s http://$LOAD_BALANCER_HOSTNAME
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - If the command is unsuccessful, egress is successfully blocked.
Exit the pod by running the following command:
exit
$ exit
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
12.7. Cleaning up your cluster Link kopierenLink in die Zwischenablage kopiert!
Clean up your cluster by running the following commands:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Clean up the assigned node labels by running the following command:
WarningIf you rely on node labels for your machine pool, this command replaces those labels. Input your desired labels into the
--labels
field to ensure your node labels remain.rosa update machinepool ${ROSA_MACHINE_POOL_NAME} \ --cluster="${ROSA_CLUSTER_NAME}" \ --labels ""
$ rosa update machinepool ${ROSA_MACHINE_POOL_NAME} \ --cluster="${ROSA_CLUSTER_NAME}" \ --labels ""
Copy to Clipboard Copied! Toggle word wrap Toggle overflow