Kubernetes- Differences between Ingress and NodePort

Nidhi Ashtikar
3 min readAug 4, 2024

--

Ingress and NodePort are both ways to expose services running in Kubernetes, but they serve different purposes and have distinct characteristics.

Ingress:

  • Definition: A Kubernetes resource that manages external access to services within a cluster, typically HTTP and HTTPS traffic.
  • Purpose: Provides a way to route external requests to services based on URL paths, hostnames, or other criteria.

Configuration:

  • Requires an Ingress Controller to manage and implement the rules.
  • Uses Ingress rules to define how traffic should be routed to different services.

Benefits:

  • Allows for sophisticated routing and load balancing based on URL paths and domains.
  • Supports SSL/TLS termination and host-based routing.
  • Centralized management of access rules and traffic routing.

Example: You can route traffic from http://example.com/api to one service and http://example.com/admin to another service within the same cluster.

NodePort:

  • Definition: A type of Kubernetes Service that exposes a service on a static port on each node in the cluster.
  • Purpose: Provides access to a service from outside the cluster by forwarding traffic from a specific port on the node to the service.

Configuration:

  • Each NodePort service is exposed on a port within a specified range (30000–32767) on all nodes.
  • Clients can access the service by sending requests to any node’s IP address and the assigned NodePort.

Benefits:

  • Simple to configure and useful for exposing services for testing or small-scale access.
  • Directly maps to the service without needing additional components.

Limitations:

  • Less flexible and scalable compared to Ingress.
  • Exposes services on every node, which can lead to security concerns and IP management complexity.
  • Not ideal for complex routing or load balancing scenarios.

Ingress is used for advanced routing of HTTP/HTTPS traffic based on URL paths and hostnames and typically requires an Ingress Controller.

NodePort is a basic service type that exposes a service on a fixed port on each node, making it simpler but less flexible for managing external access.

Ingress

  • Purpose: Ingress is used to manage external access to services within a Kubernetes cluster, typically HTTP and HTTPS traffic.
  • Functionality: It provides a way to define rules for routing traffic to different services based on the URL path or host.
  • Components: Requires an Ingress Controller to implement the rules defined in the Ingress resource.

Advantages:

  • Centralized Management: Allows for centralized management of external access.
  • Advanced Routing: Supports advanced routing features like SSL termination, path-based routing, and virtual hosts.
  • DNS Integration: Can be easily integrated with DNS to provide user-friendly URLs.

Example:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: example-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: example-service
port:
number: 80

NodePort

Purpose: NodePort is a type of Kubernetes service that exposes a service on a static port on each node’s IP address.

  • Functionality: It opens a specific port on all nodes in the cluster and forwards traffic to the service.
  • Components: Does not require an additional controller; it is a built-in feature of Kubernetes services.

Advantages:

  • Simplicity: Simple to set up and use, especially for development and testing.
  • Direct Access: Provides direct access to services via the node’s IP and the specified port.

Disadvantages:

  • Limited Routing: Lacks advanced routing capabilities.
  • Security: Exposes nodes directly to external traffic, which can be a security concern.

Example:

apiVersion: v1
kind: Service
metadata:
name: example-service
spec:
type: NodePort
selector:
app: example-app
ports:
- port: 80
targetPort: 8080
nodePort: 30007

Key Differences

  • Routing Capabilities: Ingress provides advanced routing capabilities, while NodePort offers basic port-based access.
  • Security: Ingress can provide better security features like SSL termination, whereas NodePort exposes nodes directly.
  • Complexity: Ingress requires an Ingress Controller and more configuration, while NodePort is simpler to set up but less flexible.

If you found this guide helpful then do click on 👏 the button.

Follow for more Learning like this 😊

If there’s a specific topic you’re curious about, feel free to drop a personal note or comment. I’m here to help you explore whatever interests you!

Thanks for spending your valuable time learning to enhance your knowledge!

--

--

Nidhi Ashtikar
Nidhi Ashtikar

Written by Nidhi Ashtikar

Experienced AWS DevOps professional with a passion for writing insightful articles.

No responses yet