kubernetes loadbalancer with multiple backend ports

I have an application with three different backend types. Each of them is listening on different ports (eg 8080, 8180, 8280).
Now I would like to access them by using http://example.com:{8080,8180,8280}. To be safe there should be running two pods of each service.

  1. How should the yaml file look like with multiple backends, each of them having a different port?
  2. Can I include the definition for replicas in the same file? Or is there some kind of main file in kubernetes where I can include other files?

  • RabbitMQ on Docker: Permission denied when chown-ing erlang cookie
  • Why Docker build do not have -f parameter?
  • Is there whoami analog for Docker?
  • Docker exposing ports site can't be reached
  • How to pull layers one by one in Docker?
  • use docker exec in bash script
  • Docker nfs4 mount on Elastic Beanstalk
  • docker build: Returned a non-zero code: 2
  • Docker configuration using the systemd configuration style
  • Docker in Windows Server 2016 is not working
  • Runtime.getRuntime().exec on host from inside a Docker process
  • How about the docker run in virtul machine best practice?
  • One Solution collect form web for “kubernetes loadbalancer with multiple backend ports”

    To do this you would create multiple services, see http://kubernetes.io/docs/user-guide/services/ for details.

    An example could look like (using yaml, you can also use json):

    apiVersion: v1
    kind: Service
    metadata:
      name: yourservice_1
      namespace: default
      labels:
        component: yourcomponent
    spec:
      type: NodePort
      selector:
        component: yourcomponent
      ports:
      - name: http
        port: 8080
        protocol: TCP
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: yourservice_2
      namespace: default
      labels:
        component: yourcomponent
    spec:
      type: NodePort
      selector:
        component: yourcomponent
      ports:
      - name: http
        port: 8081
        protocol: TCP
    ---
    Etc.
    

    And to answer the second part of your question:

    The is to have multiple definitions (can be services, can be any kubernetes yaml), in a single file.

    I however advice a separate file for services since they in general tend to be loaded just once, and a separate file for your pod definitions (since that will change more often).

    One thing to be aware of with the multiple service definition: In (at least Kubernetes 1.3.5/1.3.6, versions which I am using), there is a runaway pod issue in which certain combinations of selectors lead to kubernetes starting just as many pods as it can. To prevent this: Test and experiment. It does work as long as you avoid this condition.

    A single service entry point can be also be used and can be defined as:

    apiVersion: v1
    kind: Service
    metadata:
      name: yourservice_1
      namespace: default
      labels:
        component: yourcomponent
    spec:
      type: NodePort
      selector:
        component: yourcomponent
      ports:
      - name: http
        port: 8080
        protocol: TCP
      - name: http2
        port: 8081
        protocol: TCP
      - name: http2
        port: 8082
        protocol: TCP
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.