Sunday, June 7, 2026

Kubernetes Objects and Their YAML Structure

Kubernetes resources (objects) are represented by YAML manifests. Each object serves a specific purpose and contains a set of core configuration fields. Understanding these objects is essential because almost every Kubernetes deployment is built using combinations of these resources.

Kubernetes Object (kind) What it Does (Description) Core Elements in YAML File
Pod The smallest deployable unit in Kubernetes. It represents a single running process and contains one or more tightly coupled containers.
  • apiVersion
  • kind
  • metadata
  • spec.containers (image, name, ports, env)
  • spec.volumes
Deployment Manages a replicated pool of stateless Pods. Handles rolling updates, rollbacks, and ensures a desired number of Pods remain available.
  • apiVersion
  • kind
  • metadata
  • spec.replicas
  • spec.selector (matchLabels)
  • spec.template
StatefulSet Similar to a Deployment, but designed for applications requiring stable identities, ordered deployment, and persistent storage such as databases.
  • apiVersion
  • kind
  • metadata
  • spec.serviceName
  • spec.replicas
  • spec.template
  • spec.volumeClaimTemplates
DaemonSet Ensures all (or selected) Nodes run exactly one copy of a Pod. Commonly used for monitoring agents, logging agents, and networking components.
  • apiVersion
  • kind
  • metadata
  • spec.selector
  • spec.template
Job Creates one or more Pods and ensures that a specified number of them successfully complete before terminating.
  • apiVersion
  • kind
  • metadata
  • spec.backoffLimit (retry count)
  • spec.template
CronJob Creates Jobs on a recurring schedule using Linux cron syntax.
  • apiVersion
  • kind
  • metadata
  • spec.schedule (e.g. */5 * * * *)
  • spec.jobTemplate
Service Exposes Pods through a stable network endpoint and provides load balancing across multiple Pod replicas.
  • apiVersion
  • kind
  • metadata
  • spec.type (ClusterIP, NodePort, LoadBalancer)
  • spec.selector
  • spec.ports (port, targetPort)
Ingress Manages external HTTP/HTTPS access to Services, typically providing URL routing and SSL/TLS termination.
  • apiVersion: networking.k8s.io/v1
  • kind
  • metadata
  • spec.rules (host, paths)
  • spec.tls
ConfigMap Stores non-sensitive configuration data as key-value pairs that applications can consume as environment variables or mounted files.
  • apiVersion
  • kind
  • metadata
  • data (key-value pairs)
Secret Stores sensitive information such as passwords, API keys, certificates, and authentication tokens.
  • apiVersion
  • kind
  • metadata
  • type (e.g. Opaque)
  • data or stringData
PersistentVolumeClaim (PVC) A request for storage by a user. It abstracts the underlying storage infrastructure and allows Pods to consume persistent storage easily.
  • apiVersion
  • kind
  • metadata
  • spec.accessModes
  • spec.resources.requests.storage

Common Structure Shared by Most Kubernetes Objects

Although Kubernetes objects serve different purposes, most YAML manifests share a common top-level structure.

✓ Key Observation

Most Kubernetes resources contain the following mandatory sections:
  • apiVersion — Defines the API group and version.
  • kind — Defines the Kubernetes object type.
  • metadata — Stores names, labels, annotations, and identifiers.

⚠ Important Note

The object-specific behavior is usually defined inside the spec section, while Kubernetes automatically maintains runtime information inside the status section.

Tip

If you understand the structure of a Pod, Deployment, Service, ConfigMap, Secret, and PVC, you can understand approximately 80% of the Kubernetes YAML files encountered in real-world projects.

No comments:

Post a Comment

Kubernetes Objects and Their YAML Structure

Kubernetes resources (objects) are represented by YAML manifests. Each object serves a specific purpose and contains a set of core configu...