Service targetPort is a selector for the endpoints/endpointslices controller to create the endpoints based on that container port name. It is not meant to be used in the Service implementation. The relation is ServicePort.Name - EndpointPort.Name, however, ServicePort.Name is only required for multiple ports and it may be empty. If the endpoint matches the service and there is no name, that means that is a single port service and there is only one endpoint.
Fixed upstream by https://github.com/ovn-org/ovn-kubernetes/pull/2187
Verified on 4.8.0-0.nightly-2021-05-12-072240 Tested various combinations of Multiport svc with named targetPorts and unnamed ports. Tested with targetPort.name != endpoint.Port.name apiVersion: v1 kind: List items: - apiVersion: v1 kind: ReplicationController metadata: labels: name: test-rc name: test-rc spec: replicas: 10 template: metadata: labels: name: test-pods spec: containers: - image: quay.io/openshifttest/nginx-alpine@sha256:5d3f3372288b8a93fc9fc7747925df2328c24db41e4b4226126c3af293c5ad88 name: test-pod imagePullPolicy: IfNotPresent resources: limits: memory: 340Mi ports: - containerPort: 8080 name: webcache - containerPort: 8443 name: pcsync-https - apiVersion: v1 kind: Service metadata: labels: name: test-service name: test-service spec: ports: - name: http port: 27017 protocol: TCP targetPort: webcache - name: https port: 27018 protocol: TCP targetPort: pcsync-https selector: name: test-pods emtpy svc.Port.name with targetPort.name. apiVersion: v1 kind: List items: - apiVersion: v1 kind: ReplicationController metadata: labels: name: test-rc name: test-rc spec: replicas: 10 template: metadata: labels: name: test-pods spec: containers: - image: quay.io/openshifttest/nginx-alpine@sha256:5d3f3372288b8a93fc9fc7747925df2328c24db41e4b4226126c3af293c5ad88 name: test-pod imagePullPolicy: IfNotPresent resources: limits: memory: 340Mi ports: - containerPort: 8080 name: webcache - containerPort: 8443 name: pcsync-https - apiVersion: v1 kind: Service metadata: labels: name: test-service name: test-service spec: ports: - port: 27017 protocol: TCP targetPort: webcache selector: name: test-pods
Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (Moderate: OpenShift Container Platform 4.8.2 bug fix and security update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHSA-2021:2438