Forum Stats

  • 3,826,078 Users
  • 2,260,593 Discussions
  • 7,896,782 Comments

Discussions

HOW TO: expose multiple nodeports in Kubernetes(OKE) via single public IP adress

User_LEOWY
User_LEOWY Member Posts: 1 Green Ribbon
edited May 5, 2022 11:23AM in Containers and Orchestration

Hello,


Is there any solution, how to expose multiple nodeports inside Kubernetes cluster via single public IP address?


Example:

prometheus nodeport: 30001

elastic nodeport: 30002


And all these nodeports will be handle by single public IP address. Then If I need to configure output for some app that needs to reach elastic I will use IP xxx.xxx.xxx.xxx:30002

Same with output for prometheus. The IP will be same xxx.xxx.xxx.xxx only nodeport will be different.

I know I can create LB for each of these but then I will have different IPs.


Is there any way how to do that?


Many thanks in advance.


Martin

Tagged:

Answers

  • Edwin van Meerendonk
    Edwin van Meerendonk Member Posts: 190 Bronze Badge

    Yes, you can create a service, but you can create it for multiple ports.

    apiVersion: v1
    kind: Service
    metadata:
      name: external-shared-lb
      annotations:
        oci.oraclecloud.com/load-balancer-type: "nlb"
    spec:
      type: LoadBalancer
      ports:
      - name: nodered-anexo-pv1c
        port: 8080
        targetPort: nodered-port
      - name: influxdb1
        port: 8081
        targetPort: influxdb-port
      selector:
        lbtype: external-shared
    

    Here I create a network loadbalancer that will receive a single IP, but it will listen to port 8080 and 8081.

    In you deployment you have to name the target-ports

     spec:
          containers:
          - name: influxdb1
            image: ***
            ports:
            - containerPort: 8086
              name: influxdb-port
    

    So, external traffic on my loadbalancer on 8081 will be directed to the pod(s) on port 8086

  • Edwin van Meerendonk
    Edwin van Meerendonk Member Posts: 190 Bronze Badge

    Sorry, I forgot the lbtype tag in the selector.

    The full deployment example

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: influxdb1
    spec:
      selector:
        matchLabels:
          app: influxdb1app
      replicas: 1
      template:
        metadata:
          labels:
            app: influxdb1app
            lbtype: external-shared
        spec:
          containers:
          - name: influxdb1
            image: ****
            ports:
            - containerPort: 8086
              name: influxdb-port
          imagePullSecrets:
            - name: classified