sandeep P
sandeep P

Reputation: 77

Is there a way to map container port to a specific host port using Kubernetes?

In docker we can use -p flag to map container port to whatever port required. But in kubernetes if we use use NodePort then we will get ports of host which range start from 30000. So is there a way to map to a specific port?

Upvotes: 0

Views: 2020

Answers (1)

Burak Serdar
Burak Serdar

Reputation: 51682

You can use the nodePort field in the service definition to specify the port for the nodeport:

https://kubernetes.io/docs/concepts/services-networking/service/#nodeport

However, a nodePort will allocate that port on all nodes in the cluster.

You can also specify a hostPort in the pod container spec itself, though it is not recommended:

ports:
        - name: http
          containerPort: 80
          hostPort: 80 

Upvotes: 3

Related Questions