此内容没有您所选择的语言版本。
Chapter 6. GenericKafkaListener schema reference
Used in: KafkaClusterSpec
Full list of GenericKafkaListener schema properties
Configures listeners to connect to Kafka brokers within and outside OpenShift.
Configure Kafka broker listeners using the listeners property in the Kafka resource. Listeners are defined as an array.
Example Kafka resource showing listener configuration
The name and port must be unique within the Kafka cluster. By specifying a unique name and port for each listener, you can configure multiple listeners. The name can be up to 25 characters long, comprising lower-case letters and numbers.
6.1. Specifying a port number 复制链接链接已复制到粘贴板!
The port number is the port used in the Kafka cluster, which might not be the same port used for access by a client.
-
loadbalancerlisteners use the specified port number, as dointernalandcluster-iplisteners -
ingressandroutelisteners use port 443 for access -
nodeportlisteners use the port number assigned by OpenShift
For client connection, use the address and port for the bootstrap service of the listener. You can retrieve this from the status of the Kafka resource.
Example command to retrieve the address and port for client connection
oc get kafka <kafka_cluster_name> -o=jsonpath='{.status.listeners[?(@.name=="<listener_name>")].bootstrapServers}{"\n"}'
oc get kafka <kafka_cluster_name> -o=jsonpath='{.status.listeners[?(@.name=="<listener_name>")].bootstrapServers}{"\n"}'
When configuring listeners for client access to brokers, you can use port 9092 or higher (9093, 9094, and so on), but with a few exceptions. The listeners cannot be configured to use the ports reserved for interbroker communication (9090 and 9091), Prometheus metrics (9404), and JMX (Java Management Extensions) monitoring (9999).
6.2. Specifying listener types 复制链接链接已复制到粘贴板!
Set the type to internal for internal listeners. For external listeners, choose from route, loadbalancer, nodeport, or ingress. You can also configure a cluster-ip listener, which is an internal type used for building custom access mechanisms.
- internal
You can configure internal listeners with or without encryption using the
tlsproperty.Example
internallistener configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow - route
Configures an external listener to expose Kafka using OpenShift
Routesand the HAProxy router.A dedicated
Routeis created for every Kafka broker pod. An additionalRouteis created to serve as a Kafka bootstrap address. Kafka clients can use theseRoutesto connect to Kafka on port 443. The client connects on port 443, the default router port, but traffic is then routed to the port you configure, which is9094in this example.Example
routelistener configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow - ingress
Configures an external listener to expose Kafka using Kubernetes
Ingressand the Ingress NGINX Controller for Kubernetes.A dedicated
Ingressresource is created for every Kafka broker pod. An additionalIngressresource is created to serve as a Kafka bootstrap address. Kafka clients can use theseIngressresources to connect to Kafka on port 443. The client connects on port 443, the default controller port, but traffic is then routed to the port you configure, which is9095in the following example.You must specify the hostname used by the bootstrap service using
GenericKafkaListenerConfigurationBootstrapproperty. And you must also specify the hostnames used by the per-broker services usingGenericKafkaListenerConfigurationBrokerorhostTemplateproperties. With thehostTemplateproperty, you don’t need to specify the configuration for every broker.Example
ingresslistener configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteExternal listeners using
Ingressare currently only tested with the Ingress NGINX Controller for Kubernetes.- loadbalancer
Configures an external listener to expose Kafka using a
LoadbalancertypeService.A new loadbalancer service is created for every Kafka broker pod. An additional loadbalancer is created to serve as a Kafka bootstrap address. Loadbalancers listen to the specified port number, which is port
9094in the following example.You can use the
loadBalancerSourceRangesproperty to configure source ranges to restrict access to the specified IP addresses.Example
loadbalancerlistener configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow - nodeport
Configures an external listener to expose Kafka using a
NodePorttypeService.Kafka clients connect directly to the nodes of OpenShift. An additional
NodePorttype of service is created to serve as a Kafka bootstrap address.When configuring the advertised addresses for the Kafka broker pods, Streams for Apache Kafka uses the address of the node on which the given pod is running.
You can use
preferredNodePortAddressTypeproperty to configure the first address type checked as the node address.Example
nodeportlistener configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow NoteTLS hostname verification is not currently supported when exposing Kafka clusters using node ports.
- cluster-ip
Configures an internal listener to expose Kafka using a per-broker
ClusterIPtypeService.The listener does not use a headless service and its DNS names to route traffic to Kafka brokers. You can use this type of listener to expose a Kafka cluster when using the headless service is unsuitable. You might use it with a custom access mechanism, such as one that uses a specific Ingress controller or the OpenShift Gateway API.
A new
ClusterIPservice is created for each Kafka broker pod. The service is assigned aClusterIPaddress to serve as a Kafka bootstrap address with a per-broker port number. For example, you can configure the listener to expose a Kafka cluster over an Nginx Ingress Controller with TCP port configuration.Example
cluster-iplistener configurationCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Use networkPolicyPeers to configure network policies that restrict access to a listener at the network level. The following example shows a networkPolicyPeers configuration for a plain and a tls listener.
In the following example:
-
Only application pods matching the labels
app: kafka-sasl-consumerandapp: kafka-sasl-producercan connect to theplainlistener. The application pods must be running in the same namespace as the Kafka broker. -
Only application pods running in namespaces matching the labels
project: myprojectandproject: myproject2can connect to thetlslistener.
The syntax of the networkPolicyPeers property is the same as the from property in NetworkPolicy resources.
Example network policy configuration
6.4. GenericKafkaListener schema properties 复制链接链接已复制到粘贴板!
| Property | Property type | Description |
|---|---|---|
| name | string | Name of the listener. The name will be used to identify the listener and the related OpenShift objects. The name has to be unique within given a Kafka cluster. The name can consist of lowercase characters and numbers and be up to 11 characters long. |
| port | integer | Port number used by the listener inside Kafka. The port number has to be unique within a given Kafka cluster. Allowed port numbers are 9092 and higher with the exception of ports 9404 and 9999, which are already used for Prometheus and JMX. Depending on the listener type, the port number might not be the same as the port number that connects Kafka clients. |
| type | string (one of [ingress, internal, route, loadbalancer, cluster-ip, nodeport]) | Type of the listener. The supported types are as follows:
|
| tls | boolean |
Enables TLS encryption on the listener. This is a required property. For |
| authentication |
| Authentication configuration for this listener. |
| configuration | Additional listener configuration. | |
| networkPolicyPeers | NetworkPolicyPeer array | List of peers which should be able to connect to this listener. Peers in this list are combined using a logical OR operation. If this field is empty or missing, all connections will be allowed for this listener. If this field is present and contains at least one item, the listener only allows the traffic which matches at least one item in this list. |