Skip to main content

Command Palette

Search for a command to run...

what is service in Kubernetes?

Published
2 min read
what is service in Kubernetes?
D

Passionate about technology and its endless possibilities, I am a BCA graduate who embarked on a journey to explore the world of IT. With a strong foundation in Linux and a keen interest in cloud computing, I delved into the realms of Docker, Podman, and AWS, honing my skills along the way.

As a constant learner, I am currently immersing myself in the intricacies of Kubernetes, eager to unlock its full potential for scalable and efficient application deployment. My goal is to leverage this powerful container orchestration platform to streamline DevOps processes and drive seamless digital transformations.

With a solid understanding of system administration, containerization, and cloud infrastructure, I am equipped to tackle complex challenges and deliver innovative solutions. I thrive in collaborative environments, leveraging my communication skills to effectively bridge the gap between technical complexities and business objectives.

Driven by curiosity and fueled by a growth mindset, I continuously seek out new technologies and industry trends. I am excited to connect with like-minded professionals, exchange knowledge, and contribute to the ever-evolving tech landscape.

If you're looking for a dedicated and adaptable IT professional who can navigate the dynamic world of containers, cloud, and beyond, let's connect and embark on a transformative journey together.

In Kubernetes, a service is an abstraction that defines a logical set of pods and a policy by which to access them. It provides a stable network endpoint to access the pods, even as they are created, deleted, or scaled. Services enable communication and load balancing between different components or microservices within a Kubernetes cluster. The service groups the pods based on the selectors using labels.

In this example, We will see the two types of service:

  1. ClusterIP.

  2. NodePort.

ClusterIP:

This is the default service type. It exposes the service on an internal IP address, reachable only within the cluster. It allows communication between different services within the cluster.

In this image, the admin is internally using the cluster so he can access the clusterip service. The ClusterIP service type in Kubernetes provides a stable internal IP address to access a set of pods within a cluster.

  1. Internal communication

  2. Load balancing

  3. Service discovery

  4. Internal-only access

let's see how the Cluster IP works:

  • CLI commands to create a deployment and expose the service as ClusterIP.

  • Deployment

      kubectl create deployment mydep1 --image docker.io/httpd --port 80 --replicas 5
    

This will create a deployment and have 5 pods in it

  • Service

      kubectl expose deployment mydep1 --port 18080 --target-port 80
    

    This we maps all the pods of deployment and create static IP for Internal use.

    By default, the service is created as ClusterIP.

To get the svc to use the command "kubectl get svc".

To get the svc information in detail use the command

"kubectl describe svc (svc name)"

IP = static IP for accessing the pods

Endpoints = IPs of the pods that have been labelled as app=mydep1.

NodePort:

This type exposes the service on a static port on each node in the cluster. It creates a cluster-wide open port that routes to the service. It allows external access to the service using the cluster nodes' IP addresses.

The NodePort service type in Kubernetes allows external access to services by opening a static port on each node in the cluster. Here are the key aspects of NodePort:

  1. External access

  2. Port allocation

  3. Node-level load balancing

  4. Internal cluster communication

  5. Firewall considerations

Command to expose service to the external world:

kubectl expose deployment mydep1 --port 28080 --target-port 80 --type NodePort

Described the service:

There is NodePort opened for the external world

NodePort= 31521, We can use the nodeip:Nodeport to excess it in the outer world.