A Complete Guide to Kubernetes Components & YAML Configuration


🌐 Overview
Kubernetes (K8s) is a powerful open-source container orchestration platform. It automates deployment, scaling, and management of containerized apps, serving as the industry standard for modern cloud-native workloads.
1. Kubernetes Architecture
Kubernetes follows a client-server (control/data plane) architecture (kubernetes.io, spacelift.io):
Control Plane (Master Node)
kube-apiserver: Main front-end exposing Kubernetes API. All user and component interactions go through it (kubernetes.io).
etcd: Fast, consistent key-value store for all cluster data (like Pod definitions, services) (kubernetes.io).
kube-scheduler: Assigns newly created Pods to nodes based on resource needs, affinity, policy (kubernetes.io).
kube-controller-manager: Runs controllers that ensure the cluster matches the declared desired state (kubernetes.io).
cloud-controller-manager: Manages cloud-specific integrations (e.g., load balancers); optional for on-prem setups (kubernetes.io).
Worker Nodes (Data Plane)
kubelet: Node agent that maintains Pod lifecycle and health (kubernetes.io).
kube-proxy: Handles networking rules to support Services and load balancing (kubernetes.io).
Container runtime: e.g., containerd, CRI-O or Docker—runs container images (en.wikipedia.org).
2. Core Kubernetes Resources
Pods: Smallest deployable unit, containing one or more co-located containers sharing network & storage (medium.com).
Services: Abstracts a logical group of Pods and exposes a policy for accessing them internally or externally (en.wikipedia.org).
Volumes: Attach persistent or ephemeral storage to Pods.
Namespaces: Virtual clusters for multi-tenancy and isolation (en.wikipedia.org).
ConfigMaps & Secrets: Store configuration or sensitive data separately from containers (en.wikipedia.org).
3. Controllers & Workloads
Controller | Purpose |
Deployment | Declarative updates via ReplicaSets (rolling updates, rollbacks). |
StatefulSet | Manages stateful apps; persistent identity/storage. |
DaemonSet | Ensures one pod per node (e.g., logging agents). |
Job / CronJob | Executes one-shot or scheduled batch tasks. |
4. YAML Configuration Essentials
Kubernetes uses YAML manifests to declare resources. A typical file includes:
apiVersion: <api group/version>
kind: <ResourceType>
metadata:
name: <unique-name>
labels: { key: value }
spec:
# resource-specific fields
Example: Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
spec:
containers:
- name: web
image: nginx:latest
ports:
- containerPort: 80
resources:
requests: { cpu: "100m", memory: "128Mi" }
limits: { cpu: "200m", memory: "256Mi" }
env:
- name: ENV
value: "prod"
volumeMounts:
- name: config
mountPath: /etc/config
volumes:
- name: config
configMap:
name: my-config
Key Sections Explained
resources: Defines minimal and maximum CPU/memory usage (spacelift.io).
env: Defines environment variables, including
valueFrom.secretKeyRef
for sensitive info (spacelift.io).volumeMounts/volumes: Mount ConfigMaps or Secrets into Pods.
probes: (Liveness, readiness, startup) – ensure application health.
5. Managing & Validating YAML
Always use stable API versions.
Store manifests in version control for rollbacks (kubernetes.io).
Group related manifests to simplify operations.
Validate YAML with
kubectl apply --dry-run=client
.Prefer Kustomize, Helm, or templating tools for complex deployments (learnk8s.io, mirantis.com).
6. Extended Features & Ecosystem
Networking: Services types (ClusterIP, NodePort, LoadBalancer), Network Policies.
Storage: PVCs/PVs and StorageClasses.
RBAC: Role and ClusterRole permissions.
Tooling:
Helm, Kustomize: Manage deployments.
Prometheus, Grafana: Monitor and visualize metrics.
Istio, Linkerd: Service mesh for microservices.
Flux/ArgoCD: GitOps-based CI/CD pipelines.
7. Best Practices
Set realistic CPU/memory requests and limits.
Always configure health probes.
Use PodDisruptionBudgets to maintain availability during upgrades.
Define security contexts and apply network segmentation.
Use Namespaces and ResourceQuotas for resource isolation.
Consistently label resources for easier management.
Externalize config via ConfigMaps/Secrets.
Regularly audit and back up etcd.
Conclusion
Understanding Kubernetes requires mastering its architecture, resource types, YAML configuration, and ecosystem tools. A well-structured YAML manifest and thoughtful resource design form the foundation of reliable, scalable, and secure cloud-native applications.
Subscribe to my newsletter
Read articles from Di Nrei Alan Lodam directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
