Sobes.tech
Junior — Middle

What is the difference between NodePort and ClusterIP configurations in Kubernetes?

sobes.tech AI

Answer from AI

In Kubernetes, a Service with the ClusterIP type creates a virtual IP address accessible only within the cluster. This means the service is only available from inside the cluster, for example, for communication between pods.

NodePort is an extension of ClusterIP that additionally opens a fixed port on each node of the cluster. Through this port, the service becomes accessible from outside the cluster via the IP address of any node and the specified port.

In summary:

  • ClusterIP — internal access within the cluster.
  • NodePort — internal access + external access through a port on each node.

Example of a Service with NodePort:

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