I have create a pod with the below yaml definition.
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: m
I will try to answer your query here.
Also, I am able to access the page using curl on the random port (31316 in this case) and not port 80.
-- Because, kubernetes exposed the port 31316 on the host (maps to the service) and hence it can be accessed on host:31316.
-- Service port is visible only within the kubernetes cluster. You can exec into a pod container and do a curl on servicename:service port instead of the NodePort.
Note the terms - container port:
the port container listens on. Service port:
the port where kubernetes service is exposed on cluster internal ip and mapped to the container port. Nodeport:
the port exposed on the host and mapped to kubernetes service.