How to expose a Kubernetes service on a specific Nodeport?

后端 未结 6 2092
不思量自难忘°
不思量自难忘° 2021-02-07 00:04

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         


        
6条回答
  •  面向向阳花
    2021-02-07 00:25

    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.

提交回复
热议问题