I'm working on setting up a testing environment for my application. Without getting into all of the details, one requirement is that I stand up a container that is listening on two TCP ports. It is imperative that the ports be hosted by the same IP address. That is, an nmap of the IP address should reveal both ports.

This is a situation which docker-compose would solve very easily. However, my company's GitLab runners don't support docker-compose and everyone uses Kubernetes (via OpenShift, if it matters). I know that I can create NodePort services for the two ports. However, if I'm understanding Kubernetes networking correctly, there's no guarantee that the two services would be on the same IP address as far as the outside world is concerned.

Is there any way to force Kubernetes to do this?

1 Answer 1


This can be accomplished quite easily by, instead of creating two different services, creating one service with two ports:

    - name: port1
      port: 5000
      targetPort: 5000
    - name: port2
      port: 5001
      targetPort: 5001

There will be only one domain name for the service and hence both ports will be open on the same IP address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.