I have the following scenario -


The position simulator will get its longitude and latitude data based on time from a gps tracker. So this position simulator has a connection to activemq, but to receive the raw data, is it possible to expose another port of this service to receive the live tracking data?

  • Could you specify a bit more? Not sure if I understood good. If you want to expose service in more than 1 port, you can just add it in YAML config like here: kubernetes.io/docs/concepts/services-networking/service/… Or use expose kubectl expose deployment <something> --port=80,60000 --target-port=8080
    – PjoterS
    Apr 21, 2020 at 15:57

1 Answer 1


If you want to expose for example you deployment on two or more ports you can do it at least two ways.

  1. Proper configuration in YAML. This method is well described in Kubernetes documentation.

    For some Services, you need to expose more than one port. Kubernetes lets you configure multiple port definitions on a Service object. When using multiple ports for a Service, you must give all of your ports names so that these are unambiguous. For example:


apiVersion: v1
kind: Service
  name: my-service
    app: MyApp
    - name: http
      protocol: TCP
      port: 80
      targetPort: 9376
    - name: https
      protocol: TCP
      port: 443
      targetPort: 9377
    - name: <another-name>
      protocol: TCP
      port: XXX
      targetPort: XXX
  1. Using kubectl expose.

$ kubectl exposed <resource(deployment/Replicaset/etc)> <deployment-name> --port=XXX,XYZ,ABC --target-port=XXX

$ kubectl expose deployment nginx --port=80,8080,6000 --target-port=8080 service/nginx exposed

$ kubectl describe svc nginx
Name:              nginx
Namespace:         default
Labels:            run=nginx
Annotations:       <none>
Selector:          run=nginx
Type:              ClusterIP
Port:              port-1  80/TCP
TargetPort:        8080/TCP
Port:              port-2  8080/TCP
TargetPort:        8080/TCP
Port:              port-3  6000/TCP
TargetPort:        8080/TCP
Session Affinity:  None
Events:            <none>

As mentioned in Kubernetes docs

targetPort: is the port the container accepts traffic on, port: is the abstracted Service port, which can be any port other pods use to access the Service

  • Thanks a lot. I was thinking that in an isolated pod, which is only exposed to another pod, would not be possible to expose another publicly accessible node. Apr 22, 2020 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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