Skip to content

K8S Workloads

← Back to all decks

84 cards — 🟢 19 easy | 🟔 39 medium | šŸ”“ 20 hard

🟢 Easy (19)

1. What are Daemon sets?

Show answer A DaemonSet is a set of pods that runs only once on a host. They are used for host layer attributes like a network or for monitoring a network, which you may not need to run on a host more than once. DaemonSets ensure that all (or some) nodes run a copy of a pod.

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

2. How to check which container image was used as part of replica set called "repli"?

Show answer `kubectl describe rs repli | grep -i image` shows the container image used by the ReplicaSet. You can also use `kubectl get rs repli -o jsonpath='{.spec.template.spec.containers[*].image}'` for a clean output.
Gotcha: always use specific image tags (nginx:1.25.3) in production — the 'latest' tag is mutable and can change unexpectedly.

3. What is the purpose of Horizontal Pod Autoscaling in Kubernetes?

Show answer **Horizontal Pod Autoscaling (HPA):**
* Automatically adjusts the number of pod replicas based on observed metrics, such as CPU utilization or custom metrics.
* Ensures optimal resource utilization and responsiveness.
* Helps maintain a balance between application performance and resource efficiency.
* HPA allows Kubernetes to dynamically scale the number of pod replicas in response to changing demand. By automatically adjusting the replica count based on specified metrics, * HPA ensures that applications can efficiently handle varying workloads without manual intervention.

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

4. How to delete a replica set called "rori"?

Show answer `kubectl delete rs rori` removes the ReplicaSet and all pods it manages. The workload hierarchy is: Deployment -> ReplicaSet -> Pod.
Gotcha: if the ReplicaSet was created by a Deployment, the Deployment will immediately recreate it. Delete the parent Deployment instead to fully remove the workload.

5. What is the difference between a Job and a CronJob in Kubernetes?

Show answer * Job: A Job in Kubernetes runs a pod to completion and then terminates.
* It is used for short-lived, batch-style processes, ensuring that the task is executed once successfully.
* CronJob: A CronJob is a higher-level abstraction that schedules jobs at specified intervals using cron expressions.
* It is suitable for recurring, automated tasks that need to run periodically.
* While Jobs are designed for one-time execution of tasks, CronJobs provide a scheduling mechanism for recurring tasks.

Remember: CronJob = Job on schedule. Fields: minute hour day month weekday. "MHDMW."

Gotcha: `concurrencyPolicy: Forbid` prevents overlap. Default allows multiple Jobs.

6. What is the difference between Pod, Container, and Deployment?

Show answer Different abstraction levels:

**Container**: The actual running process - your application. Docker/containerd runs it.

**Pod**: The scheduling unit in Kubernetes. Contains one or more containers that:
* Share network namespace (same IP, localhost works)
* Share storage volumes
* Are scheduled together on same node
* Live and die together

**Deployment**: Manages ReplicaSets which manage Pods.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

7. What is a "ReplicaSet"?

Show answer A ReplicaSet ensures a specified number of identical pod replicas are running at all times. If a pod crashes or is deleted, the ReplicaSet controller creates a replacement to maintain the desired count.
Best practice: don't create ReplicaSets directly — use Deployments, which manage ReplicaSets and add rolling update and rollback capabilities.

8. How to delete a deployment?

Show answer One way is by specifying the deployment name: `kubectl delete deployment [deployment_name]`

Another way is using the deployment configuration file: `kubectl delete -f deployment.yaml`

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

9. True or False? Deleting a ReplicaSet will delete the Pods it created

Show answer True (and not only the Pods but anything else it created).

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

10. True or False? In case of a ReplicaSet, if Pods specified in the selector field don't exists, the ReplicaSet will wait for them to run before doing anything

Show answer False. A ReplicaSet actively creates pods to match its desired replica count — it does not wait for pods to appear on their own. If the selector matches existing pods, they count toward the desired number. If not enough exist, the ReplicaSet creates new ones immediately. This is the core reconciliation loop of Kubernetes controllers.

11. What is a StatefulSet in Kubernetes?

Show answer A StatefulSet is a workload API object for managing stateful applications. It ensures that each pod has a unique, stable identity (hostname) and persistent storage across rescheduling. Use StatefulSets for applications like databases where ordering and stable network ID matters.

Remember: StatefulSet = stable identity: pod-0/pod-1, stable storage, ordered operations.

Gotcha: Deleting StatefulSet does NOT delete PVCs. By design for data safety.

12. What is the job of the kube-scheduler?

Show answer The kube-scheduler assigns nodes to newly created pods. It watches for newly created pods that have no node assigned, and selects a node for them to run on based on resource requirements, hardware/software/policy constraints, affinity and anti-affinity specifications, data locality, and workload interference.

Remember: Job = run-to-completion. Tracks successful completions. "One-time task."

Example: `kubectl create job db-migrate --image=myapp -- python manage.py migrate`

13. How to list all daemonsets in the current namespace?

Show answer `kubectl get ds`

Remember: DaemonSet = one pod per node. For: log collectors, monitoring, network plugins.

Gotcha: DaemonSets use node affinity to ensure one copy per eligible node.

14. What is the purpose of ReplicaSet?

Show answer [kubernetes.io](https://kubernetes.io/docs/concepts/workloads/controllers/replicaset): "A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time. As such, it is often used to guarantee the availability of a specified number of identical Pods."

In simpler words, a ReplicaSet will ensure the specified number of Pods replicas is running for a selected Pod. If there are more Pods than defined in the ReplicaSet, some will be removed. If there are less than what is defined in the ReplicaSet then, then more replicas will be added.

15. How to list ReplicaSets in the current namespace?

Show answer `kubectl get rs` lists all ReplicaSets in the current namespace showing NAME, DESIRED, CURRENT, and READY counts. Add `-o wide` to see container images and selectors. In practice, you rarely interact with ReplicaSets directly — Deployments create and manage them automatically during rollouts and rollbacks.

16. What is a "Deployment" in Kubernetes?

Show answer AĀ Kubernetes DeploymentĀ is used to tellĀ KubernetesĀ how to create or modify instances of the pods that hold a containerized application.
DeploymentsĀ can scale the number of replica pods, enable rollout of updated code in a controlled manner, or roll back to an earlierĀ deploymentĀ version if necessary.

A Deployment is a declarative statement for the desired state for Pods and Replica Sets.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

17. How to check how many Pods are ready as part of a replica set called "repli"?

Show answer `k describe rs repli | grep -i "Pods Status"`

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

18. What is a "Deployment"?

Show answer An object that manages multiple replicas of pods.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

19. True or False? The same as there are "Static Pods" there are other static resources like "deployments" and "replicasets"

Show answer False. Static Pods are unique — they are managed directly by the kubelet on a specific node, not by the API server. Deployments, ReplicaSets, and other workloads are API-managed resources with no 'static' equivalent.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

🟔 Medium (39)

1. What's the difference between a Deployment and a StatefulSet?

Show answer Deployment: suited for stateless pods, pods are interchangeable and get recreated at will. StatefulSet: suited for stateful pods, each pod gets a persistent identity (name, storage) and ordering guarantees (e.g., only one pod starts at a time) – use it when each instance needs stable identity or storage (like databases).

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

2. Explain what is CronJob and what is it used for

Show answer A CronJob creates Jobs on a repeating schedule. One CronJob object is like one line of a crontab (cron table) file. It runs a job periodically on a given schedule, written in Cron format.

Remember: CronJob = Job on schedule. Fields: minute hour day month weekday. "MHDMW."

Gotcha: `concurrencyPolicy: Forbid` prevents overlap. Default allows multiple Jobs.

3. Create a deployment called "pluck" using the image "redis" and make sure it runs 5 replicas

Show answer `kubectl create deployment pluck --image=redis`

`kubectl scale deployment pluck --replicas=5`

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

4. Deploy a pod called "my-pod" using the nginx:alpine image

Show answer `kubectl run my-pod --image=nginx:alpine`

If you are a Kubernetes beginner you should know that this is not a common way to run Pods. The common way is to run a Deployment which in turn runs Pod(s).

In addition, Pods and/or Deployments are usually defined in files rather than executed directly using only the CLI arguments.

Remember: Use specific tags (:1.25.3), never :latest in prod. Latest is mutable.

5. How to scale a deployment to 8 replicas?

Show answer `kubectl scale deploy --replicas=8` sets the desired replica count to
8. Kubernetes gradually creates new pods to match the target. For auto-scaling, use HorizontalPodAutoscaler: `kubectl autoscale deployment --min=2 --max=10 --cpu-percent=80`.
Gotcha: manual scaling is overridden if HPA is active on the same deployment.

6. In case of a ReplicaSet, Which field is mandatory in the spec section?

Show answer The field `template` in spec section is mandatory. It's used by the ReplicaSet to create new Pods when needed.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

7. What the following block of lines does?

Show answer It defines a replicaset for Pods whose type is set to "backend" so at any given point of time there will be 2 concurrent Pods running.

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

8. What is the difference between a Pod and a Deployment in Kubernetes?

Show answer A Pod is the smallest deployable unit in Kubernetes - it represents one or more
containers that share storage and network resources.

A Deployment is a higher-level controller that manages Pods:
- Ensures desired number of Pod replicas are running
- Handles rolling updates and rollbacks
- Provides declarative updates for Pods and ReplicaSets
- Self-healing: recreates Pods if they fail

Key differences:
- Pod: Single instance, no auto-recovery if deleted
- Deployment: Manages multiple Pod replicas, auto-recovers failures

You rarely create Pods directly in production.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

9. What is a Kubernetes StatefulSet and when would you use it?

Show answer StatefulSet is the workload API object used to manage stateful applications. Manages the deployment and scaling of a set of Pods, and provides guarantees about the ordering and uniqueness of these Pods.[Learn more](https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/)

Remember: StatefulSet = stable identity: pod-0/pod-1, stable storage, ordered operations.

Gotcha: Deleting StatefulSet does NOT delete PVCs. By design for data safety.

10. How does a Kubernetes DaemonSet work and ensure one pod per node?

Show answer Historically, up 1.12, it was done with NodeName attribute.

Starting 1.12, it's achieved with regular scheduler and node affinity.

Remember: DaemonSet = one pod per node. For: log collectors, monitoring, network plugins.

Gotcha: DaemonSets use node affinity to ensure one copy per eligible node.

11. ReplicaSets are running the moment the user executed the command to create them (like kubectl create -f rs.yaml)

Show answer False. It can take some time, depends on what exactly you are running. To see if they are up and running, run `kubectl get rs` and watch the 'READY' column.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

12. Create a file definition/manifest of a deployment called "dep", with 3 replicas that uses the image 'redis'

Show answer `k create deploy dep -o yaml --image=redis --dry-run=client --replicas 3 > deployment.yaml `

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

13. How do you scale a Deployment in Kubernetes?

Show answer You can use kubectl scale deployment/ --replicas=N to adjust the number of replicas, or update the replicas field in the Deployment manifest and apply it. The Deployment's ReplicaSet will then add or remove pods to match the desired count.

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

14. What the following in a Deployment configuration file means?

Show answer USER_PASSWORD environment variable will store the value from password key in the secret called "some-secret"
In other words, you reference a value from a Kubernetes Secret.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

15. How to scale an application (deployment) so it runs more than one instance of the application?

Show answer To run two instances of the application:

`kubectl scale deployment --replicas=2`

You can specify any other number, given that your application knows how to scale.

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

16. How Service and Deployment are connected?

Show answer The truth is they aren't connected. Service points to Pod(s) directly, without connecting to the Deployment in any way.

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

17. Explain Canary deployments/rollouts in detail

Show answer Canary deployment steps:

1. Traffic coming from users through a load balancer to the application which is currently version 1

Users -> Load Balancer -> App Version 1

2. A new application version 2 is deployed (while version 1 still running) and part of the traffic is redirected to the new version

Users -> Load Balancer ->(95% of the traffic) App Version 1
->(5% of the traffic) App Version 2

3.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

18. Delete the deployment depdep

Show answer `kubectl delete deploy depdep` removes the Deployment and its managed ReplicaSets and Pods. This is the clean way to remove a workload — deleting individual pods or ReplicaSets will just cause the Deployment to recreate them. Add `--grace-period=0 --force` for immediate deletion, but only in dev environments.

19. What is the difference between a StatefulSet and a Deployment in Kubernetes?

Show answer **Deployment:**
• Used for stateless applications.
• Provides a way to manage and scale replica sets.
• Pods created by a deployment are not uniquely identified.
• Suitable for applications that can be easily replicated and scaled horizontally.
**StatefulSet:**
• Designed for stateful applications with unique network identities and stable hostnames.
• Maintains a unique identifier for each pod, allowing for ordered scaling and predictable naming.
• Suitable for applications that require stable network identities and persistent storage.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

20. How to verify a deployment was created?

Show answer `kubectl get deployments` or `kubectl get deploy`

This command lists all the Deployment objects created and exist in the cluster. It doesn't mean the deployments are ready and running. This can be checked with the "READY" and "AVAILABLE" columns.

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

21. What's the difference between a ReplicaSet and DaemonSet?

Show answer A ReplicaSet's purpose is to maintain a stable set of replica Pods running at any given time.
A DaemonSet ensures that all Nodes run a copy of a Pod.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

22. What is a Kubernetes DaemonSet and when would you use it?

Show answer [Kubernetes.io](https://kubernetes.io/docs/concepts/workloads/controllers/daemonset): "A DaemonSet ensures that all (or some) Nodes run a copy of a Pod. As nodes are added to the cluster, Pods are added to them. As nodes are removed from the cluster, those Pods are garbage collected. Deleting a DaemonSet will clean up the Pods it created."

Remember: DaemonSet = one pod per node. For: log collectors, monitoring, network plugins.

Gotcha: DaemonSets use node affinity to ensure one copy per eligible node.

23. What ways are you familiar with to implement deployment strategies (like canary, blue/green) in Kubernetes?

Show answer There are multiple ways. One of them is Argo Rollouts.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

24. Scale up a replica set called "rori" to run 5 Pods instead of 2

Show answer `kubectl scale rs rori --replicas=5` increases the ReplicaSet to 5 pods. Kubernetes creates 3 new pods to reach the target. For production, prefer scaling through Deployments (`kubectl scale deploy`) or HPA for automatic scaling based on CPU/memory metrics.
Gotcha: scaling a ReplicaSet directly may conflict with its parent Deployment's desired state.

25. Is it possible to delete ReplicaSet without deleting the Pods it created?

Show answer Yes, with `kubectl delete rs rori --cascade=orphan` (or the older `--cascade=false`). This removes the ReplicaSet object but leaves its pods running as orphans without a controller. Useful when you want to adopt pods under a new controller.
Gotcha: orphaned pods will not be recreated if they crash — they lose their self-healing capability.

26. Explain "Horizontal Pod Autoscaler"

Show answer In Kubernetes, a HorizontalPodAutoscaler automatically updates a workload resource with the aim of automatically scaling the workload to match demand.

Example: Manual: `kubectl scale deploy web --replicas=5`. Auto: HPA with --cpu-percent.

27. What are some use cases for using a DaemonSet?

Show answer * Monitoring: You would like to perform monitoring on every node part of cluster. For example datadog pod runs on every node using a daemonset
* Logging: You would like to having logging set up on every node part of your cluster
* Networking: there is networking component you need on every node for all nodes to communicate between them

Remember: DaemonSet = one pod per node. For: log collectors, monitoring, network plugins.

Gotcha: DaemonSets use node affinity to ensure one copy per eligible node.

28. Scale down a replica set called "rori" to run 1 Pod instead of 5

Show answer `kubectl scale rs rori --replicas=1` reduces the ReplicaSet from 5 to 1 pod. Kubernetes terminates 4 pods, respecting terminationGracePeriodSeconds (default 30s) to allow graceful shutdown.
Gotcha: if pods have preStop hooks or need to drain connections, ensure the grace period is long enough to avoid dropped requests.

29. What will happen when a Pod, created by ReplicaSet, is deleted directly with kubectl delete po ...?

Show answer The ReplicaSet will create a new Pod in order to reach the desired number of replicas.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

30. True or False? If a ReplicaSet defines 2 replicas but there 3 Pods running matching the ReplicaSet selector, it will do nothing

Show answer False. It will terminate one of the Pods to reach the desired state of 2 replicas.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

31. You've created a ReplicaSet, how to check whether the ReplicaSet found matching Pods or it created new Pods?

Show answer `kubectl describe rs `

It will be visible under `Events` (the very last lines)

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

32. True or False? Removing the label from a Pod that is tracked by a ReplicaSet, will cause the ReplicaSet to create a new Pod

Show answer True. When the label, used by a ReplicaSet in the selector field, removed from a Pod, that Pod no longer controlled by the ReplicaSet and the ReplicaSet will create a new Pod to compensate for the one it "lost".

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

33. How to modify a replica set called "rori" to use a different image?

Show answer `kubectl edit rs rori` opens the ReplicaSet manifest in your default editor. Change the container image under spec.template.spec.containers[].image.
Gotcha: editing the ReplicaSet template does not automatically restart existing pods — you must delete old pods manually for the new image to take effect. Use Deployments for automatic rolling updates.

34. What is the difference between a replica set and a replication controller?

Show answer A Replication Controller (RC) is a wrapper on a pod. This provides additional functionality to the pods, which offers replicas. It monitors the pods and automatically restarts them if they fail. If the node fails, this controller will respawn all the pods of that node on another node. If the pods die, they won't be spawned again unless wrapped around a replica set.

Replica Set (RS) is the next-generation replication controller. This kind of support has some selector types and supports both equality-based and set-based selectors. It allows filtering by label values and keys.

35. True or False? Pods specified by the selector field of ReplicaSet must be created by the ReplicaSet itself

Show answer False. The Pods can be already running and initially they can be created by any object. It doesn't matter for the ReplicaSet and not a requirement for it to acquire and monitor them.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

36. How to edit a deployment?

Show answer `kubectl edit deployment ` opens the manifest in your editor for live editing. Changes to the pod template (image, env, resources) trigger an automatic rolling update. Alternative: `kubectl set image deployment/ container=image:tag` for quick image updates without opening an editor. Use `kubectl rollout status` to monitor the update progress.

37. How to execute a rollback?

Show answer For Helm: `helm rollback RELEASE_NAME REVISION_ID` reverts to a previous release revision. For Deployments: `kubectl rollout undo deployment/` reverts to the previous ReplicaSet, or `kubectl rollout undo deployment/ --to-revision=2` for a specific version. Check history first with `kubectl rollout history deployment/`.

38. How to create a deployment with the image "nginx:alpine"?

Show answer `kubectl create deployment my-first-deployment --image=nginx:alpine`

OR

```\ncat << EOF | kubectl create -f -\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: nginx\nspec:\n replicas: 1\n selector:\n matchLabels:\n app: nginx\n template:\n metadata:\n labels:\n app: nginx\n spec:\n containers:\n - name: nginx\n image: nginx:alpine\n```

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

39. You would like to limit the number of resources being used in your cluster. For example no more than 4 replicasets, 2 services, etc. How would you achieve that?

Show answer Use ResourceQuotas to limit the total number of objects and resource consumption per namespace.
Example: `kubectl create quota my-quota --hard=replicasets=4,services=2,pods=10` in a namespace. ResourceQuotas also limit total CPU/memory: `requests.cpu=4,limits.memory=8Gi`.
Gotcha: without LimitRange, users can still create pods without resource requests, so combine both.

šŸ”“ Hard (20)

1. How does Kubernetes handle rolling back a deployment?

Show answer * Rolling Back a Deployment: Kubernetes allows rolling back a deployment to a previous revision.
* Users can use the kubectl rollout undo command to revert to a previous version of the deployment.
* The rollout mechanism gradually replaces new pods with the older version, ensuring a controlled rollback.
* Rolling back a deployment in Kubernetes involves undoing a previous rollout. Kubernetes ensures a smooth transition by gradually replacing new pods with the older version, maintaining the availability of the application throughout the rollback process.

2. What possible issue can arise from using the following spec and how to fix it?

Show answer If the cron job fails, the next job will not replace the previous one due to the "concurrencyPolicy" value which is "Allow". It will keep spawning new jobs and so eventually the system will be filled with failed cron jobs.
To avoid such problem, the "concurrencyPolicy" value should be either "Replace" or "Forbid".

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

3. Fix the following ReplicaSet definition

Show answer The selector doesn't match the label (cache vs cachy). To solve it, fix cachy so it's cache instead.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

4. Discuss the implications of pod sprawl and how to manage it effectively in Kubernetes.

Show answer Implications of Pod Sprawl:
• Increased resource consumption.
• More complex cluster management.
• Potential impact on network performance.
Management Strategies:
• Implement resource quotas and limits.
• Use Horizontal Pod Autoscaling to adjust pod counts dynamically.
• Regularly review and decommission unused or redundant pods. projects/knowledge/interview/kubernetes/368-discuss-the-implications-of-pod-sprawl-and-how-to-.txt

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

5. Fix the following deployment manifest

Show answer Change `kind: Deploy` to `kind: Deployment`

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

6. How does Kubernetes handle rolling updates with zero downtime?

Show answer Rolling Updates with Zero Downtime:
* Kubernetes updates a Deployment by creating a new ReplicaSet alongside the existing one.
* New pods are gradually created and added to the new ReplicaSet, while old pods are gracefully terminated.
* This ensures a controlled transition without disrupting the availability of the application.
* During a rolling update, Kubernetes progressively replaces old pods with new ones, ensuring that there is always a sufficient number of healthy pods.

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

7. How do you define a Kubernetes Deployment?

Show answer A Kubernetes Deployment is a resource object used to declare the desired state for a set of pods. It provides declarative updates to applications, allowing users to describe how an application should run and scale over time. Deployments enable rolling updates, rollbacks, and scaling of applications without manual intervention.
Key elements of a Deployment include:
* Pod Template: Defines the desired state of the pods.
* Replica Count: Specifies the desired number of pod replicas.
* Update Strategy: Defines how updates should be applied (e.g., rolling updates).\

8. What issue might arise from using the following CronJob and how to fix it?

Show answer The following lines placed under the template:

```\nconcurrencyPolicy: Forbid\nsuccessfulJobsHistoryLimit: 1\nfailedJobsHistoryLimit: 1\n```

As a result this configuration isn't part of the cron job spec hence the cron job has no limits which can cause issues like OOM and potentially lead to API server being down.
To fix it, these lines should placed in the spec of the cron job, above or under the "schedule" directive in the above example.

Remember: CronJob = Job on schedule. Fields: minute hour day month weekday. "MHDMW."

Gotcha: `concurrencyPolicy: Forbid` prevents overlap. Default allows multiple Jobs.

9. Explain the differences between a DaemonSet and a Deployment in Kubernetes.

Show answer **Deployment:**
* Used for stateless applications.
* Manages the deployment and scaling of replicas across nodes.
* Suitable for applications that can be replicated and scaled horizontally.
**DaemonSet:**
* Ensures that a copy of a pod runs on all (or a subset of) nodes.
* Typically used for cluster-level services or agents.
* Ensures that specific pods are present on each node in the cluster.
* While Deployments are suitable for stateless applications that can be replicated, DaemonSets are designed for scenarios where at least one instance of a pod is required on each node.

10. What happens when you delete a deployment?

Show answer The pod related to the deployment will terminate and the replicaset will be removed.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

11. How does Kubernetes ensure high availability of applications?

Show answer Kubernetes ensures high availability through several mechanisms:
* ReplicaSets: Deployments in Kubernetes are often managed by ReplicaSets, which ensure a specified number of replicas (pod instances) are running at all times. If a pod or node fails, ReplicaSets automatically create replacements on healthy nodes.
* Pod Distribution: Kubernetes spreads pods across multiple nodes to avoid a single point of failure.

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

12. How does rolling deployment work in Kubernetes?

Show answer **Rolling Deployment:**
* Strategy for updating an application without downtime.
* Involves gradually replacing old pods with new ones.
* Ensures a smooth transition, as each new pod is ready before an old one is terminated.
**Deployment Update:** A new version of the application is deployed using a Deployment resource.
* ReplicaSet Transition: Kubernetes creates a new ReplicaSet for the updated version while maintaining the old one.
* Pod Replacement: Pods are gradually replaced by new ones, ensuring a controlled rollout.\

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

13. What are the challenges in managing stateful applications in Kubernetes?

Show answer * Challenges in Managing Stateful Applications: Persistent Storage: Ensuring data persistence and managing stateful data storage.
* Unique Network Identities: Assigning stable network identities to stateful pods.
* Orderly Scaling: Scaling stateful applications in a specific order to maintain relationships.
* Backup and Restore: Implementing robust backup and restore mechanisms for data.
* Stateful applications often have unique challenges compared to stateless ones, especially related to data persistence and maintaining stable identities.

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

14. Describe the sequence of events in case of creating a ReplicaSet

Show answer * The client (e.g. kubectl) sends a request to the API server to create a ReplicaSet
* The Controller detects there is a new event requesting for a ReplicaSet
* The controller creates new Pod definitions (the exact number depends on what is defined in the ReplicaSet definition)
* The scheduler detects unassigned Pods and decides to which nodes to assign the Pods.

Remember: Don't create ReplicaSets directly. Use Deployments for rolling updates+rollbacks.

15. Explain the considerations for deploying stateful applications in a Kubernetes cluster.

Show answer **Considerations for Stateful Applications:* •
• Use StatefulSets to ensure stable network identities for pods.
• Implement persistent volumes for data persistence.
• Consider ordering and coordination when scaling stateful applications.
• Configure affinity and anti-affinity rules for predictable pod placement. projects/knowledge/interview/kubernetes/367-explain-the-considerations-for-deploying-stateful-.txt

Remember: Workload hierarchy: Deployment/StatefulSet/DaemonSet→ReplicaSet→Pod.

Gotcha: Use `kubectl explain ` for field reference without leaving the CLI.

16. What rollout/deployment strategies are you familiar with?

Show answer * Blue/Green Deployments: You deploy a new version of your app, while old version still running, and you start redirecting traffic to the new version of the app
* Canary Deployments: You deploy a new version of your app and start redirecting **portion** of your users/traffic to the new version. So you the migration to the new version is much more gradual

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

17. Explain Blue/Green deployments/rollouts in detail

Show answer Blue/Green deployment steps:

1. Traffic coming from users through a load balancer to the application which is currently version 1

Users -> Load Balancer -> App Version 1

2. A new application version 2 is deployed (while version 1 still running)

Users -> Load Balancer -> App Version 1
App Version 2

3. If version 2 runs properly, traffic switched to it instead of version 1

User -> Load Balancer App version 1
-> App Version 2

4.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

18. What happens after you edit a deployment and change the image?

Show answer The pod will terminate and another, new pod, will be created.

Also, when looking at the replicaset, you'll see the old replica doesn't have any pods and a new replicaset is created.

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`

19. Create a deployment with the following properties:

Show answer `kubectl create deployment blufer --image=python --replicas=3 -o yaml --dry-run=client > deployment.yaml`

Add the following section (`vi deployment.yaml`):

```\nspec:\n affinity:\n nodeAffinity:\n requiredDuringSchedulingIgnoredDuringExecution:\n nodeSelectorTerms:\n - matchExpressions:\n - key: blufer\n operator: Exists\n```

`kubectl apply -f deployment.yaml`

Example: `kubectl create deployment web --image=nginx --replicas=3 --port=80`

Remember: Deployments manage ReplicaSets→Pods. `kubectl rollout` for updates.

20. What happens behind the scenes when you create a Deployment object?

Show answer The following occurs when you run `kubectl create deployment some_deployment --image=nginx`

1. HTTP request sent to kubernetes API server on the cluster to create a new deployment
2. A new Pod object is created and scheduled to one of the workers nodes
3. Kublet on the worker node notices the new Pod and instructs the Container runtime engine to pull the image from the registry
4. A new container is created using the image that was just pulled

Remember: Deployment > ReplicaSet > Pod. Three layers for declarative management.

Example: `kubectl create deployment web --image=nginx:1.25 --replicas=3 --port=80`