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?

  • How to properly start nginx in Docker
  • Is there Jenkins or other open-source CI for a distributed system?
  • Docker External File Access Not in /Users/ on OSX
  • bin mounted to alpine container fails to run with /gogs not found
  • Why change NGINX file locations?
  • Difference between nodejs v0.12 and v5.x distributions
  • Docker container - how to configure so it gets a viable IP address when running in vagrant?
  • Docker fixed date
  • docker-compose service and the network
  • (mac) dockers , how to connect to a redis server in the hosting machine from a containter
  • Docker container on another IP and not reachable
  • marathon + mesos + networking + docker-compose
  • 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.