Kubernetes ContainerDevOps AutomationDevOps GuidesKubernetes Guide

Article & Tutorial

Kubernetes Services Explained: ClusterIP, NodePort, LoadBalancer and DNS

Learn Kubernetes Services with ClusterIP, NodePort, LoadBalancer, selectors, ports, DNS names, service discovery and troubleshooting examples.

Contents

Kubernetes Services Explained

A Kubernetes Service gives stable networking to a group of pods. It solves the problem of changing pod IPs and provides service discovery inside the cluster.

Quick answer

ClusterIP

Internal service inside the cluster.

NodePort

Exposes service on a port on each node.

LoadBalancer

Creates an external load balancer in supported cloud environments.

ClusterIP service example

apiVersion: v1 kind: Service metadata: name: nginx-service spec: type: ClusterIP selector: app: nginx ports: - port: 80 targetPort: 80

NodePort service example

apiVersion: v1 kind: Service metadata: name: nginx-nodeport spec: type: NodePort selector: app: nginx ports: - port: 80 targetPort: 80 nodePort: 30080

Commands

kubectl get svc kubectl describe svc nginx-service kubectl get endpoints nginx-service kubectl port-forward svc/nginx-service 8080:80

Service DNS

Pods can usually access a service by service name inside the same namespace.

curl

Common mistakes

  • Selector labels do not match pod labels.
  • Confusing service port and targetPort.
  • Using NodePort for production without understanding network exposure.
  • Expecting LoadBalancer to work in local clusters without a load balancer implementation.

Best practices

  • Use ClusterIP for internal communication.
  • Use Ingress for HTTP/HTTPS routing when suitable.
  • Use clear labels and selectors.
  • Check endpoints when traffic is not reaching pods.

Related Melochip guides

  • Kubernetes Learning Path
  • Docker Networks Explained

Official references

  • Kubernetes Services documentation

Did this help?

Yes No

Join the discussion

0 Comments

Ask questions, add context, or share what worked.

Sign in to join the discussion

No comments yet. Start the discussion.

More from Melochip Editorial

Related articles

Stay in the loop. Get new Melochip articles

Receive Melochip article updates when new articles are available. Explicit opt-in only.

No pre-checked boxes. Unsubscribe support is part of the subscriber foundation.