1

I have the following scenario -

image

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?

Jonas
  • 1,187
  • 5
  • 19
  • 33
Nazia Jahan Trisha
  • 120
  • 1
  • 1
  • 8
  • 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: https://kubernetes.io/docs/concepts/services-networking/service/#multi-port-services Or use expose `kubectl expose deployment --port=80,60000 --target-port=8080` – PjoterS Apr 21 '20 at 15:57

1 Answers1

3

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:

Example:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: MyApp
  ports:
    - 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
IP:                10.0.74.75
Port:              port-1  80/TCP
TargetPort:        8080/TCP
Endpoints:         10.48.0.13:8080
Port:              port-2  8080/TCP
TargetPort:        8080/TCP
Endpoints:         10.48.0.13:8080
Port:              port-3  6000/TCP
TargetPort:        8080/TCP
Endpoints:         10.48.0.13:8080
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

PjoterS
  • 705
  • 3
  • 11
  • 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. – Nazia Jahan Trisha Apr 22 '20 at 06:47