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?
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.
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.
At the same time, a Pod can contain more than one container, usually because these containers are relatively tightly coupled.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With