Exposing two ports in Google Container Engine

cute_marmalade picture cute_marmalade · Dec 28, 2015 · Viewed 32.5k times · Source

Is it possible to create a Pod in the Google Container Engine where two ports are exposed: port 8080 is listening for incoming content and port 80 distributes this content to clients?

The following command to create a Pod is given as example by Google:

kubectl run hello-node --image=gcr.io/${PROJECT_ID}/hello-node --port=8080

I can't seem to define a listening port, and when adding a second "--port=" switch only one port is exposed. Is there a way to expose a second port or am I limited to one port per container?

Answer

caesarxuchao picture caesarxuchao · Dec 29, 2015

No, you cannot specify multiple ports in kubectl run. But you can use kubectl create to create a replication controller, and specify multiple ports for the container.

https://github.com/kubernetes/examples/blob/master/cassandra/cassandra-statefulset.yaml has an example:

          ports:
        - containerPort: 7000
          name: intra-node
        - containerPort: 7001
          name: tls-intra-node
        - containerPort: 7199
          name: jmx
        - containerPort: 9042
          name: cql