此内容没有您所选择的语言版本。

Chapter 8. Using a firewall


Firewalls are not required in MicroShift, but using a firewall can prevent undesired access to the MicroShift API.

8.1. About network traffic through the firewall

Firewalld is a networking service that runs in the background and responds to connection requests, creating a dynamic customizable host-based firewall. If you are using Red Hat Enterprise Linux for Edge (RHEL for Edge) with MicroShift, firewalld should be installed and you only need to configure it.

Details are provided in procedures that follow. Overall, you must explicitly allow the following OVN-Kubernetes traffic when the firewalld service is running.

CNI pod to CNI pod
CNI pod to Host-Network pod Host-Network pod to Host-Network pod
CNI pod
The Kubernetes pod that uses the CNI network
Host-Network pod
The Kubernetes pod that uses host network You can configure the firewalld service by using the following procedures. In most cases, firewalld is part of RHEL for Edge installations. If you do not have firewalld, you can install it with the simple procedure in this section.
Important

MicroShift pods must have access to the internal CoreDNS component and API servers.

8.2. Installing the firewalld service

To install and enable firewalld on your RHEL for Edge host when the package is missing, you can use dnf to install the package and systemctl to enable and start the service. Optionally check for the package with rpm -q firewalld before you install.

Procedure

  1. Optional: Check for firewalld on your system by running the following command:

    $ rpm -q firewalld
  2. If the firewalld service is not installed, run the following command:

    $ sudo dnf install -y firewalld
  3. To start the firewall, run the following command:

    $ sudo systemctl enable firewalld --now

8.3. Required firewall settings

An IP address range for the node network must be enabled during firewall configuration. You can use the default values or customize the IP address range. If you choose to customize the node network IP address range from the default 10.42.0.0/16 setting, you must also use the same custom range in the firewall configuration.

Expand
Table 8.1. Firewall IP address settings
IP RangeFirewall rule requiredDescription

10.42.0.0/16

No

Host network pod access to other pods

169.254.169.1

Yes

Host network pod access to Red Hat build of MicroShift API server

8.3.1. Example commands

The following are examples of commands for settings that are mandatory for firewall configuration:

  • Configure host network pod access to other pods:

    $ sudo firewall-cmd --permanent --zone=trusted --add-source=10.42.0.0/16
  • Configure host network pod access to services backed by Host endpoints, such as the Red Hat build of MicroShift API:

    $ sudo firewall-cmd --permanent --zone=trusted --add-source=169.254.169.1

8.4. Using optional port settings

To allow external access to services and APIs in MicroShift, you can add custom ports to your firewall configuration. Use the listed ports and protocols as a guide for HTTP, HTTPS, NodePort, mDNS, and API access.

For a complete list of ports and protocols, see "Optional ports".

The following examples show commands to open firewall access for services running on MicroShift.

Procedure

  • To add customized ports to your firewall configuration, use the following command syntax:

    $ sudo firewall-cmd --permanent --zone=public --add-port=<port number>/<port protocol>

    For example, to configure a port for the MicroShift API server, enter the following command:

    $ sudo firewall-cmd --permanent --zone=public --add-port=6443/tcp

    To close unnecessary ports in your MicroShift instance, follow the procedure in "Closing unused or unnecessary ports to enhance network security".

8.4.1. Optional ports

The following table lists the optional ports that are available for use with the MicroShift firewall service.

Expand
Table 8.2. Optional ports
Port(s)Protocol(s)Description

80

TCP

HTTP port used to serve applications through the OpenShift Container Platform router.

443

TCP

HTTPS port used to serve applications through the OpenShift Container Platform router.

5353

UDP

mDNS service to respond for OpenShift Container Platform route mDNS hosts.

30000-32767

TCP

Port range reserved for NodePort services; can be used to expose applications on the LAN.

30000-32767

UDP

Port range reserved for NodePort services; can be used to expose applications on the LAN.

6443

TCP

HTTPS API port for the Red Hat build of MicroShift API.

8.5. Adding services to open ports

To open default ports for predefined services through firewalld on your MicroShift instance, you can use the firewall-cmd command. Add each service with the --add-service option.

Procedure

  1. Optional: You can view all predefined services in firewalld by running the following command

    $ sudo firewall-cmd --get-services
  2. To open a service that you want on a default port, run the following example command:

    $ sudo firewall-cmd --add-service=mdns

8.6. Allowing network traffic through the firewall

You can allow network traffic through the firewall by configuring the IP address range and inserting the DNS server to allow internal traffic from pods through the network gateway.

Procedure

  1. Use one of the following commands to set the IP address range:

    1. Configure the IP address range with default values by running the following command:

      $ sudo firewall-offline-cmd --permanent --zone=trusted --add-source=10.42.0.0/16
    2. Configure the IP address range with custom values by running the following command:

      $ sudo firewall-offline-cmd --permanent --zone=trusted --add-source=<custom IP range>
  2. To allow internal traffic from pods through the network gateway, run the following command:

    $ sudo firewall-offline-cmd --permanent --zone=trusted --add-source=169.254.169.1
  3. If you are using a load balancer, allow the IPv6 traffic through the firewall by running the following command:

    $ sudo firewall-cmd --permanent --zone=trusted --add-source=fd01::/48

8.7. Applying firewall settings

To apply firewall settings after you have finished configuring network access through the firewall, you can reload the firewall service.

Procedure

  • Restart the firewall and apply the settings by running the following command:

    $ sudo firewall-cmd --reload

8.8. Verifying firewall settings

After you have restarted the firewall, you can verify your settings by listing them with the firewall-cmd command.

Procedure

  • To verify rules added in the default public zone, such as ports-related rules, run the following command:

    $ sudo firewall-cmd --list-all
  • To verify rules added in the trusted zone, such as IP-range related rules, run the following command:

    $ sudo firewall-cmd --zone=trusted --list-all

8.9. Overview of firewall ports when a service is exposed

Firewalld is often active when you run services on MicroShift. This can disrupt certain services on MicroShift because traffic to the ports might be blocked by the firewall. You must ensure that the necessary firewall ports are open if you want certain services to be accessible from outside the host.

There are several options for opening your ports:

  • Services of the NodePort and LoadBalancer type are automatically available with OVN-Kubernetes.

    In these cases, OVN-Kubernetes adds iptables rules so the traffic to the node IP address is delivered to the relevant ports. This is done using the PREROUTING rule chain and is then forwarded to the OVN-K to bypass the firewalld rules for local host ports and services. Iptables and firewalld are backed by nftables in Red Hat Enterprise Linux (RHEL) 9. The nftables rules, which the iptables generates, always have priority over the rules that the firewalld generates.

  • Pods with the HostPort parameter settings are automatically available. This also includes the router-default pod, which uses ports 80 and 443.

    For HostPort pods, the CRI-O config sets up iptables DNAT (Destination Network Address Translation) to the pod’s IP address and port.

These methods function for clients whether they are on the same host or on a remote host. The iptables rules, which are added by OVN-Kubernetes and CRI-O, attach to the PREROUTING and OUTPUT chains. The local traffic goes through the OUTPUT chain with the interface set to the lo type. The DNAT runs before it hits filler rules in the INPUT chain.

Because the MicroShift API server does not run in CRI-O, it is subject to the firewall configurations. You can open port 6443 in the firewall to access the API server in your MicroShift node.

8.11. Known firewall issue

To avoid traffic failures after a firewalld reload or restart on MicroShift, run firewall commands before you start Red Hat Enterprise Linux (RHEL). If you must run firewall commands later, restart the ovnkube-master pod in openshift-ovn-kubernetes to restore iptable rules that OVN-Kubernetes manages.

The CNI driver in MicroShift makes use of iptable rules for some traffic flows, such as those using the NodePort service. The iptable rules are generated and inserted by the CNI driver, but are deleted when the firewall reloads or restarts. The absence of the iptable rules breaks traffic flows.

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部