Kubernetes Services and Endpoint

Table of Contents


Introduction to Kubernetes

Kubernetes, also known as "k8s," is an open-source container orchestration platform designed to automate the deployment, scaling, and management of containerized applications across a cluster of nodes¹². It provides a powerful framework for managing workloads, networking, and services within a distributed environment.

Creating Deployments and Services

Creating Deployments

In Kubernetes, a Deployment defines a desired state for a set of Pods. Let's create a Deployment running Nginx:

Apply the Deployment:

Creating Services

Now let's create a ClusterIP Service that points to the Nginx Deployment:

Apply the Service:

Testing ClusterIP Service

  1. Create a busybox pod:

  2. Execute a curl command to check if the ClusterIP service is listening to the Nginx webpage:

  3. Delete the busybox pod:

Creating NodePort Service

Next, let's create a NodePort Service:

Apply the NodePort Service:

Testing NodePort Service

  1. Get the IP address of any node in your cluster:

  2. Use the node's IP address and the specified nodePort (e.g., 30080) to access the Nginx service externally:

Comparing Endpoint IPs with Pods

  • Endpoints represent the IP addresses of one or more Pods dynamically assigned to a Service.

  1. First, let's assume we have two Pods associated with our Nginx Deployment. We'll use the following Pod names:

    • nginx-pod-1

    • nginx-pod-2

  2. Now, let's retrieve the IP addresses of these Pods using the kubectl get pods -o wide command:

    In this example:

    • nginx-pod-1 has an IP address of 10.244.1.10.

    • nginx-pod-2 has an IP address of 10.244.2.20.

  3. Let's get more information about the nginx-service using kubectl describe:

This command will provide detailed information about the service, including its IP address, ports, and associated endpoints.

  1. Next, let's check the Endpoints associated with our nginx-service using the kubectl get endpoints nginx-service command:

    Here, the nginx-service has endpoints corresponding to both Pods:

    • 10.244.1.10:80 (associated with nginx-pod-1)

    • 10.244.2.20:80 (associated with nginx-pod-2)

  2. Finally, we can compare the IP addresses from the Endpoints with the Pod IPs to verify that they match.

Remember that these IP addresses are internal to the cluster and are used for communication between services and Pods. The Service abstraction ensures seamless connectivity without exposing individual Pod IPs externally.

References

Last updated