Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing two ports in Google Container Engine

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?

like image 398
cute_marmalade Avatar asked Dec 28 '15 22:12

cute_marmalade


People also ask

How do you expose a container port in Kubernetes?

From the Service type drop-down list, select Node port. Click Expose. When your Service is ready, the Service details page opens, and you can see details about your Service. Under Ports, make a note of the Node Port that Kubernetes assigned to your Service.

Can two containers use the same port in a pod?

I understand that containers within a Pod are actually under the same network namespace, which enables accessing another container in the Pod with localhost or 127.0. 0.1 . It means containers can't use the same port.

Can a pod contains multiple containers?

At the same time, a Pod can contain more than one container, usually because these containers are relatively tightly coupled.


2 Answers

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
like image 170
caesarxuchao Avatar answered Oct 14 '22 14:10

caesarxuchao


Pointed out in another answer using kubernetes allows targeting, but also multiple ports:

kubectl expose deployment example --type=LoadBalancer --port 8080,8081 --target-port 80
like image 42
NotJohn Avatar answered Oct 14 '22 13:10

NotJohn