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.
Fact file
  • 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.

Runtime vs orchestratorA runtime starts containers on one host. An orchestrator picks hosts, keeps the count and replaces what fails.
By hand, one host You SSH, scripts Host A 3 web containers crash : restart policy, same host Host dies all 3 stay down until you rebuild With an orchestrator You replicas: 3 apply Control plane API, scheduler, controllers Node 1 Node 2 lost Node 3 want 3, have 2 : new Pods start on Node 1 and 3
ChoreOne host, by handKubernetes
PlacementYou pick a host, then SSH inScheduler packs Pods by CPU / memory requests
Crashed containerRestart policy, same hostRestart, kill on failed checks, no traffic until ready
Dead machineDown until you rebuild itDeployment replaces the Pods on healthy nodes, after about 5 min
More copiesStart more, edit the proxykubectl scale, or an HPA fed by metrics-server
UpgradeStop old, start new, undo by handRolling update, kubectl rollout undo to go back
Finding the appHard-coded host IP:portDNS name or IP, load-balanced across copies
Config, secretsEnv files on the host, or in the imageConfigMaps and Secrets, no image rebuild
Source of truthShell history and memoryAPI 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.

Loops, not a scriptNot a workflow engine : no fixed A, then B, then C, and no central brain. Many small loops each fix their own part. A busy cluster may never look stable, and that is fine.
You or CI kubectl apply The real cluster Pods crash, nodes fail writes spec watch, report API server every read and write Deployment web spec : 3 replicas status : 2 ready watch Controller compares spec, status differ 2 vs 3 Act ask for 1 more Pod request match : keep watching
In short : Kubernetes runs your containers across a cluster. You declare the state you want, and never-ending control loops keep pushing the real state toward it.

1.What you get, and what you do not

Built in
  • 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 included
  • 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.

Your manifest becomes the object apiVersionapps/v1 kindDeployment metadatanamespace, name specwhat you want statuswhat is true Identity API group + resource type + namespace + name not the version Controllers read spec, write status
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

TechniqueExampleWorks onBest for
Imperative commandskubectl create deployment web --image=nginx:1.30Live objectsDev, trying things
Imperative object configkubectl create -f web.yaml, then replace -fSingle filesProduction
Declarative object configkubectl diff -f configs/, then kubectl apply -f configs/Folders of filesProduction

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

CommandWhat it does
kind create clusterLocal cluster, nodes are containers (or minikube start)
kubectl version --clientClient version. Stay within 1 minor of the server
kubectl config get-contextsContexts (cluster, user, namespace) in ~/.kube/config
kubectl api-resourcesEvery type this cluster serves, with its group/version
kubectl explain pods.spec.containersField docs from the cluster's own schema
kubectl create deployment web --image=nginx:1.30 --dry-run=client -o yamlStarter manifest, nothing sent to the cluster
kubectl diff -f web.yamlPreview apply. Exit 1 = changes found, above 1 = error
kubectl apply -f web.yamlCreate or update objects to match the file
kubectl get deploy web -o yamlSpec and status, side by side
kubectl scale --replicas=5 deployment/webImperative. The next apply undoes it if the file sets replicas
kubectl get pods -wWatch live. Delete a Pod, see a new one appear
In short : Everything is an API object : you write the spec, Kubernetes writes the status. Manage each object one way, ideally kubectl diff then kubectl apply.