What are core Kubernetes abstractions (Pod, Deployment, Service, ConfigMap, Secret)?
❓ Interview Prompt: Explain Kubernetes Pods, Deployments (replica management), Services (network endpoints), ConfigMaps, and Secrets with YAML examples.
Kubernetes manages containerized workloads through a set of declarative API objects:
Pod — Atomic Unit of Scheduling:
A Pod is the smallest deployable unit in Kubernetes — one or more tightly-coupled containers sharing the same network namespace and storage volumes. Pods are ephemeral; controllers manage their lifecycle.
Deployment — Replica Management:
A Deployment describes the desired state for stateless Pod replicas. The Deployment Controller continuously reconciles the actual state with the desired state — creating, replacing, or scaling Pods automatically. Supports rolling updates and rollbacks.
Service — Stable Network Endpoint:
A Service provides a stable IP address and DNS name for a set of Pods selected via label selectors. Pods are ephemeral (IPs change); Services provide a consistent endpoint. Types: ClusterIP (internal), NodePort (external), LoadBalancer (cloud LB).
ConfigMap — Non-secret Configuration:
Key-value pairs injected as environment variables or mounted files into Pods. For non-sensitive data (feature flags, connection strings without passwords).
Secret — Sensitive Configuration:
Like ConfigMaps but Base64-encoded and intended for sensitive data (API keys, TLS certificates, database passwords). Stored encrypted at rest when KMS encryption is enabled.
Code Implementation Example
# Deployment — manages 3 replicas of the API pod
apiVersion: apps/v1
kind: Deployment
metadata:
name: api
spec:
replicas: 3
selector:
matchLabels:
app: api
template:
metadata:
labels:
app: api
spec:
containers:
- name: api
image: myapp:v1.2.3
ports:
- containerPort: 3000
envFrom:
- configMapRef:
name: api-config # inject ConfigMap as env vars
- secretRef:
name: api-secrets # inject Secret as env vars
resources:
limits:
memory: "512Mi"
cpu: "500m"
---
# Service — stable ClusterIP endpoint selecting Deployment pods
apiVersion: v1
kind: Service
metadata:
name: api-svc
spec:
selector:
app: api # selects all pods with label app=api
ports:
- port: 80
targetPort: 3000
type: ClusterIPDeployments manage Pod replicas and rolling updates; Services provide stable network endpoints regardless of Pod IP churn. Always use resource limits.