{"id":386,"date":"2026-12-04T12:00:00","date_gmt":"2026-12-04T12:00:00","guid":{"rendered":"https:\/\/rezachegini.com\/?p=386"},"modified":"2026-12-04T19:45:05","modified_gmt":"2026-12-04T19:45:05","slug":"ckad-prep-part-4-who-owns-this-pod","status":"publish","type":"post","link":"https:\/\/rezachegini.com\/?p=386","title":{"rendered":"CKAD Prep, Part 4: Who Owns This Pod?"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Where we are<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Hi, I&#8217;m Reza. I&#8217;m sharing my preparation for the CKAD exam, practiced on a <a href=\"https:\/\/k3s.io\/\">K3s<\/a> cluster in my home lab. I am a junior engineer looking for my first SRE, DevOps or Cloud job, and that is why I learn in public. You can see how I think, what breaks, and how I fix it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/rezachegini.com\/?p=382\">Part 3<\/a> ended with a gap: a ReplicaSet keeps the number of pods right, but a new image never reaches the running ones. Deployments fill that gap. This part is about how they do it, and who owns what:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C1: create and scale a Deployment.<\/li>\n\n\n\n<li>C2: follow the ownership chain with <code>ownerReferences<\/code>.<\/li>\n\n\n\n<li>C4: delete a pod, then delete its ReplicaSet, and watch both come back.<\/li>\n\n\n\n<li>C5: fix a Deployment manifest with two bugs.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">(C3, where the template changes a few times, sits between C2 and C4. I&#8217;m leaving its details out of this part, but you&#8217;ll see its leftovers in C4.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The key picture is a chain of three levels. You only create the top one:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"744\" height=\"272\" src=\"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/12\/ckad-prep-part-4-diagram.png\" alt=\"Each level heals the level below it: a Deployment owns a ReplicaSet, which owns the pods.\" class=\"wp-image-385\" srcset=\"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/12\/ckad-prep-part-4-diagram.png 744w, https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/12\/ckad-prep-part-4-diagram-300x110.png 300w\" sizes=\"auto, (max-width: 744px) 100vw, 744px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The confusing part: you create a Deployment, but the pods belong to a ReplicaSet that the Deployment made. So <code>kubectl get pods api<\/code> finds nothing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C1: create and scale a Deployment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The task: a Deployment <code>api<\/code>, with <code>nginx:1.27<\/code>, 3 replicas and port 80. Then scale it to 5.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cleanup first<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl delete -f 04-rs-broken.yaml<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This deletes <code>rs-broken<\/code> from Part 3, and its pods with it. Why? It selects <code>app=api<\/code>, and so does the new Deployment. The two controllers wouldn&#8217;t steal each other&#8217;s pods (a pod that already has a controller can&#8217;t be adopted). But anything that reads by label would see both sets: <code>kubectl get pods -l app=api<\/code>, and later a Service, which would send traffic to the old pods too.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>delete -f<\/code> removes the objects the file describes. The file itself stays in the repo.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The skeleton<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl create deploy api --image=nginx:1.27 --replicas=3 --port=80 --dry-run=client -o yaml &gt; 06-api-deploy.yaml<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>create deploy<\/code> makes a Deployment (<code>kubectl run<\/code> only makes pods). It puts the label <code>app: api<\/code> in three places for you: the Deployment&#8217;s metadata, the selector, and the template.<\/li>\n\n\n\n<li>The container is named after the image (<code>nginx<\/code>), not after the Deployment.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The file<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: api\n  labels:\n    app: api\nspec:\n  replicas: 5\n  selector:\n    matchLabels:\n      app: api\n  template:\n    metadata:\n      labels:\n        app: api\n    spec:\n      containers:\n      - name: nginx\n        image: nginx:1.27\n        ports:\n        - containerPort: 80<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>metadata.labels<\/code> are labels on the Deployment object itself. They only help you find the Deployment. Which pods it manages is the selector&#8217;s job.<\/li>\n\n\n\n<li><code>replicas<\/code> started at 3, then went to 5. The Deployment passes this number on to its current ReplicaSet.<\/li>\n\n\n\n<li>The selector is required and immutable, like the ReplicaSet&#8217;s in Part 3. The Deployment uses it to find its ReplicaSets.<\/li>\n\n\n\n<li>Any change under <code>template:<\/code> makes a new ReplicaSet. That&#8217;s how a Deployment rolls out a change. Changing replicas doesn&#8217;t touch the template, so scaling reused the same ReplicaSet.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I removed the dry-run noise: <code>creationTimestamp: null<\/code>, <code>strategy: {}<\/code>, <code>resources: {}<\/code>, <code>status: {}<\/code>. <code>strategy<\/code> defaults to RollingUpdate.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Waiting and checking<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl apply -f 06-api-deploy.yaml\nkubectl rollout status deploy\/api\nkubectl get deploy,rs,pods -l app=api --show-labels<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>rollout status<\/code> waits until every replica is updated and available, then prints <code>successfully rolled out<\/code>. It exits non-zero on failure, so it works in scripts and CI. Better than running <code>get<\/code> again and again.<\/li>\n\n\n\n<li>One <code>get<\/code> for three types. <code>-l app=api<\/code> applies to all of them.<\/li>\n\n\n\n<li><code>READY 5\/5<\/code> is ready pods over desired. <code>UP-TO-DATE<\/code> is pods running the current template. <code>AVAILABLE<\/code> is pods that have been Ready for at least <code>minReadySeconds<\/code> (0 by default).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The pod-template-hash label<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The ReplicaSet is called <code>api-7579bcc6c4<\/code>. That suffix is the pod-template-hash: a hash of the pod template. The Deployment adds it as a label to the ReplicaSet and its pods, and to the ReplicaSet&#8217;s selector. So when a template change makes a second ReplicaSet, the two never overlap, even though both have <code>app=api<\/code>. It&#8217;s the built-in fix for the overlap problem I avoided by deleting <code>rs-broken<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pod names follow the chain: <code>&lt;deployment&gt;-&lt;template-hash&gt;-&lt;random&gt;<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Two mistakes<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I scaled to 6, not 5. <code>get deploy<\/code> showed 6\/6. I fixed the file and applied again. This is my third &#8220;right command, wrong value&#8221; mistake in this lab, after the image tags in <a href=\"https:\/\/rezachegini.com\/?p=377\">Part 2<\/a>. The habit I need: re-read the task after each scenario, and compare every number, name and tag.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>kubectl get pods api<\/code> gave NotFound. <code>api<\/code> is the Deployment, not a pod. Its pods are <code>api-&lt;hash&gt;-&lt;random&gt;<\/code>. Use <code>kubectl get pods -l app=api<\/code> or <code>kubectl get deploy api<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>NAME   READY   UP-TO-DATE   AVAILABLE   AGE\napi    5\/5     5            5           3m43s\n\nNAME                  DESIRED   CURRENT   READY   AGE\napi-7579bcc6c4        5         5         5       3m45s<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Five replicas, from one ReplicaSet, because scaling doesn&#8217;t make a new one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C2: follow the ownership chain<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The task: find the ReplicaSet owned by <code>api<\/code>, and one pod owned by that ReplicaSet. Write both names to <code>\/opt\/ckad\/00\/chain.txt<\/code>. Not by reading names, but through <code>metadata.ownerReferences<\/code>, the field that records &#8220;who controls me&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">First, the whole chain as a table<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get rs -o custom-columns=RS:.metadata.name,OWNER_KIND:.metadata.ownerReferences[0].kind,OWNER:.metadata.ownerReferences[0].name\nkubectl get pods -o custom-columns=POD:.metadata.name,OWNER_KIND:.metadata.ownerReferences[0].kind,OWNER:.metadata.ownerReferences[0].name<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>ownerReferences<\/code> is a list. An object can have several owners, but only one with <code>controller: true<\/code>. <code>[0]<\/code> is the controller for everything in this lab.<\/li>\n\n\n\n<li><code>.kind<\/code> and <code>.name<\/code> are the owner&#8217;s type and name. There&#8217;s also <code>.uid<\/code>, which is what Kubernetes actually matches on. Names can be reused after a delete. UIDs never are.<\/li>\n\n\n\n<li>The <code>api-*<\/code> pods show ReplicaSet \/ <code>api-7579bcc6c4<\/code>. My bare pods from Parts 1 and 2 (<code>broken<\/code>, <code>printer<\/code>, <code>sleeper<\/code>, <code>web<\/code>) show <code>&lt;none&gt;<\/code>. Nothing recreates them if they&#8217;re deleted.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">The typo that looked like an answer<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">My first try showed <code>&lt;none&gt;<\/code> for every row, including the pods I knew had an owner. I had typed <code>.metadata.ownerReference[0]<\/code>, without the s. That field doesn&#8217;t exist, and <code>custom-columns<\/code> doesn&#8217;t complain. It just prints <code>&lt;none&gt;<\/code>, which looks exactly like &#8220;this object has no owner&#8221;.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the fourth problem in this lab with the same root: <code>jsonpath<\/code> and <code>custom-columns<\/code> don&#8217;t validate field names. A wrong path prints blank or <code>&lt;none&gt;<\/code>. My rule now: if the output is empty or <code>&lt;none&gt;<\/code> and I didn&#8217;t expect that, I check the path with <code>kubectl explain pod.metadata.ownerReferences<\/code> before I believe it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finding the ReplicaSet with a filter<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>RS=$(kubectl get rs -o jsonpath='{.items[?(@.metadata.ownerReferences[0].name==\"api\")].metadata.name}')<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>.items<\/code>, because <code>get rs<\/code> without a name returns a List (the lesson from Part 1).<\/li>\n\n\n\n<li><code>[?( ... )]<\/code> is a filter: keep only the items where the condition is true.<\/li>\n\n\n\n<li><code>@<\/code> is the current item while the filter loops.<\/li>\n\n\n\n<li><code>.metadata.name<\/code> after the filter gives the names of the items that matched. Result: <code>api-7579bcc6c4<\/code>.<\/li>\n\n\n\n<li>A weak spot: it matches on the owner&#8217;s name only, not its kind. Good enough here, and the check at the end confirms the kind.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Finding a pod with a filter<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>POD=$(kubectl get pods -o jsonpath=\"{.items[?(@.metadata.ownerReferences[0].name==\\\"$RS\\\")].metadata.name}\" | awk '{print $1}')<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Double quotes outside this time, so bash puts in <code>$RS<\/code> before kubectl sees the expression. Inside, a literal <code>\"<\/code> must be written <code>\\\"<\/code>.<\/li>\n\n\n\n<li>The filter matches all 5 pods, printed on one line. <code>awk '{print $1}'<\/code> keeps the first one: <code>api-7579bcc6c4-2ttzr<\/code>.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Writing the answer, and checking it from the other side<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>echo -e \"$RS\\n$POD\" &gt; \/opt\/ckad\/00\/chain.txt\nkubectl get pod \"$POD\" -o jsonpath='{.metadata.ownerReferences[0].kind}\/{.metadata.ownerReferences[0].name}{\"\\n\"}'<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-e<\/code> makes echo turn <code>\\n<\/code> into a real newline, so the file has two lines.<\/li>\n\n\n\n<li>The check reads the pod&#8217;s owner directly: <code>ReplicaSet\/api-7579bcc6c4<\/code>. That matches line 1 of the file.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I used shell variables instead of one long command, so I could check each piece with <code>echo<\/code> before the next step used it. Slower than a one-liner, but each step is verified.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C4: delete a pod, then delete the ReplicaSet<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The task: test self-healing at two levels of the chain. After C3, the current ReplicaSet is <code>api-7d54f6c494<\/code>, still with 5 pods.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Level 1: delete a pod<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl delete pod api-7d54f6c494-2hpff<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The pod&#8217;s owner still exists, and still wants 5. The ReplicaSet counts 4, and creates one from its template: <code>api-7d54f6c494-hng7s<\/code>, AGE 3s.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s a <strong>new<\/strong> pod, with a new name and a new IP. Not the old one coming back. The other 4 pods kept serving the whole time, so there was no downtime.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Level 2: delete the ReplicaSet<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">First I saved its UID:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>RS=api-7d54f6c494\nkubectl get rs $RS -o jsonpath='{.metadata.uid}{\"\\n\"}'<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The API server gives every object a unique ID when it&#8217;s created, and never reuses it. Names can repeat after a delete. UIDs can&#8217;t. That makes the UID the only reliable way to tell &#8220;the same object&#8221; from &#8220;a new object with the same name&#8221;. Before: <code>d1fd3f3a-ca8c-4c39-9e63-064f5a22a471<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl delete rs $RS\nkubectl rollout status deployment\/api<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">What happened, in order:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The ReplicaSet is deleted. By default this is a background cascading delete: the owner goes first, then the garbage collector deletes everything whose <code>ownerReferences<\/code> point at the old UID. That&#8217;s all 5 pods.<\/li>\n\n\n\n<li>The Deployment notices it has no ReplicaSet for its current template.<\/li>\n\n\n\n<li>It hashes the template: <code>7d54f6c494<\/code>, the same as before, because the template didn&#8217;t change. So the new ReplicaSet gets the same name.<\/li>\n\n\n\n<li>The new ReplicaSet creates 5 new pods.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">The UID after: <code>92db45f2-d624-450a-80c2-a020ba75a3f4<\/code>. Different. A new object with the old name.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is the confusing part. The ReplicaSet &#8220;came back&#8221; with an identical name, so it looks as if the delete did nothing. Only the UID and the AGE (27 seconds) show it&#8217;s new. That&#8217;s why I recorded the UID before and after: the name alone can&#8217;t prove anything.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And unlike level 1, all 5 pods were gone at the same moment. That&#8217;s downtime.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I predicted all of this before running it: same name, new UID, 5 new pods. All confirmed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Deployment rebuilds the current template<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">After C3, there were three older ReplicaSets at 0 replicas: <code>7579bcc6c4<\/code>, <code>5bdd66b8cc<\/code> and <code>7f4887bdf6<\/code>. The Deployment ignored them. It rebuilt the current template, not an old revision. Going back to an old one takes an explicit <code>kubectl rollout undo<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Who heals what<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Delete a pod: its ReplicaSet creates 1 replacement. No downtime.<\/li>\n\n\n\n<li>Delete the current ReplicaSet: garbage collection removes all its pods, and the Deployment makes a new ReplicaSet with all new pods. Downtime.<\/li>\n\n\n\n<li>Delete the Deployment: garbage collection removes its ReplicaSets, then their pods. Gone for good.<\/li>\n\n\n\n<li>Delete a bare pod (like <code>web<\/code> from <a href=\"https:\/\/rezachegini.com\/?p=372\">Part 1<\/a>): nobody notices. It stays deleted.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Three ways to cascade<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>--cascade=background<\/code> (the default): the owner first, then the garbage collector removes what it owned.<\/li>\n\n\n\n<li><code>--cascade=foreground<\/code>: the owned objects first, then the owner.<\/li>\n\n\n\n<li><code>--cascade=orphan<\/code>: delete only the owner. The owned objects keep running, with no owner.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">With <code>orphan<\/code>, the 5 pods would have survived. The Deployment&#8217;s new ReplicaSet would then have adopted them, like the stray pod in Part 3, with no downtime at all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The answer file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1. Deleting a pod: the ReplicaSet saw 4 of 5 pods and created a replacement right away (new pod name, same ReplicaSet).\n2. Deleting the ReplicaSet: its pods were garbage-collected, and the Deployment created a new ReplicaSet (same template hash name, new UID) with 5 new pods.<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">C5: a Deployment from a broken file<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The task: a Deployment manifest called <code>shop<\/code> with two bugs. Fix it and get 2 pods running.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Bug 1: <code>kind: deployment<\/code>, in lowercase.<\/li>\n\n\n\n<li>Bug 2: no <code>spec.selector<\/code>.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The interesting part: the two bugs are caught by different checks, and you only see one error at a time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bug 1: the lowercase kind<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><code>kind<\/code> must match the registered type name exactly, including case. To see the real error, I tested the lowercase version on its own, with a server-side dry run (nothing gets created):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Error from server (BadRequest): error when creating \"STDIN\": deployment in version \"v1\" cannot be handled as a Deployment: no kind \"deployment\" is registered for version \"apps\/v1\" in scheme \"k8s.io\/apimachinery@v1.37.2-k3s1\/...\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">How to read it:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>Error from server (BadRequest)<\/code>: kubectl accepted <code>deployment<\/code>. Its lookup ignores case, just to find the right URL. So it sent the request, and the server rejected it.<\/li>\n\n\n\n<li><code>cannot be handled as a Deployment<\/code>: the server knew which resource it was, from the URL&#8230;<\/li>\n\n\n\n<li><code>no kind \"deployment\" is registered<\/code>: &#8230;but the <code>kind<\/code> field in the body doesn&#8217;t match any registered name, and that check is case-sensitive.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">I had predicted a different error: a client-side resource mapping not found &#8230; no matches for kind. That&#8217;s what many guides show, from older kubectl versions or for kinds that don&#8217;t exist at all. On this cluster (K3s, v1.37), it reaches the server. The outcome is the same, rejected, but the message is different. That&#8217;s why I test instead of trusting my prediction.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One honest detail: during the real task, I never saw this error. My first apply went straight to the selector error. That means I had already typed <code>kind: Deployment<\/code> correctly while writing the file. The separate test is what showed me the real message.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Bug 2: the missing selector<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>The Deployment \"shop\" is invalid:\n* spec.selector: Required value\n* spec.template.metadata.labels: Invalid value: {\"app\":\"shop\"}: `selector` does not match template `labels`<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is a validation error (<code>is invalid<\/code>). So the server decoded the object fine, meaning the kind was correct, and then checked its fields.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Two lines, but <strong>one cause<\/strong>. With no selector, nothing can match the labels, so the second line follows from the first. When several validation errors appear, look for the one the others depend on.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>spec.selector<\/code> is required in <code>apps\/v1<\/code>. Older API versions (<code>extensions\/v1beta1<\/code>) filled it in from the template labels, which is why old tutorials leave it out. The fix:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>spec:\n  replicas: 2\n  selector:\n    matchLabels:\n      app: shop\n  template:\n    metadata:\n      labels:\n        app: shop\n    spec:\n      containers:\n      - name: shop\n        image: nginx:1.27<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The selector is immutable, so it has to be right on the first successful apply. And <code>app: shop<\/code> matters later in the lab, when a broken Service tries to select it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>deployment.apps\/shop created\ndeployment \"shop\" successfully rolled out\n\nNAME   READY   UP-TO-DATE   AVAILABLE   AGE\nshop   2\/2     2            2           24s<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Which layer catches which error<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A manifest goes through several checks, in order. Each one stops at the first failure, so you fix, apply again, and read the next error:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>kubectl<\/code> parses the YAML: bad indentation or tabs. <code>error converting YAML to JSON<\/code>.<\/li>\n\n\n\n<li><code>kubectl<\/code> maps the resource: an unknown <code>apiVersion<\/code>, or a kind that doesn&#8217;t exist. <code>no matches for kind<\/code>.<\/li>\n\n\n\n<li>The server decodes the body: a kind with the wrong case. <code>BadRequest ... no kind \"x\" is registered<\/code>.<\/li>\n\n\n\n<li>The server validates the fields: missing or invalid fields. <code>is invalid: * spec.x: ....<\/code><\/li>\n\n\n\n<li>The cluster runs it: a bad image or a crash. You see it in the pod status, like the broken pod in Part 2.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">To check a file without creating anything: <code>kubectl apply --dry-run=server -f file.yaml<\/code>. It runs every server check and stores nothing. <code>--dry-run=client<\/code> only checks what kubectl can check locally, so it would miss the case problem, and possibly the missing selector.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What I learned<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Deployment owns ReplicaSets, and ReplicaSets own pods. You create the top, and the pods are named <code>&lt;deployment&gt;-&lt;template-hash&gt;-&lt;random&gt;<\/code>.<\/li>\n\n\n\n<li><code>replicas<\/code> scales the current ReplicaSet. A template change makes a new one. The pod-template-hash label keeps them from overlapping.<\/li>\n\n\n\n<li><code>rollout status<\/code> waits for a Deployment, and fails loudly if it doesn&#8217;t finish.<\/li>\n\n\n\n<li><code>ownerReferences<\/code> is the real chain, and jsonpath filters (<code>[?(@.x==\"y\")]<\/code>) can follow it.<\/li>\n\n\n\n<li>A wrong field name prints <code>&lt;none&gt;<\/code>, not an error. Check the path with <code>kubectl explain<\/code> before you believe empty output.<\/li>\n\n\n\n<li>Names can repeat. UIDs can&#8217;t. A ReplicaSet that comes back with the same name is still a new object.<\/li>\n\n\n\n<li>Each level heals the level below. Deleting a pod costs nothing. Deleting the current ReplicaSet takes every pod down at once.<\/li>\n\n\n\n<li>Manifest errors come one layer at a time. Fix, apply again, read the next one. <code>--dry-run=server<\/code> runs every server check without creating anything.<\/li>\n\n\n\n<li>Re-read the task. Right command, wrong number (6 instead of 5) is still a wrong answer.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What is next<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Next in the lab: more about labels and selectors, and then Services, the stable name and IP in front of pods that keep changing. The shop Deployment from C5 is waiting there for a broken Service<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Where we are Hi, I&#8217;m Reza. I&#8217;m sharing my preparation for the CKAD exam, practiced on a K3s cluster in my home&hellip;<\/p>\n","protected":false},"author":2,"featured_media":384,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_rezaops_part":"4","_rezaops_linkedin_url":"https:\/\/www.linkedin.com\/pulse\/ckad-prep-part-4-who-owns-pod-reza-chegini-jfgpe\/","footnotes":""},"categories":[10,62,9,74],"tags":[224,228,68,5,3,227,6],"series":[226],"class_list":["post-386","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-home-lab","category-kubernetes","category-linux","tag-ckad","tag-deployment","tag-k3s","tag-kubectl","tag-kubernetes","tag-replicaset","tag-yaml","series-ckad-prep"],"jetpack_featured_media_url":"https:\/\/rezachegini.com\/wp-content\/uploads\/2026\/12\/ckad-prep-part-4-cover.png","_links":{"self":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/386","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=386"}],"version-history":[{"count":1,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/386\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/posts\/386\/revisions\/387"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=\/wp\/v2\/media\/384"}],"wp:attachment":[{"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=386"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=386"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=386"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/rezachegini.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=386"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}