Core Kubernetes · 01
What is Kubernetes
1.What is Kubernetes ?
Kubernetes is an open-source platform that runs containers across a cluster of machines.
You do not give it a list of steps. You declare the state you want as API objects, and control loops keep pulling the cluster toward it.
- ManagedEKS, GKE, AKS run the control plane.
- Distributionsk3s, RKE2, OpenShift, Talos package it with defaults.
- Localkind, minikube, k3d on a laptop.
- Extendyour own object types and controllers.
- NameGreek for helmsman or pilot. K8s = K, 8 letters, s.
- RootsIdeas from Borg, Google's in-house cluster manager.
- 2014First commit June 6. Google open-sources it.
- 2015v1.0 on July 21. Google pledges it to the new CNCF.
- OSLinux control plane. Linux or Windows workers.
- HomeCNCF hosts it.
- Nowv1.37, patch v1.37.1.
2.Why does it exist ?
An image packages your app. Production needs more : keep it running on many machines, with no downtime. By hand, you are the scheduler, health checker, load balancer and upgrade script.
| Chore | One host, by hand | Kubernetes |
|---|---|---|
| Placement | You pick a host, then SSH in | Scheduler packs Pods by CPU / memory requests |
| Crashed container | Restart policy, same host | Restart, kill on failed checks, no traffic until ready |
| Dead machine | Down until you rebuild it | Deployment replaces the Pods on healthy nodes, after about 5 min |
| More copies | Start more, edit the proxy | kubectl scale, or an HPA fed by metrics-server |
| Upgrade | Stop old, start new, undo by hand | Rolling update, kubectl rollout undo to go back |
| Finding the app | Hard-coded host IP:port | DNS name or IP, load-balanced across copies |
| Config, secrets | Env files on the host, or in the image | ConfigMaps and Secrets, no image rebuild |
| Source of truth | Shell history and memory | API objects, plus manifests kept in Git |
3.Desired vs current state
Every object is a record of intent. You write its spec (what you want). Kubernetes writes its status (what is true now).
A controller is a never-ending loop, like a thermostat. It watches, compares spec with status, and asks the API server for changes until they match.
1.What you get, and what you do not
- Service discovery and load balancing (Services)
- Rollouts and rollbacks at a set pace
- Bin packing : Pods placed by CPU / memory requests
- Self-healing : restart, replace, kill on failed checks
- Storage, batch jobs, secrets and config
- Horizontal scaling, IPv4 / IPv6 dual-stack
- Not an all-in-one PaaS : no code builds, no CI/CD
- No built-in databases, caches or middleware
- No required logging, monitoring or config language
- Does not set up or manage your machines
- Upstream ships no metrics-server (an HPA needs one)
2.Everything is an API object
Pods, Namespaces, ConfigMaps, Events : each is an object behind one HTTP API on the API server. kubectl and controllers all go through it. You write YAML, kubectl sends JSON.
apiVersion: apps/v1 # core kinds use just v1 kind: Deployment metadata: name: web spec: # desired state, yours replicas: 3 # 1 if left out selector: # required, immutable matchLabels: {app: web} template: # the Pod template metadata: labels: {app: web} # = selector spec: containers: - name: web image: nginx:1.30 # no status here : Kubernetes writes it
3.Three ways to manage objects
| Technique | Example | Works on | Best for |
|---|---|---|---|
| Imperative commands | kubectl create deployment web --image=nginx:1. | Live objects | Dev, trying things |
| Imperative object config | kubectl create -f web.yaml, then replace -f | Single files | Production |
| Declarative object config | kubectl diff -f configs/, then kubectl apply -f configs/ | Folders of files | Production |
apply keeps changes made by other writers. Use one technique per object, mixing them is undefined. replace drops whatever the file leaves out, even an HPA's changes.
4.First commands
| Command | What it does |
|---|---|
kind create cluster | Local cluster, nodes are containers (or minikube start) |
kubectl version --client | Client version. Stay within 1 minor of the server |
kubectl config get-contexts | Contexts (cluster, user, namespace) in ~/.kube/config |
kubectl api-resources | Every type this cluster serves, with its group/version |
kubectl explain pods. | Field docs from the cluster's own schema |
kubectl create deployment web --image=nginx:1. | Starter manifest, nothing sent to the cluster |
kubectl diff -f web.yaml | Preview apply. Exit 1 = changes found, above 1 = error |
kubectl apply -f web.yaml | Create or update objects to match the file |
kubectl get deploy web -o yaml | Spec and status, side by side |
kubectl scale --replicas=5 deployment/web | Imperative. The next apply undoes it if the file sets replicas |
kubectl get pods -w | Watch live. Delete a Pod, see a new one appear |
kubectl diff then kubectl apply.