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?

  • Nancy slow first request of any route (not just first request) on mono
  • How to allow ptrace in docker container
  • curl syntax error: append couchdb document failed with “conflict”?
  • “kubectl exec” results in “error: unable to upgrade connection: Unauthorized”
  • docker exposing multiple ports - not working
  • docker with shared folder d drive
  • How to edit source code of a python project deployed in docker
  • How does docker handle almost equal images?
  • How do you get a file from a windows host to linux docker container?
  • Access to localhost from docker container
  • Docker compose linking to mariaDB
  • How to disable write barrier on docker thinpooldev?
  • 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.