Fresh Opportunities Brighter Tomorrow!

Kubernetes Explained: Pods, Deployments and Services

If you are learning DevOps, cloud computing or container orchestration, Kubernetes is one of the most important technologies to understand.

Docker makes it possible to package applications into containers, but running a few containers manually is very different from managing hundreds or thousands of them. Kubernetes helps solve that problem by providing a platform for deploying, scaling and managing containerized applications.

Simple definition:
Kubernetes is an open-source container orchestration system that helps automate the deployment, scaling and management of containerized applications.

In this Kubernetes basics guide, we will focus on three fundamental objects: Pods, Deployments and Services.

Kubernetes in Simple Terms

A useful way to understand Kubernetes is to imagine that you have an application running inside containers and Kubernetes is responsible for keeping the application in the desired state.

Kubernetes Application Flow
Application
Container Image
Deployment
Desired Replicas
Pods
Running Workloads
Service
Stable Access

What Is Kubernetes?

Kubernetes is designed to manage containerized workloads across a cluster of machines.

Instead of manually starting containers and checking whether they are still running, you describe what you want Kubernetes to run. Kubernetes controllers then work toward maintaining that desired state.

For example, you might tell Kubernetes that you want three replicas of an application. Kubernetes can then work to maintain three running Pods for that workload.

What Is a Kubernetes Cluster?

A Kubernetes cluster is a collection of machines that work together to run Kubernetes workloads.

At a high level, a Kubernetes environment contains the components responsible for managing the cluster and the machines where workloads run.

Kubernetes Cluster

├── Control Plane
│ ├── API Server
│ ├── Scheduler
│ ├── Controllers
│ └── Cluster State

└── Worker Nodes
├── Pods
├── Containers
└── Supporting Components

The control plane manages the cluster, while worker nodes provide the environment where application workloads run.

What Is a Kubernetes Pod?

A Pod is the smallest deployable unit in Kubernetes.

A Pod can contain one or more containers that are intended to run together. Containers inside the same Pod share certain resources and networking.

In many common applications, a Pod contains a single main application container. However, Kubernetes also supports multi-container Pods when containers need to operate closely together.

Pod Structure
Kubernetes Pod
Application Container
Web Application
Optional Container
Supporting Process

Containers in the same Pod share the Pod's network identity and can communicate with each other through localhost.

Are Pods Permanent?

No. A Pod should generally be treated as a replaceable workload unit.

If a Pod fails, Kubernetes may create another Pod depending on the controller managing it.

This is one reason beginners should avoid thinking of a Pod as a permanent server. Kubernetes is designed around managing desired state rather than manually maintaining individual machines.

What Is a Kubernetes Deployment?

A Deployment manages a set of replicated Pods and provides a declarative way to describe how an application should be deployed.

Instead of manually creating every Pod, you can define the desired number of replicas and the container image to use.

For example, you might want:

Application: web application
Replicas: 3
Image: my-web-app:1.0

Kubernetes can then create and maintain the required Pods.

Deployment and Pods

One Deployment Managing Multiple Pods
Deployment
Pod 1
Pod 2
Pod 3

Example Kubernetes Deployment

Kubernetes resources are commonly described using YAML manifests.

Here is a simplified Deployment example:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: web-app
  template:
    metadata:
      labels:
        app: web-app
    spec:
      containers:
        - name: web-app
          image: nginx:latest
          ports:
            - containerPort: 80

The important part for beginners is the relationship between Deployment → replicas → Pods.

Creating the Deployment

If the YAML file is saved as deployment.yaml, you can apply it with:

kubectl apply -f deployment.yaml

Kubernetes will process the manifest and attempt to create the desired resources.

Check the Deployment

kubectl get deployments

Check the Pods

kubectl get pods

You should see Pods associated with the Deployment.

What Is a Kubernetes Service?

Pods can be created and replaced during the normal operation of a Kubernetes cluster. Their IP addresses can therefore change.

Applications need a stable way to communicate with a group of Pods. This is where a Kubernetes Service is useful.

Simple idea:
A Service provides a stable network endpoint for reaching a set of Pods selected by labels.

How a Service Connects to Pods

Service → Pod Selection
Service
Stable Endpoint
Pod 1
Pod 2
Pod 3

Example Kubernetes Service

A simple Service can select Pods using labels.

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

The selector:

app: web-app

tells the Service which Pods it should target.

Pods vs Deployments vs Services

Object Main Purpose Think of It As
Pod Runs one or more containers Workload unit
Deployment Manages replicated Pods Application manager
Service Provides stable access to Pods Stable network endpoint

Scaling a Kubernetes Application

One of Kubernetes' useful capabilities is the ability to change the number of replicas for a Deployment.

For example:

kubectl scale deployment web-app --replicas=5

Kubernetes will attempt to bring the Deployment to the requested number of replicas.

You can then check the result:

kubectl get pods

What Happens If a Pod Fails?

Kubernetes controllers continuously compare the current state of resources with the desired state.

If a Deployment specifies three replicas and one Pod disappears, Kubernetes can create another Pod so that the desired number of replicas can be restored, assuming the cluster has the resources and conditions required to do so.

Desired state: 3 replicas
Pod 1 ✓
Pod 2 ✗
Pod 3 ✓
Kubernetes works toward:
Pod 1 ✓
Pod 2 → replacement
Pod 3 ✓

Putting Everything Together

The relationship between these three objects is one of the most important concepts for Kubernetes beginners.

Deployment
    │
    ├── Pod
    ├── Pod
    └── Pod

Service
    │
    └── Selects Pods using labels

A Deployment manages the desired number of application Pods, while a Service provides a stable mechanism for reaching the selected Pods.

Useful kubectl Commands

View cluster information

kubectl cluster-info

List Pods

kubectl get pods

List Deployments

kubectl get deployments

List Services

kubectl get services

Get detailed Pod information

kubectl describe pod POD_NAME

View Pod logs

kubectl logs POD_NAME

Basic Kubernetes Troubleshooting

When an application is not working, avoid immediately deleting everything. Start by examining the state of the Kubernetes objects.

  1. Check whether the Pod exists.
  2. Check the Pod status.
  3. Review Pod events.
  4. Check application logs.
  5. Check the Deployment.
  6. Check the Service and its selector.
  7. Check whether the application is listening on the expected port.

Useful commands include:

kubectl get pods
kubectl describe pod POD_NAME
kubectl logs POD_NAME
kubectl get deployment
kubectl get service

Why Kubernetes Is Important for DevOps

Kubernetes is commonly used as part of modern application deployment platforms. It can provide mechanisms for scheduling workloads, maintaining replicas, exposing services and managing application updates.

For someone preparing for a DevOps or cloud engineering career, understanding Pods, Deployments and Services provides an important foundation for more advanced Kubernetes topics.

Once these concepts are clear, you can move on to topics such as Ingress, Gateway API, ConfigMaps, Secrets, persistent storage, probes, resource requests and limits, networking and Kubernetes security.

Kubernetes Interview Questions for Beginners

1. What is Kubernetes?

Kubernetes is an open-source container orchestration system used to automate the deployment, scaling and management of containerized applications.

2. What is a Pod?

A Pod is the smallest deployable unit in Kubernetes and can contain one or more containers.

3. What is a Deployment?

A Deployment provides declarative management of replicated Pods and helps maintain the desired number of application replicas.

4. Why do we need a Service?

A Service provides a stable network endpoint for accessing a selected group of Pods.

5. Can a Pod contain multiple containers?

Yes. A Pod can contain multiple containers when those containers need to operate together and share the Pod's networking and other resources.

6. What happens if a Pod managed by a Deployment disappears?

The Deployment's underlying controllers can work to create a replacement so that the desired replica count is restored.

7. How do you check running Pods?

kubectl get pods

Frequently Asked Questions

Is Kubernetes a virtual machine?

No. Kubernetes is a container orchestration platform. It can run containerized workloads on physical or virtual machines.

Is a Pod the same thing as a container?

No. A Pod is a Kubernetes workload unit that can contain one or more containers.

Can a Service have multiple Pods behind it?

Yes. A Service can select multiple Pods using labels and provide a stable endpoint for accessing them.

Does a Deployment directly provide networking?

A Deployment manages application Pods. A Service is normally used when those Pods need a stable network endpoint.

Practical Kubernetes Exercise

If you have access to a Kubernetes cluster, try this small exercise.

Step 1: Create a Deployment

kubectl create deployment web --image=nginx

Step 2: Check the Deployment

kubectl get deployment

Step 3: Check the Pod

kubectl get pods

Step 4: Scale the Deployment

kubectl scale deployment web --replicas=3

Step 5: Check the Pods again

kubectl get pods

Observe how the Deployment changes the number of Pods to match the requested replica count.

Key Takeaways

  • Kubernetes is a container orchestration platform.
  • A Pod is the smallest deployable unit in Kubernetes.
  • A Pod can contain one or more containers.
  • A Deployment manages replicated application Pods.
  • A Service provides a stable network endpoint for selected Pods.
  • Labels are commonly used to identify which Pods a Service should target.
  • Kubernetes works toward maintaining the desired state defined by its resources.
  • kubectl is the primary command-line tool used to interact with Kubernetes clusters.
  • Pods, Deployments and Services are foundational Kubernetes concepts.

Related Topics

  • Docker Containers Explained
  • Kubernetes Services: ClusterIP, NodePort and LoadBalancer
  • Kubernetes Networking
  • Kubernetes CNI Explained
  • Kubernetes Ingress
  • Kubernetes Storage
  • CI/CD and Kubernetes
  • Linux Commands for Beginners
Freshers Nation Editorial Note: This tutorial is intended as an educational introduction to Kubernetes for students, freshers and IT professionals building DevOps and cloud fundamentals. Examples are simplified for learning purposes and should be adapted appropriately for production environments.

No comments:

Post a Comment

Stay Connected

Get the latest job opportunities and career updates.

👍 Like us on
facebook
Subscribe to Job Updates

Get the latest jobs directly from Freshers Nation.

Subscribe via RSS → No spam. Unsubscribe anytime.