is there a way to assign hostports in pod template dynamically

2 views
Skip to first unread message

Sivaram Mothiki

unread,
Mar 6, 2015, 2:21:50 PM3/6/15
to google-c...@googlegroups.com
Hi ,

I didn't find any documentation about assigning dynamic host-ports to the container . Could you let me know if it is possible to assign dynamic host port .
I've tried the below pod json template keeping host port =0 but didn't work.

{
  "id": "hello1.v2-1.web",
  "kind": "Pod",
  "apiVersion": "v1beta1",
  "desiredState": {
    "manifest": {
      "version": "v1beta1",
      "id": "hello",
      "containers": [{
        "name": "hello1",
        "image": "hello",
        "ports": [{
          "containerPort": 80,
          "hostPort": 0
        }]
      }]
    }
  },
  "labels": {
    "name": "hello",
    "environment": "testing"
  }
}

Thanks
smothiki

jay vyas

unread,
Mar 6, 2015, 5:08:43 PM3/6/15
to google-c...@googlegroups.com
This is an interesting question, but ... From what i can tell, this might indicate a flaw in your design.

Other kube experts please correct if im wrong,
but today I (think) I learned something about how kubernetes external exposure is supposed to work - you're not really meant to expose ports directly on pods using containerPort/hostPort at large scale.

Normally, one might do this, for example, because they want "10" servers running, and they only have "8" servers, so there might be some collisions... so the logical choice is to have have server1 bind to 8080, and server2 bind to 8081, in the case that 1 & 2 are running on the *same* minion.

But alas- there is no need for this :)... because the ports are on an internal network, and you can have kubernetes load balance services for you.  So, an alternative way to allow multiple identical services to run on the same host, is to stop host port binding entirely. instead, you can use the kubernetes "service" with a the publicIP:[....] feature, on any minion. 

This will then serve as an HA proxy, i.e., it will route to the service load balancer itself, which will send your requests to one of the 10 running servers, all of which are operating behind the kube network.

Tim Hockin

unread,
Mar 6, 2015, 7:25:19 PM3/6/15
to google-c...@googlegroups.com
Jay has nailed it.

HostPorts are all about sharing an IP space. Kubernetes fundamentally
rejects that model.

Read this and see if it clarifies, I'd love to make sure this doc
explains it well enough.

https://github.com/thockin/kubernetes/blob/docs2/docs/cluster/networking.md
> --
> You received this message because you are subscribed to the Google Groups
> "Containers at Google" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-contain...@googlegroups.com.
> To post to this group, send email to google-c...@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-containers.
> For more options, visit https://groups.google.com/d/optout.

jay vyas

unread,
Mar 9, 2015, 11:19:41 AM3/9/15
to google-c...@googlegroups.com
Also I've updated the docs for guestbook demo app to reflect this.  PS thanks to tim st claire and eric paris for helping me with this last week !


On Friday, March 6, 2015 at 2:21:50 PM UTC-5, Sivaram Mothiki wrote:

jay vyas

unread,
Mar 9, 2015, 11:21:51 AM3/9/15
to google-c...@googlegroups.com
https://github.com/GoogleCloudPlatform/kubernetes/pull/5144 (PR still pending, for now you can see it there)
Reply all
Reply to author
Forward
0 new messages