Repository: strimzi/strimzi-kafka-operator (2025-06-07T11:05:10Z)

Issue:
[Enhancement]: Service definitions use named ports rather than port numbers
### Related problem

Current Kubernetes best practices suggest use of named ports for connecting services to containers rather than port numbers.  Currently the created services use explicit port numbers when connecting to the generated containers.

### Suggested solution

Use the assigned port names in the created service definitions.

### Alternatives

It currently works.

### Additional context

from the container:
```yaml
      name: kafka
      ports:
      - containerPort: 9090
        name: tcp-ctrlplane
        protocol: TCP
      - containerPort: 9091
        name: tcp-replication
        protocol: TCP
      - containerPort: 9092
        name: tcp-clients
        protocol: TCP
      - containerPort: 9093
        name: tcp-clientstls
        protocol: TCP
      - containerPort: 9094
        name: tcp-external
        protocol: TCP
      - containerPort: 9404
        name: tcp-prometheus
```

from a service:
```yaml
    ports:
    - name: tcp-ctrlplane
      port: 9090
      protocol: TCP
      targetPort: 9090   ### change this
    - name: tcp-replication
      port: 9091
      protocol: TCP
      targetPort: 9091   ### change this
    - name: tcp-kafkaagent
      port: 8443
      protocol: TCP
      targetPort: 8443   ### change this
    - name: tcp-clients
      port: 9092
      protocol: TCP
      targetPort: 9092   ### change this
    - name: tcp-clientstls
      port: 9093
      protocol: TCP
      targetPort: 9093   ### change this
```


Discussion:
@jcpunk Out of curiosity ... could please share where did you find this recommendation? What is the expected advantage? Thanks
Ideally, this would prevent hard coding port mappings.  In practice the kafka ports are pretty static and well known, but use of names means, if at some point you need to fiddle with the mappings simply altering the pod's listed export port is all that is required.

Essentially, using the numbers means storing the numbers twice and needing to manually be sure they match up.

I'll need to retrace my steps to find where I found this recommendation.  I'd swear it was under https://docs.kubelinter.io/#/generated/checks but I'm not seeing it now...
Interesting. Not sure this really matters that much when you have an operator generate Kubernetes resources. Also, in our case the names are basically meaning less for most people reading it, but so are the port numbers. Thanks for the explanation.

Hopefully, all the various tools out there expect this and are ready to handle it so that there are no ugly surprises if it is done 🤔.
Feature wise, use of port names has been stable for all the versions of kubernetes you support.  portNames were added way back in the past.
Triaged on 29.5.2025: As you mentioned in the example, the names of the ports are also mentioned in the name field of the particular port of the Service. But anyway, we can keep it opened and implement it.
I will try to implement it in the following days
hey, i opened https://github.com/strimzi/strimzi-kafka-operator/pull/11510 to solve this issue.
Thanks in advance! 



Patch:
diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java
index 8b965894d9c..21d2179bdde 100644
--- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java
+++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CruiseControl.java
@@ -303,7 +303,7 @@ public Service generateService() {
                 labels,
                 ownerReference,
                 templateService,
-                List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, "TCP"))
+                List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT_NAME, "TCP"))
         );
     }
 
diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java
index 0ddb0ce3854..4417b51f3ee 100644
--- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java
+++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaBridgeCluster.java
@@ -234,7 +234,7 @@ public Service generateService() {
                 labels,
                 ownerReference,
                 templateService,
-                List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, port, port, "TCP")),
+                List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, port, REST_API_PORT_NAME, "TCP")),
                 labels.strimziSelectorLabels(),
                 ModelUtils.getCustomLabelsOrAnnotations(CO_ENV_VAR_CUSTOM_SERVICE_LABELS),
                 Util.mergeLabelsOrAnnotations(getDiscoveryAnnotation(port), ModelUtils.getCustomLabelsOrAnnotations(CO_ENV_VAR_CUSTOM_SERVICE_ANNOTATIONS))
diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java
index d981a888298..032060453be 100644
--- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java
+++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaCluster.java
@@ -650,10 +650,10 @@ private List<ServicePort> getServicePorts() {
         List<GenericKafkaListener> internalListeners = ListenersUtils.internalListeners(listeners);
 
         List<ServicePort> ports = new ArrayList<>(internalListeners.size() + 1);
-        ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, "TCP"));
+        ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP"));
 
         for (GenericKafkaListener listener : internalListeners) {
-            ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), "TCP"));
+            ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP"));
         }
 
         return ports;
@@ -669,12 +669,12 @@ private List<ServicePort> getHeadlessServicePorts() {
         List<GenericKafkaListener> internalListeners = ListenersUtils.internalListeners(listeners);
 
         List<ServicePort> ports = new ArrayList<>(internalListeners.size() + 3);
-        ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT, "TCP"));
-        ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT, "TCP"));
-        ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT, "TCP"));
+        ports.add(ServiceUtils.createServicePort(CONTROLPLANE_PORT_NAME, CONTROLPLANE_PORT, CONTROLPLANE_PORT_NAME, "TCP"));
+        ports.add(ServiceUtils.createServicePort(REPLICATION_PORT_NAME, REPLICATION_PORT, REPLICATION_PORT_NAME, "TCP"));
+        ports.add(ServiceUtils.createServicePort(KAFKA_AGENT_PORT_NAME, KAFKA_AGENT_PORT, KAFKA_AGENT_PORT_NAME, "TCP"));
 
         for (GenericKafkaListener listener : internalListeners) {
-            ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), listener.getPort(), "TCP"));
+            ports.add(ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener), listener.getPort(), ListenersUtils.backwardsCompatiblePortName(listener), "TCP"));
         }
 
         ports.addAll(jmx.servicePorts());
@@ -747,7 +747,7 @@ public List<Service> generateExternalBootstrapServices() {
             List<ServicePort> ports = Collections.singletonList(
                     ServiceUtils.createServicePort(ListenersUtils.backwardsCompatiblePortName(listener),
                             listener.getPort(),
-                            listener.getPort(),
+                            ListenersUtils.backwardsCompatiblePortName(listener),
                             ListenersUtils.bootstrapNodePort(listener),
                             "TCP")
             );
@@ -838,7 +838,7 @@ public List<Service> generatePerPodServices() {
                                 ServiceUtils.createServicePort(
                                         ListenersUtils.backwardsCompatiblePortName(listener),
                                         listener.getPort(),
-                                        listener.getPort(),
+                                        ListenersUtils.backwardsCompatiblePortName(listener),
                                         ListenersUtils.brokerNodePort(listener, node.nodeId()),
                                         "TCP")
                         );
diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java
index 8b82270f6b2..336cc7482c3 100644
--- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java
+++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/KafkaConnectCluster.java
@@ -342,7 +342,7 @@ public String getServiceName() {
      */
     public Service generateService() {
         List<ServicePort> ports = new ArrayList<>(1);
-        ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, "TCP"));
+        ports.add(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT_NAME, "TCP"));
 
         ports.addAll(jmx.servicePorts());
 
@@ -362,7 +362,7 @@ public Service generateService() {
      * @return The generated Service
      */
     public Service generateHeadlessService() {
-        List<ServicePort> ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT, "TCP"));
+        List<ServicePort> ports = List.of(ServiceUtils.createServicePort(REST_API_PORT_NAME, REST_API_PORT, REST_API_PORT_NAME, "TCP"));
 
         return ServiceUtils.createHeadlessService(
                 componentName,
diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java
index ac2592f2a47..7de967da93b 100644
--- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java
+++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/ServiceUtils.java
@@ -219,13 +219,13 @@ private static List<IpFamily> ipFamilies(InternalServiceTemplate template)  {
      *
      * @param name          Name of the port
      * @param port          The port on the service which can be accessed by clients
-     * @param targetPort    The port on the container / Pod where the connections will be routed
+     * @param targetPortName the name of the target port on the container / Pod where the connections will be routed
      * @param protocol      Protocol used by this port
      *
      * @return  Created port
      */
-    public static ServicePort createServicePort(String name, int port, int targetPort, String protocol)   {
-        return createServicePort(name, port, targetPort, null, protocol);
+    public static ServicePort createServicePort(String name, int port, String targetPortName, String protocol)   {
+        return createServicePort(name, port, targetPortName, null, protocol);
     }
 
     /**
@@ -233,18 +233,18 @@ public static ServicePort createServicePort(String name, int port, int targetPor
      *
      * @param name          Name of the port
      * @param port          The port on the service which can be accessed by clients
-     * @param targetPort    The port on the container / Pod where the connections will be routed
+     * @param targetPortName the name of the target port on the container / Pod where the connections will be routed
      * @param nodePort      The desired node port number
      * @param protocol      Protocol used by this port
      *
      * @return  Created port
      */
-    public static ServicePort createServicePort(String name, int port, int targetPort, Integer nodePort, String protocol)   {
+    public static ServicePort createServicePort(String name, int port, String targetPortName, Integer nodePort, String protocol)   {
         return new ServicePortBuilder()
                 .withName(name)
                 .withProtocol(protocol)
                 .withPort(port)
-                .withNewTargetPort(targetPort)
+                .withNewTargetPort(targetPortName)
                 .withNodePort(nodePort)
                 .build();
     }
diff --git a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java
index 24e77f05e80..cb0e25570a3 100644
--- a/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java
+++ b/cluster-operator/src/main/java/io/strimzi/operator/cluster/model/jmx/JmxModel.java
@@ -115,7 +115,7 @@ public String secretName()   {
      */
     public List<ServicePort> servicePorts()    {
         if (isEnabled)  {
-            return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT, "TCP"));
+            return List.of(ServiceUtils.createServicePort(JMX_PORT_NAME, JMX_PORT, JMX_PORT_NAME, "TCP"));
         } else {
             return List.of();
         }


Test patch:
diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java
index 290286a77ab..c280f9f752c 100644
--- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java
+++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/KafkaClusterListenersTest.java
@@ -775,7 +775,7 @@ public void testExternalRoutes() {
         assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA);
@@ -799,7 +799,7 @@ public void testExternalRoutes() {
             assertThat(service.getSpec().getPorts().size(), is(1));
             assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
             assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
             assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
             assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         }
@@ -1006,7 +1006,7 @@ public void testExternalLoadBalancers() {
         assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         assertThat(bootstrapServices.get(0).getSpec().getLoadBalancerIP(), is(nullValue()));
@@ -1035,7 +1035,7 @@ public void testExternalLoadBalancers() {
             assertThat(service.getSpec().getPorts().size(), is(1));
             assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
             assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
             assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
             assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             assertThat(service.getSpec().getLoadBalancerIP(), is(nullValue()));
@@ -1162,14 +1162,14 @@ public void testExternalLoadBalancerAllocateNodePorts() {
         assertThat(externalServices, hasSize(1));
         assertThat(externalServices.get(0).getSpec().getAllocateLoadBalancerNodePorts(), is(false));
         assertThat(externalServices.get(0).getSpec().getPorts(), hasSize(1));
-        assertThat(externalServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(externalServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-lb1"));
 
         List<Service> perPodServices = kc.generatePerPodServices();
         assertThat(perPodServices, hasSize(5));
         for (Service service : perPodServices) {
             assertThat(service.getSpec().getAllocateLoadBalancerNodePorts(), is(false));
             assertThat(service.getSpec().getPorts(), hasSize(1));
-            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-lb1"));
         }
     }
 
@@ -1426,7 +1426,7 @@ public void testExternalNodePorts() {
         assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA);
@@ -1450,7 +1450,7 @@ public void testExternalNodePorts() {
             assertThat(service.getSpec().getPorts().size(), is(1));
             assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
             assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
             assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
             assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         }
@@ -1612,7 +1612,7 @@ public void testExternalNodePortOverrides() {
         assertThat(ext.getSpec().getPorts().size(), is(1));
         assertThat(ext.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
         assertThat(ext.getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(ext.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(ext.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
         assertThat(ext.getSpec().getPorts().get(0).getNodePort(), is(32001));
         assertThat(ext.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
 
@@ -1627,21 +1627,21 @@ public void testExternalNodePortOverrides() {
                 assertThat(service.getSpec().getPorts().size(), is(1));
                 assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
                 assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
                 assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32106));
                 assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             } else if (service.getMetadata().getName().startsWith("foo-mixed-3")) {
                 assertThat(service.getSpec().getPorts().size(), is(1));
                 assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
                 assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
                 assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32103));
                 assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             } else {
                 assertThat(service.getSpec().getPorts().size(), is(1));
                 assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
                 assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
                 assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
                 assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             }
@@ -1744,7 +1744,7 @@ public void testNodePortWithLoadbalancer() {
         assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().size(), is(1));
         assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
         assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
         assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getNodePort(), is(32189));
         assertThat(kc.generateExternalBootstrapServices().get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP"));
 
@@ -1757,21 +1757,21 @@ public void testNodePortWithLoadbalancer() {
                 assertThat(service.getSpec().getPorts().size(), is(1));
                 assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
                 assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
                 assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32006));
                 assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             } else if (service.getMetadata().getName().startsWith("foo-mixed-3")) {
                 assertThat(service.getSpec().getPorts().size(), is(1));
                 assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
                 assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
                 assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(32003));
                 assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             } else {
                 assertThat(service.getSpec().getPorts().size(), is(1));
                 assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
                 assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+                assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
                 assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
                 assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
             }
@@ -1895,7 +1895,7 @@ public void testExternalIngress() {
         assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA);
@@ -1919,7 +1919,7 @@ public void testExternalIngress() {
             assertThat(service.getSpec().getPorts().size(), is(1));
             assertThat(service.getSpec().getPorts().get(0).getName(), is(ListenersUtils.BACKWARDS_COMPATIBLE_EXTERNAL_PORT_NAME));
             assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-external"));
             assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
             assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         }
@@ -2130,7 +2130,7 @@ public void testClusterIP() {
         assertThat(bootstrapServices.get(0).getSpec().getPorts().size(), is(1));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getName(), is("tcp-clusterip"));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getPort(), is(9094));
-        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+        assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-clusterip"));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
         assertThat(bootstrapServices.get(0).getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         TestUtils.checkOwnerReference(bootstrapServices.get(0), KAFKA);
@@ -2167,7 +2167,7 @@ public void testClusterIP() {
             assertThat(service.getSpec().getPorts().size(), is(1));
             assertThat(service.getSpec().getPorts().get(0).getName(), is("tcp-clusterip"));
             assertThat(service.getSpec().getPorts().get(0).getPort(), is(9094));
-            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getIntVal(), is(9094));
+            assertThat(service.getSpec().getPorts().get(0).getTargetPort().getStrVal(), is("tcp-clusterip"));
             assertThat(service.getSpec().getPorts().get(0).getNodePort(), is(nullValue()));
             assertThat(service.getSpec().getPorts().get(0).getProtocol(), is("TCP"));
         }
diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java
index f43cc1d8cd2..924a957a0cb 100644
--- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java
+++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/ServiceUtilsTest.java
@@ -42,7 +42,7 @@ public class ServiceUtilsTest {
             .withStrimziComponentType("my-component-type")
             .withAdditionalLabels(Map.of("label-1", "value-1", "label-2", "value-2"));
     private static final String PORT_NAME = "my-port";
-    private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, "HTTP");
+    private static final ServicePort PORT = ServiceUtils.createServicePort(PORT_NAME, 1234, PORT_NAME, "HTTP");
     private static final InternalServiceTemplate TEMPLATE = new InternalServiceTemplateBuilder()
             .withNewMetadata()
                 .withLabels(Map.of("label-3", "value-3", "label-4", "value-4"))
@@ -53,23 +53,23 @@ public class ServiceUtilsTest {
             .build();
 
     @ParallelTest
-    public void testCreateServicePort() {
-        ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, "HTTP");
+    public void testCreateServicePortName() {
+        ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, PORT_NAME, "HTTP");
 
         assertThat(port.getName(), is(PORT_NAME));
         assertThat(port.getPort(), is(1234));
-        assertThat(port.getTargetPort().getIntVal(), is(5678));
+        assertThat(port.getTargetPort().getStrVal(), is(PORT_NAME));
         assertThat(port.getNodePort(), is(nullValue()));
         assertThat(port.getProtocol(), is("HTTP"));
     }
 
     @ParallelTest
     public void testCreateServiceWithNodePort() {
-        ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, 5678, 30000, "HTTP");
+        ServicePort port = ServiceUtils.createServicePort(PORT_NAME, 1234, PORT_NAME, 30000, "HTTP");
 
         assertThat(port.getName(), is(PORT_NAME));
         assertThat(port.getPort(), is(1234));
-        assertThat(port.getTargetPort().getIntVal(), is(5678));
+        assertThat(port.getTargetPort().getStrVal(), is(PORT_NAME));
         assertThat(port.getNodePort(), is(30000));
         assertThat(port.getProtocol(), is("HTTP"));
     }
diff --git a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java
index 95463afaff2..dc4843304d7 100644
--- a/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java
+++ b/cluster-operator/src/test/java/io/strimzi/operator/cluster/model/jmx/JmxModelTest.java
@@ -73,7 +73,7 @@ public void testEnabledJmx() {
         assertThat(jmx.servicePorts().size(), is(1));
         assertThat(jmx.servicePorts().get(0).getName(), is("jmx"));
         assertThat(jmx.servicePorts().get(0).getPort(), is(9999));
-        assertThat(jmx.servicePorts().get(0).getTargetPort().getIntVal(), is(9999));
+        assertThat(jmx.servicePorts().get(0).getTargetPort().getStrVal(), is("jmx"));
         assertThat(jmx.servicePorts().get(0).getProtocol(), is("TCP"));
 
         assertThat(jmx.containerPorts().size(), is(1));
@@ -108,7 +108,7 @@ public void testEnabledJmxWithAuthentication() {
         assertThat(jmx.servicePorts().size(), is(1));
         assertThat(jmx.servicePorts().get(0).getName(), is("jmx"));
         assertThat(jmx.servicePorts().get(0).getPort(), is(9999));
-        assertThat(jmx.servicePorts().get(0).getTargetPort().getIntVal(), is(9999));
+        assertThat(jmx.servicePorts().get(0).getTargetPort().getStrVal(), is("jmx"));
         assertThat(jmx.servicePorts().get(0).getProtocol(), is("TCP"));
 
         assertThat(jmx.containerPorts().size(), is(1));