Kubernetes Object Hierarchy Explained


Here Kubernetes Object Hierarchy Explained

Kubernetes organizes applications into a hierarchy of objects. Understanding this hierarchy is essential for deploying, managing, and troubleshooting applications.


Object Hierarchy

Cluster

├── Namespace
│   │
│   ├── Deployment
│   │   └── ReplicaSet
│   │       └── Pod
│   │           └── Container
│   │
│   ├── StatefulSet
│   │   └── Pod
│   │
│   ├── DaemonSet
│   │   └── Pod
│   │
│   ├── Job
│   │   └── Pod
│   │
│   └── CronJob
│       └── Job
│           └── Pod

└── Node

What is a Cluster?

A Kubernetes Cluster is the highest-level object.

It consists of:

  • Control Plane
  • Worker Nodes
  • Networking
  • Storage

What is a Namespace?

Namespaces logically separate workloads inside a cluster.

Examples:

  • production
  • development
  • staging

What is a Deployment?

Deployments manage stateless applications.

Responsibilities:

  • Rolling Updates
  • Rollbacks
  • Scaling
  • Self-healing

What is a ReplicaSet?

A ReplicaSet ensures the desired number of Pods are always running.

Example:

Desired replicas:

replicas: 3

If one Pod crashes:

3 Pods



1 Dies



ReplicaSet Creates New Pod

What is a Pod?

A Pod is the smallest deployable unit in Kubernetes.

A Pod may contain:

  • One container
  • Multiple tightly coupled containers

Example:

Pod

├── nginx
└── log-agent

What is a Container?

A container is where your application runs.

Examples:

  • nginx
  • Python API
  • Java Application
  • Redis

Request Flow

User



Ingress



Service



Pod



Container

Advantages

  • High availability
  • Automatic recovery
  • Easy scaling
  • Rolling deployments
  • Platform independent

Best Practices

  • Keep Pods small
  • Use Namespaces
  • Use Deployments instead of Pods directly
  • Set Resource Requests and Limits
  • Use Health Probes

Common Interview Questions

Why shouldn’t you create Pods directly?

Because Deployments automatically manage:

  • Scaling
  • Recovery
  • Rollbacks
  • ReplicaSets

Difference between Deployment and StatefulSet?

Deployment:

  • Stateless

StatefulSet:

  • Stateful
  • Stable identities
  • Persistent storage

Summary

Remember this hierarchy:

Cluster

Namespace

Deployment

ReplicaSet

Pod

Container