Objects

You write the spec, and Kubernetes fills in the status

apiVersion: apps/v1kind: Deploymentmetadata: name: webspec: replicas: 3status: readyReplicas: 2which API group and versionwhat sort of object it isits name, with namespace and labelswhat you want: you write thisdesired statewhat exists: Kubernetes writes thisactual statea controllerworks until statusmatches specEverything in Kubernetes is an object: you write the spec, and Kubernetes fills in the status.Every object has the same four parts: apiVersion and kind say what it is, metadata names it, and specdeclares what you want. This is the declarative model. You never tell Kubernetes what to do, onlywhat should be true, and a controller keeps working until it is.

Every object has apiVersion, kind, metadata and spec. Kubernetes adds status.

Objects · Going deeper

The kinds of object

The kinds of object, grouped by jobRun thingsPod, Deployment, ReplicaSet, StatefulSet, DaemonSet, Job, CronJobConnect thingsService, Ingress, Gateway, NetworkPolicyConfigure thingsConfigMap, SecretStore thingsPersistentVolume, PersistentVolumeClaim, StorageClassDivide the clusterNamespace, ResourceQuota, LimitRangeControl accessServiceAccount, Role, ClusterRole, RoleBinding, ClusterRoleBindingExtend KubernetesCustomResourceDefinition: your own kind of objectWhen a question names a job, the answer is one of the kinds on its row.Imperative means giving commands, one at a time. Declarative means handing over the desired state.

Kinds that run, connect, configure, store, divide, control and extend.

Components

Every component talks to the API server, and to nothing else

kube-apiserverthe only door to the clusterkubectlyou, or any other clientetcdstores all cluster statekube-schedulerpicks a node for each new podkube-controller-managerruns the control loopscloud-controller-managertalks to the cloud providerkubelet and kube-proxyon every nodeEvery component talks to the API server, and only the API server talks to etcd.The API server, etcd, the scheduler and the two controller managers are the control plane: it decides.The kubelet and kube-proxy run on each worker node, beside a container runtime such as containerd:they carry the decisions out. Nothing reaches around the API server, so it is where access is checked.

The API server is the only door, and the only thing that talks to etcd.

Components · Going deeper

Eight components, one job each

ComponentRuns onIts one jobkube-apiservercontrol planeServes the Kubernetes API; validates and stores every requestetcdcontrol planeKey-value store holding the state of the whole clusterkube-schedulercontrol planeAssigns each unscheduled pod to a nodekube-controller-managercontrol planeRuns the controllers that drive actual state to desiredcloud-controller-managercontrol planeLinks the cluster to the cloud: load balancers, nodes, routeskubeletevery nodeMakes sure the containers of its pods are running and healthykube-proxyevery nodeMaintains the network rules that make Services workcontainer runtimeevery nodePulls images and runs containers: containerd or CRI-OScheduler decides where. Kubelet makes it run. Controllers decide how many. The exam swaps these.In a managed service such as GKE, EKS or AKS, the provider runs the control plane and you run the nodes.

Scheduler decides where. Kubelet makes it run. Controllers decide how many.

Check yourself

schedulercontroller managerkubelet?etcd

Which component belongs at the "?"

Workloads

Choose the controller by what the pods need

DEPLOYMENTwebwebwebidentical copies,freely replacedSTATEFULSETdb-0db-1db-2stable names,a disk eachDAEMONSETagentagentagentnode 1node 2node 3exactly oneon every nodeJOBtaskthen doneruns to the end,then stopsCRONJOBtaskdaily, 02:00a Job, startedon a scheduleYou rarely create pods yourself. You choose the controller that fits what the pods need.A Deployment is for stateless services. A StatefulSet is for databases and anything that needs itsown identity and storage. A DaemonSet is for agents every node must run. A Job is for work thatfinishes, and a CronJob starts Jobs on a timetable.

Deployment for stateless copies, StatefulSet for identity, DaemonSet per node, Job and CronJob for finite work.

Workloads · Going deeper

Deployments, ReplicaSets and rolling updates

A Deployment owns ReplicaSets, and a ReplicaSet owns podsDeploymentthe version you wantReplicaSetkeeps the countPodsrun the containersA rolling update, step by stepold ReplicaSet (v1)new ReplicaSet (v2)startone swappedtwo swappedfinishedAn update makes a new ReplicaSet and shifts pods across a few at a time, so the service never stops.The old ReplicaSet is kept at zero, which is what makes a rollback one command. A bare ReplicaSetis almost never created by hand: the Deployment manages it.

A Deployment owns ReplicaSets, and an update shifts pods from old to new.

Pods

A pod is containers that share one address and one fate

A POD · ONE ADDRESS: 10.1.2.7app containerserves on port 8080sidecar containerships the logsthey reach each other on localhostshared volumeboth can use itinit containers run first, one at a time, each to completionthe smallest thing Kubernetes runsplaced on one node, as a unitdisposable: a new pod, a new addressusually one main containerA pod is one or more containers that share an address and storage, and live and die together.Kubernetes schedules pods, not containers. Containers in one pod share a network namespace, so theyshare one IP address and one set of ports. Put two containers in a pod only when they cannot workapart, such as an application and the helper that ships its logs.

A pod shares one IP address and its volumes among its containers.

Pods · Going deeper

Pod phases and probes

The five phases of a podPendingAccepted, but not running yet: waiting for a node, or pulling imagesRunningBound to a node, and at least one container is runningSucceededEvery container finished successfully and will not restartFailedEvery container has stopped, and at least one ended in failureUnknownThe node cannot be reached, so the state cannot be readPhase is the pod as a whole. Readiness is a separate question: can it take traffic yet?A liveness probe restarts a container that has hung. A readiness probe keeps a pod out of a Serviceuntil it can answer. A startup probe gives a slow application time before the other two begin.

Pending, Running, Succeeded, Failed, Unknown.

Check yourself

NODE 1agentNODE 2agentNODE 3agentNODE 4agentnode 4 was just added; nobody created its pod by hand

A fourth node joins the cluster and gets the same pod at once. Which controller is this?

Labels

Objects find each other by label, not by name

podapp=webpodapp=webpodapp=webpodapp=dbDeploymentselector: app=webServiceselector: app=weblabel does not match:neither one sees itObjects find each other by labels. Nothing holds a list of pod names.A label is a key and a value on an object. A selector is a query for labels. The Deployment and theService do not know about each other: both simply select the same pods. Replace a pod and the newone is found at once, because it carries the same label.

A label marks an object. A selector finds every object with that label.

Labels · Going deeper · 1 of 2

Names, namespaces, labels, annotations

Four ways an object is identifiedWhat it isUsed forNameunique within a namespace, for one kindreferring to one objectNamespacea named division of the clusterseparating teams and environmentsLabelkey and value that selectors can querygrouping and selecting objectsAnnotationkey and value that selectors cannot querynotes for tools and peopleUIDan identifier Kubernetes generatestelling apart two objects that reused a nameLabels select. Annotations describe. That one difference is a favourite exam question.Some objects are not in any namespace: Nodes, PersistentVolumes, StorageClasses and Namespaces themselves.

Labels select. Annotations only describe.

Labels · Going deeper · 2 of 2

Clue words for core concepts

When the question saysThe answer isBecause it is"the only component that talks to etcd"kube-apiserverthe front door"stores cluster state", "key-value"etcdthe database"assigns pods to nodes"kube-schedulerdecides where"reconciles", "control loops"kube-controller-managerdecides how many"agent on each node", "runs pods"kubeletmakes it run"network rules for Services"kube-proxyroutes traffic"stateless", "rolling update"Deploymentreplaceable copies"stable identity", "ordered", "own storage"StatefulSetnamed replicas"one per node", "log or monitoring agent"DaemonSetevery node"run once to completion"Jobfinite work"smallest deployable unit"Podshared network and storage"group and select objects"Labels and selectorsloose couplingCore concepts is about a quarter of domain 1. These twelve cover most of it.

Each component and controller by its one job.

Check yourself

Namesfixed and numbered: db-0, db-1, db-2Storageeach pod keeps its own diskStart-upone at a time, in order

A team lists what its pods need as shown. Which controller fits?

Lesson complete

You finished “Kubernetes core concepts”

Answer the questions along the way to see your score here.

Open in a new tab