Complete Reference Guide for Kubernetes Concepts, Architecture, and Best Practices
kubectl apply is the primary command for deploying and updating Kubernetes resources. It follows a declarative approach where you define the desired state in YAML files, and Kubernetes ensures the cluster matches that state.
Pod.yaml file with desired configurationkubectl apply -f Pod.yaml command| Component | Role | Location |
|---|---|---|
| API Server | Entry point for all requests, RESTful interface | Control Plane |
| etcd | Persistent storage for cluster state | Control Plane |
| Scheduler | Assigns pods to nodes | Control Plane |
| Kubelet | Runs containers on nodes | Worker Node |
| Kube-proxy | Manages network rules and service routing | Worker Node |
apiVersion: v1
kind: Pod
metadata:
name: my-app-pod
labels:
app: my-app
spec:
containers:
- name: app-container
image: my-app:latest
ports:
- containerPort: 8080
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
Kubernetes uses DNS to provide service discovery. Because Pods are dynamicβthey restart, scale, and their IPs keep changingβDNS is essential for reliable communication between services.
CoreDNS is a flexible, extensible DNS server that serves as Kubernetes' cluster DNS. It automatically discovers services and resolves their names to IP addresses.
my-service.default.svc.cluster.local)<service-name>.<namespace>.svc.cluster.local
backend.default.svc.cluster.local - Service in default namespacedatabase.production.svc.cluster.local - Service in production namespacecache.monitoring.svc.cluster.local - Service in monitoring namespaceCoreDNS runs as a Deployment in the kube-system namespace and is configured via a ConfigMap. You can view the current configuration with:
kubectl get configmap coredns -n kube-system -o yaml
Kubernetes is a containerization platform that provides automated deployment, scaling, and management of containerized applications. It abstracts away the underlying infrastructure and provides a unified interface for managing containers across a cluster of machines.
Kubernetes follows a master-worker (or control plane-worker node) architecture:
The management layer that maintains the desired state of the cluster.
Run the actual application containers.
The Control Plane is the brain of Kubernetes and consists of several critical components:
Worker Nodes run the actual application containers and consist of:
kubectl β API Server β etcd β Scheduler β Node β Pod runs
| Benefit | Explanation |
|---|---|
| Separation of Concerns | Control Plane manages, Worker Nodes execute |
| Scalability | Add more nodes without changing control plane logic |
| Resilience | Control Plane can be replicated for high availability |
| Flexibility | Different workload types can run on different nodes |
| Declarative Management | Define desired state, Kubernetes ensures it |
Ingress is a Kubernetes API object that manages external access to services within a cluster. It provides HTTP and HTTPS routing to services based on hostnames and URL paths.
Without Ingress, you would need to:
Ingress solves this by providing a single entry point with intelligent routing.
Defines routing rules (YAML configuration)
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
spec:
rules:
- host: example.com
http:
paths:
- path: /api
pathType: Prefix
backend:
service:
name: api-service
port:
number: 8080
- path: /web
pathType: Prefix
backend:
service:
name: web-service
port:
number: 3000
Implements the Ingress rules (e.g., NGINX, HAProxy, Istio)
api.example.com β api-service
web.example.com β web-service
admin.example.com β admin-service
example.com/api β api-service
example.com/web β web-service
example.com/admin β admin-service
api.example.com/v1 β api-v1-service
api.example.com/v2 β api-v2-service
| Controller | Features | Use Case |
|---|---|---|
| NGINX | Lightweight, fast, widely used | General purpose routing |
| HAProxy | High performance, advanced features | Enterprise deployments |
| Istio | Service mesh, advanced traffic management | Complex microservices |
| Traefik | Cloud-native, dynamic configuration | Modern cloud deployments |
Probes are diagnostic checks that Kubernetes uses to determine the health and readiness of containers. They help Kubernetes make intelligent decisions about pod lifecycle management.
Use Cases:
Example:
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 30
periodSeconds: 10
Use Cases:
Example:
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 10
periodSeconds: 5
Example:
startupProbe:
httpGet:
path: /startup
port: 8080
failureThreshold: 30
periodSeconds: 10
httpGet:
path: /health
port: 8080
scheme: HTTP
httpHeaders:
- name: Custom-Header
value: Awesome
tcpSocket:
port: 8080
exec:
command:
- /bin/sh
- -c
- curl localhost:8080/health
| Parameter | Description | Default |
|---|---|---|
initialDelaySeconds |
Delay before first probe | 0 |
periodSeconds |
Interval between probes | 10 |
timeoutSeconds |
Probe timeout | 1 |
failureThreshold |
Failures before marking unhealthy | 3 |
successThreshold |
Successes before marking healthy | 1 |
$ kubectl apply -f deployment.yaml
User (kubectl apply)
β
API Server (validate & store)
β
etcd (persistent storage)
β
Controllers (create resources)
β
Scheduler (assign to node)
β
Kubelet (create container)
β
Container Runtime (run container)
β
Running Pod (serving traffic)
kubectl describe, kubectl logs, and kubectl get events to see what's happening at each stage.
What: Smallest deployable unit in Kubernetes
Contains: One or more containers
Lifetime: Ephemeral (can be created and destroyed)
Use: Never create Pods directly; use Deployments
What: Stable endpoint for accessing pods
Purpose: Provides service discovery and load balancing
Types: ClusterIP, NodePort, LoadBalancer, ExternalName
Benefit: Pods can change, but Service IP remains stable
What: Declarative way to manage pods
Features: Scaling, rolling updates, rollbacks
Manages: ReplicaSets and Pods
Use: Primary way to deploy stateless applications
What: Store configuration data
Format: Key-value pairs
Use Cases: Environment variables, config files
Benefit: Separate configuration from application code
What: Store sensitive data
Types: Opaque, TLS, ServiceAccount, Docker registry
Encoding: Base64 encoded (not encrypted by default)
Use: Passwords, API keys, certificates
What: Virtual cluster within a cluster
Purpose: Isolate resources and teams
Default: default, kube-system, kube-public
Benefit: Multi-tenancy and resource organization
| Object | Purpose | Scope | Typical Use |
|---|---|---|---|
| Pod | Run containers | Namespace | Basic unit (usually via Deployment) |
| Service | Network access | Namespace | Expose pods to network |
| Deployment | Manage pods | Namespace | Deploy applications |
| ConfigMap | Store config | Namespace | Application configuration |
| Secret | Store secrets | Namespace | Sensitive data |
| Namespace | Isolate resources | Cluster | Multi-tenancy |
A Pod is the smallest deployable unit in Kubernetes. It's a wrapper around one or more containers (usually one) that runs together on the same node and shares network namespace.
| Phase | Description |
|---|---|
| Pending | Pod accepted but containers not yet running (waiting for resources) |
| Running | Pod bound to node, at least one container running |
| Succeeded | All containers terminated successfully (job pods) |
| Failed | At least one container terminated with failure |
| Unknown | Pod state cannot be determined |
apiVersion: v1
kind: Pod
metadata:
name: my-first-pod
labels:
app: hello-world
spec:
containers:
- name: hello-container
image: nginx:latest
ports:
- containerPort: 80
$ kubectl apply -f pod.yaml
pod/my-first-pod created
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-first-pod 1/1 Running 0 10s
$ kubectl describe pod my-first-pod
$ kubectl logs my-first-pod
$ kubectl exec -it my-first-pod -- /bin/bash
apiVersion: v1
kind: Pod
metadata:
name: multi-container-pod
spec:
containers:
- name: web-container
image: nginx:latest
ports:
- containerPort: 80
- name: app-container
image: my-app:latest
ports:
- containerPort: 8080
apiVersion: v1
kind: Pod
metadata:
name: resource-limited-pod
spec:
containers:
- name: app
image: my-app:latest
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
apiVersion: v1
kind: Pod
metadata:
name: env-pod
spec:
containers:
- name: app
image: my-app:latest
env:
- name: ENVIRONMENT
value: "production"
- name: DEBUG
value: "false"
- name: DATABASE_PASSWORD
valueFrom:
secretKeyRef:
name: db-secret
key: password
| Command | Purpose |
|---|---|
kubectl get pods |
List all pods |
kubectl describe pod <name> |
Get detailed pod information |
kubectl logs <pod-name> |
View pod logs |
kubectl exec -it <pod-name> -- /bin/bash |
Execute command in pod |
kubectl port-forward <pod-name> 8080:80 |
Forward local port to pod |
kubectl delete pod <pod-name> |
Delete a pod |