Welcome to the Linux Foundation Forum!

Doubts reg port while creating pod


In Lab 2.3. Create a Basic Pod

We have created basic pod using:

tkundu@master-node:~/LFD259/SOLUTIONS/s_02$ cat basic.yaml
apiVersion: v1
kind: Pod
name: basicpod
- name: webcont
image: nginx

Now, we tried to add
ports: #<--Add this and following

  • containerPort: 80

But i was able to curl to the pod Ip and get nginx page before and after. So, would like to know the difference.

Even without adding containerPort, i am able to curl:

tkundu@master-node:~/LFD259/SOLUTIONS/s_02$ curl
<!DOCTYPE html>

Welcome to nginx!

body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; }

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.


I am new into kubernetes, would be helpful is someone can explain.


  • FlamentBruno
    FlamentBruno Posts: 9
    edited July 2020

    It's normal, check container spec:


    List of ports to expose from the container. Exposing a port here gives the system additional information about the network connections a container uses, but is primarily informational. Not specifying a port here DOES NOT prevent that port from being exposed. Any port which is listening on the default "" address inside a container will be accessible from the network. Cannot be updated.


  • chrispokorni
    chrispokorni Posts: 2,190

    Hi @tapakund,

    The container running inside the Pod is already listening on the port(s) it was designed to listen for traffic.

    In the case of an nginx webserver, the container is listening on port 80. Therefore, you are able to access the webserver via curl to port 80.
    The containerPort property of the Pod spec is for informational purposes only in the context of the Kubernetes cluster. When exposing an application with Kubernetes, the cluster needs to know where to forward traffic requests, and specifying the containerPort is one method to inform the cluster where to forward such traffic.


  • tapakund
    tapakund Posts: 8

    Thanks @chrispokorni @FlamentBruno. This helps.


Upcoming Training