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?

  • External endpoint of Kubernetes dashboard
  • Facing ISsue while pulling images in Docker
  • Why removing docker containers and images does not free up storage space on Windows? How to fix it?
  • Point different domains to different Docker containers on a single EC2 instance?
  • Setting up redis with docker
  • How to achieve build isolation and caching simultaneously?
  • Installing cron via apt-get fails in a docker ubuntu:12.04 container from permissions problems
  • Building draw.io WAR
  • How to check that the docker container is restarted and accessible?
  • Compass provision failing with Docker compose up
  • Vagrant - Docker provider vs. docker provisioner
  • How to copy file from host to container using Dockerfile
  • 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.