Kubernetes NodePort

Kubernetes NodePort

# What is a NodePort?

A NodePort is an open port on every node of your cluster. Kubernetes transparently routes incoming traffic on the NodePort to your service, even if your application is running on a different node.

Every Kubernetes cluster supports NodePort, although if you’re running in a cloud provider such as AKS or EKS, you may have to edit your firewall rules. However, a NodePort is assigned from a pool of cluster-configured NodePort ranges (typically 30000–32767). While this is likely not a problem for most TCP or UDP clients, HTTP or HTTPS traffic ends up being exposed on a non-standard port.

Example:

apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  type: NodePort
  selector:
    app: MyApp
  ports:
      # By default and for convenience, the `targetPort` is set to the same value as the 
`port` field.
    - port: 80
      targetPort: 8080
      # Optional field
      # By default and for convenience, the Kubernetes control plane will allocate a port
 from a range (default: 30000-32767)
      nodePort: 30007

Nodeport.jpg

Hope you have got an idea about Kubernetes Nodeport and why it is needed

Thank you !