Kubernetes Fundamentals: Complete Orchestration Guide
· Pavan Y N · kubernetes, containers, devops, cloud
Kubernetes (K8s) is an open source container orchestration platform. It schedules containers onto a cluster of machines, keeps them running, connects them to each other, and rolls out changes gradually. EduGeek explains the architecture, the core objects, and the day-to-day kubectl commands, using manifests that validate against current Kubernetes releases (1.35 through 1.37 at the time of writing).
# What is Kubernetes?
Kubernetes runs containerized applications across clusters of machines and provides:
- →Automated deployment: declare the desired state, and controllers make the cluster match it
- →Scaling: change replica counts manually or automatically
- →Self-healing: restart failed containers and replace pods when a node fails
- →Service discovery and load balancing: stable names and virtual IPs in front of changing pods
- →Rolling updates and rollbacks: replace pods gradually, and undo a bad release
If containers are new to you, read Docker Fundamentals first.
# Kubernetes architecture
A cluster has a control plane and worker nodes.
## Control plane components
- →kube-apiserver: exposes the Kubernetes HTTP API and is the front door for every client and component
- →etcd: a consistent, highly available key-value store holding all API server data
- →kube-scheduler: assigns pods that have no node to a suitable node
- →kube-controller-manager: runs the controllers that implement API behavior
- →cloud-controller-manager (optional): integrates with the underlying cloud provider
Older material calls the control plane machines "master nodes." Current Kubernetes documentation says control plane.
## Node components
- →kubelet: the node agent that ensures pods and their containers are running
- →kube-proxy (optional): maintains network rules on nodes to implement Services
- →Container runtime: the software that runs containers, such as containerd or CRI-O
Pods are the workloads that run on nodes, not node components. Docker Engine is not a supported runtime through a built-in integration: the dockershim component was removed from Kubernetes in version 1.24. Images built with Docker still run unchanged on containerd and CRI-O, because they follow the standard OCI image format.
# Core concepts
## Pods
A Pod is the smallest deployable unit. It holds one or more containers that share a network namespace and storage volumes.
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
spec:
containers:
- name: nginx
image: nginx:1.30
ports:
- containerPort: 80
A bare Pod is not rescheduled if its node fails. Production workloads normally run under a controller such as a Deployment.
## Deployments
A Deployment manages a set of identical pods through a ReplicaSet and handles rolling updates:
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
replicas: 3
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.30
ports:
- containerPort: 80
The selector must match the pod template labels, and in apps/v1 it is required.
## Services
A Service gives a set of pods a stable virtual IP and DNS name:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
The default Service type is ClusterIP, which is reachable only inside the cluster. port is the port clients connect to, and targetPort is the port on the pods. Other types expose the Service further:
| Type | Behavior |
|---|---|
ClusterIP (default) | Internal virtual IP only |
NodePort | Also opens a port on every node |
LoadBalancer | Also requests an external load balancer from the cloud provider or a load balancer add-on |
ExternalName | Maps the Service name to a DNS name |
type: LoadBalancer only works where something provisions the load balancer. On a local kind or minikube cluster without an add-on, the external IP typically stays <pending>. For HTTP routing into the cluster, see Advanced Kubernetes, which covers Ingress and the Gateway API.
# Essential kubectl commands
# Get resources
kubectl get pods
kubectl get deployments
kubectl get services
kubectl get pods -n kube-system # in a specific namespace
kubectl get pods -o wide # extra columns, including the node
# Describe resources
kubectl describe pod <pod-name>
kubectl describe deployment <deployment-name>
# View logs
kubectl logs <pod-name>
kubectl logs -f <pod-name> # follow
kubectl logs <pod-name> --previous # the previous container instance
# Run a command in a pod (use sh if the image has no bash)
kubectl exec -it <pod-name> -- /bin/sh
# Apply configuration
kubectl apply -f deployment.yaml
# Watch and manage a rollout
kubectl rollout status deployment/nginx-deployment
kubectl rollout history deployment/nginx-deployment
kubectl rollout undo deployment/nginx-deployment
# Delete resources
kubectl delete pod <pod-name>
kubectl delete deployment <deployment-name>
# ConfigMaps and Secrets
## ConfigMap
A ConfigMap stores non-sensitive configuration:
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
database_url: "postgres://db:5432"
log_level: "info"
## Secret
A Secret stores sensitive values:
apiVersion: v1
kind: Secret
metadata:
name: app-secret
type: Opaque
stringData:
password: example-password # written as plain text, stored base64-encoded
Values under data must be base64-encoded, while stringData accepts plain text and the API server encodes it. Base64 is an encoding, not encryption. The Kubernetes documentation states that Secrets are stored unencrypted in etcd by default, and that anyone with API access, or permission to create a pod in the namespace, can read them. At a minimum, enable encryption at rest, apply least-privilege RBAC rules, and consider an external secret store. Never commit real Secret manifests to Git.
# Troubleshooting pods
## Common issues
Pending: the scheduler cannot place the pod.
kubectl describe pod <pod-name>
# Look in Events for: insufficient CPU or memory, node selector or taint mismatch,
# or an unbound PersistentVolumeClaim
CrashLoopBackOff: the container starts and exits repeatedly.
kubectl logs <pod-name> --previous
# Look for: application errors, missing configuration, failing probes
ImagePullBackOff: the image cannot be pulled.
kubectl describe pod <pod-name>
# Check: image name and tag, registry access, imagePullSecrets
For images without a shell, such as distroless images, attach a temporary debugging container instead of using kubectl exec:
kubectl debug -it <pod-name> --image=busybox:1.37 --target=<container-name>
# Resource management
## Resource requests and limits
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Requests are what the scheduler reserves when it places the pod. Limits are the ceiling the container may use. A container that exceeds its memory limit is killed, and the pod shows OOMKilled. Requests also drive autoscaling and the pod's quality of service class, covered in Advanced Kubernetes.
# Health checks
Probes tell the kubelet how to check a container.
- →A liveness probe detects a container stuck in a broken state, and the kubelet restarts the container when it fails.
- →A readiness probe decides whether the pod receives traffic. A failing readiness probe removes the pod from Service endpoints but does not restart it.
- →A startup probe protects slow-starting applications. Liveness and readiness checks are disabled until it succeeds.
startupProbe:
httpGet:
path: /health
port: 8080
periodSeconds: 5
failureThreshold: 30 # up to 150 seconds to start
livenessProbe:
httpGet:
path: /health
port: 8080
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
periodSeconds: 5
A startup probe is the better answer to a slow start than a large initialDelaySeconds on the liveness probe, which delays detection of real failures after startup. Keep the liveness endpoint limited to the process itself. If it also checks a database, a database outage makes every replica fail liveness and restart. Put dependency checks in the readiness probe.
# Best practices
- •Use namespaces: separate teams, environments, and quotas.
- •Set requests and limits: prevent one workload from starving others.
- •Add readiness, liveness, and startup probes: enable self-healing and safe rollouts.
- •Use labels consistently: Services, Deployments, and tooling select pods by label.
- •Pin image versions: avoid
:latestin production so rollouts and rollbacks are predictable. - •Keep configuration out of images: use ConfigMaps and Secrets, and protect Secrets as described above.
- •Enforce Pod Security Standards: the built-in Pod Security Admission controller (stable since Kubernetes 1.25) enforces the
privileged,baseline, orrestrictedlevel per namespace through labels such aspod-security.kubernetes.io/enforce: restricted. It replaced PodSecurityPolicy. - •Monitor everything: see Prometheus Monitoring.
# Next steps
- •Create a local cluster with kind or minikube, or enable Kubernetes in Docker Desktop.
- •Deploy the examples above and break them on purpose: wrong image tag, failing probe, too-small memory limit.
- •Practice
kubectl describe,logs, androllout. - •Continue with Advanced Kubernetes for Helm, Gateway API and Ingress, and autoscaling.
- •Learn how to manage cluster state from Git in GitOps: The Complete Guide.
# Key takeaways
- →A Kubernetes cluster consists of a control plane (API server, etcd, scheduler, controller manager) and worker nodes running the kubelet, optional kube-proxy, and a container runtime.
- →Docker Engine is no longer integrated with Kubernetes because dockershim was removed in 1.24, but Docker-built images run on containerd and CRI-O unchanged.
- →Run workloads under Deployments rather than bare Pods, and remember that a Deployment's
selectormust match its pod template labels. - →A Service defaults to
ClusterIP, andtype: LoadBalancerneeds a cloud provider or add-on to provision the external load balancer. - →Secrets are base64-encoded and unencrypted in etcd by default, so enable encryption at rest, restrict access with RBAC, and keep real Secret manifests out of Git.
- →Use startup, readiness, and liveness probes for different jobs, and never make the liveness probe depend on external services.
- →Pin image tags instead of using
:latest, and enforce Pod Security Standards with Pod Security Admission labels on namespaces.
# Further reading
Test yourself: Kubernetes Fundamentals assessment