codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
☸️

Kubernetes

8 / 82 topics
5Using kubectl Command Line Tool6Understanding Pods7Deploying Applications with Deployments8Using Services in Kubernetes
Tutorials/Kubernetes/Using Services in Kubernetes
☸️Kubernetes

Using Services in Kubernetes

Updated 2026-05-15
10 min read

Using Services in Kubernetes

Introduction

In Kubernetes, a Service is an abstraction that defines a logical set of Pods and a policy by which to access them. It enables a loose coupling between dependent Pods, making it easier to manage and scale your applications. This tutorial will explore the different types of services available in Kubernetes and their use cases.

Concept

What is a Service?

A Kubernetes Service provides a stable network endpoint for a set of Pods. Services allow you to expose your application to other components within the cluster or outside of it. They abstract away the underlying IP addresses and port numbers, providing a consistent interface for communication.

Types of Services

Kubernetes supports several types of services:

  1. ClusterIP: Exposes the Service on an internal IP in the cluster that is reachable only from within the cluster.
  2. NodePort: Exposes the Service on each Node's IP at a static port (the NodePort). A ClusterIP Service, to which the NodePort Service routes, is automatically created.
  3. LoadBalancer: Creates an external load balancer in the cloud provider that routes traffic to the Nodes where your Pods are running.
  4. ExternalName: Maps a Service to a DNS name, usually for services hosted outside of the cluster.

Examples

ClusterIP Service

A ClusterIP service is the default type and exposes the service on an internal IP within the Kubernetes cluster.

Example YAML

apiVersion: v1
kind: Service
metadata:
  name: my-clusterip-service
spec:
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

Explanation

  • selector: The service routes traffic to Pods that match the label app: my-app.
  • ports: Defines the port on which the service is exposed and the port on which the Pod listens.

NodePort Service

A NodePort service exposes the service on each node's IP at a static port.

Example YAML

apiVersion: v1
kind: Service
metadata:
  name: my-nodeport-service
spec:
  type: NodePort
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376
      nodePort: 30007

Explanation

  • type: Specifies the service type as NodePort.
  • nodePort: The static port on which the service is exposed on each node.

LoadBalancer Service

A LoadBalancer service creates an external load balancer in the cloud provider.

Example YAML

apiVersion: v1
kind: Service
metadata:
  name: my-loadbalancer-service
spec:
  type: LoadBalancer
  selector:
    app: my-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 9376

Explanation

  • type: Specifies the service type as LoadBalancer.

ExternalName Service

An ExternalName service maps a service to a DNS name.

Example YAML

apiVersion: v1
kind: Service
metadata:
  name: my-externalname-service
spec:
  type: ExternalName
  externalName: foo.bar.example.com

Explanation

  • type: Specifies the service type as ExternalName.
  • externalName: The DNS name to which the service maps.

What's Next?

In this tutorial, we explored different types of services in Kubernetes and their use cases. Understanding these concepts is crucial for managing and scaling your applications effectively within a Kubernetes cluster. In the next section, we will delve into "Managing Configuration with ConfigMaps," where you'll learn how to manage configuration data for your applications.

Info

Remember, Services are essential for exposing your Pods to other components in the cluster or outside of it. Choose the right type of service based on your application's requirements.


PreviousDeploying Applications with DeploymentsNext Managing Configuration with ConfigMaps

Recommended Gear

Deploying Applications with DeploymentsManaging Configuration with ConfigMaps