Kubernetes - NodePort Service

Last Updated : 15 Oct, 2026

NodePort is a Kubernetes Service type that exposes applications outside the cluster through a port on each Node.

  • External Access allows traffic from outside the cluster to reach the application.
  • NodePort exposes the Service on a port available on the cluster Nodes.
  • Application Access forwards incoming traffic to the Pods running the application.
  • Node IP users can access the application using the Node's IP address and NodePort.

Working

NodePort service will exposes the pods of node to the another and also it will expose the pods to the outside of the cluster from where the users can aceses from the internet by using the IP address of node and port.

Following is the sample YAML file for NodePort Service.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  type: NodePort
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  • API Version defines The Service uses v1 as its API version.
  • Kind tells The resource type is Service.
  • Port Defines the port on which the Service exposes the application.
  • TargetPort Defines the port on which the Pod listens for incoming traffic.
  • Port is the Service port, while targetPort is the Pod's application port.

Steps To Use

Step 1: Create an NGINX Deployment

Create a file named deployment.yaml:

yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          ports:
            - containerPort: 80
Screenshot-2026-10-15-155448

Apply the configuration:

kubectl apply -f deployment.yaml

Step 2: Create a NodePort Service

Create the service.yaml configuration:

yaml
apiVersion: v1
kind: Service
metadata:
  name: nginx-nodeport
spec:
  type: NodePort
  selector:
    app: nginx
  ports:
    - port: 80
      targetPort: 80
      nodePort: 30080
Screenshot-2026-10-15-155702

Apply the configuration:

kubectl apply -f service.yaml

Step 3: Verify the Service

kubectl get svc nginx-nodeport
Screenshot-2026-10-15-160716

Step 4: Access the NGINX webpage

If Kubernetes is running on an EC2 instance, find its public IP:

http://YOUR_EC2_PUBLIC_IP:30080
Screenshot-2026-10-15-144713

NodePort Vs ClusterIP

FeatureNodePortClusterIPLoadBalancer
PurposeExposes applications outside the clusterProvides internal access within the clusterExposes applications externally through a cloud load balancer
AccessibilityInternal + ExternalInternal onlyExternal
Traffic SourceExternal users and cluster servicesCluster services onlyExternal users
PortUses a static port on each NodeUses an internal ClusterIPUses an external load balancer IP
Use CaseWeb applications and testingDatabases, APIs, and internal servicesProduction applications requiring external access
External AccessNode IP + NodePortNot directly accessible from outsideLoad balancer IP/DNS
Typical EnvironmentDevelopment, testing, small deploymentsInternal communicationProduction environments
Comment