Hello! Let's dive into Module 10.
In our last lesson, you successfully provisioned a production-grade Kubernetes cluster on AWS using EKS and eksctl. You now have a running, albeit empty, cluster and you know how to connect to it using kubectl. This is a massive step, moving us from a single-machine setup to a distributed cloud environment.
Today, we'll start giving that cluster something to do. Our goal is to tell Kubernetes how to run our Blog service. To do this, we'll learn to write a Deployment manifest—a declarative configuration file that describes the desired state for our application.
MERN Stack Comparison
In your MERN world, you might use a process manager like PM2 to run your Node.js application, ensure it restarts on failure, and scale it across CPU cores. A Kubernetes Deployment serves a similar purpose but on a much grander, cluster-wide scale. It defines which Docker container to run, how many copies (replicas) to maintain for high availability, and how to perform updates. The manifest file we will write is the declarative "source of truth" for how our service should run.
1. The Core of Kubernetes: Desired State
Before we write any code, it's crucial to understand the fundamental principle of Kubernetes: desired state management.
You don't tell Kubernetes how to do things (e.g., "start a container"). Instead, you tell it what you want the end result to be (e.g., "I want 3 instances of my application running at all times"). This is the desired state.
Kubernetes's job is to constantly observe the current state of the cluster and take action to make it match the desired state you've defined.

We define this desired state using YAML files, which are called manifests in Kubernetes terminology. The first and most common manifest we'll work with is the Deployment.
2. Anatomy of a Deployment Manifest
A Deployment is a Kubernetes object specifically designed to manage stateless applications. It creates and manages a set of identical Pods. A Pod is the smallest deployable unit in Kubernetes—think of it as a wrapper around one or more of your application containers.
Let's break down the structure of a Deployment manifest.
Kubernetes YAML File Explained - Deployment and Service | Kubernetes Tutorial 19
To get a high-level overview of how Kubernetes configuration files are structured, watch this short explanation from TechWorld with Nana. It clarifies the purpose of the metadata, spec, and auto-generated status fields.
Watch from the beginning to 03:42. Focus on understanding the roles of the three main parts of a Kubernetes configuration file. Don't worry about the Service example for now; we'll cover that in the next lesson.
As you saw, a typical manifest has these top-level fields:
apiVersion: Specifies the Kubernetes API version to use for this object. For Deployments, it'sapps/v1.kind: The type of object we are defining. Here, it'sDeployment.metadata: Data that helps uniquely identify the object, such as itsname.spec: This is the most important part—it's where we define the desired state for ourDeployment.
Let's dig deeper into the spec for a Deployment.
Developing and deploying Spring Boot microservices on Kubernetes - Defining a Deployment
The article "Developing and deploying Spring Boot microservices on Kubernetes" provides a practical, code-first breakdown of a Deployment manifest. We'll use it to understand the key fields within the spec.
Read the section that breaks down the knote.yaml file, starting from "Now that you know how to look up the documentation..." down to the end of the section. Pay close attention to the explanation of replicas, selector, and the template section.
Based on that reading, here are the crucial fields inside spec:
-
replicas: A simple integer that tells Kubernetes how many identical Pods to run. If you set this to3, Kubernetes will ensure three Pods for your application are always running. -
selector: This tells theDeploymenthow to find the Pods it is supposed to manage. It useslabels—key-value pairs you attach to objects. Theselectorspecifies which labels a Pod must have to be managed by thisDeployment. -
template: This is the blueprint for the Pods that theDeploymentwill create. It has its ownmetadataandspec:template.metadata.labels: These are the labels applied to each Pod created from this template. Crucially, these labels must match theselectorof the Deployment. This is how theDeploymentfinds its Pods.template.spec: This defines the actual contents of the Pod, most importantly the containers to run.containers: A list of containers to run inside the Pod. For our simple services, this will just be one container.name: A name for the container (e.g.,blog-service).image: The Docker image to pull and run.ports: The network ports to open on the container (e.g.,containerPort: 8080for our Spring Boot app).
3. Hands-On: Deploying the Blog Service
Let's put theory into practice. We'll create a Deployment manifest for our blog-service.
Since we haven't set up our image registry (ECR) yet, we'll use a public, pre-built Spring Boot "hello world" image for now. This lets us focus purely on the Kubernetes part. We'll substitute our actual service image in a later module.
Step 1: Create the Manifest File
In the root of your project, create a new directory called kube. Inside this directory, create a file named blog-service-deployment.yaml.
/blog-platform
|-- /kube
| |-- blog-service-deployment.yaml
|-- /src
|-- ...
Step 2: Write the Deployment Manifest
Copy the following YAML content into your blog-service-deployment.yaml file.
# kube/blog-service-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: blog-service-deployment
spec:
replicas: 2
selector:
matchLabels:
app: blog-service
template:
metadata:
labels:
app: blog-service
spec:
containers:
- name: blog-service-container
image: paulbouwer/spring-boot-hello-world:latest
ports:
- containerPort: 8080
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
Let's break down two new additions here:
resources: This is a critical section for production stability.requests: The amount of CPU and memory that Kubernetes guarantees to allocate to the Pod.limits: The maximum amount of CPU and memory the Pod is allowed to consume. If it exceeds the memory limit, Kubernetes will terminate it (a common "OOMKilled" error).
- Why is this important? Setting resources prevents a single misbehaving service from consuming all the resources on a node and crashing other services. It also helps Kubernetes make smarter decisions about where to schedule Pods.

Step 3: Apply the Manifest and Verify
Now, use kubectl to send this manifest to your EKS cluster.
-
Apply the configuration:
kubectl apply -f kube/blog-service-deployment.yamlYou should see the output:
deployment.apps/blog-service-deployment created. -
Verify the Deployment: Check that the Deployment object exists and its desired state is being met.
kubectl get deploymentsThe output should show
blog-service-deploymentwith2/2in theREADYcolumn, indicating both replicas are running. -
Inspect the Pods: The Deployment creates Pods. Let's see them.
kubectl get podsYou'll see two Pods with names like
blog-service-deployment-xxxxxxxxxx-xxxxx. Their status should beRunning.
This workflow—apply, get, describe—is the fundamental feedback loop for working with Kubernetes.
Kubernetes Tutorial | Run & Deploy Spring Boot Application in K8s Cluster using yaml configuration
To see this workflow in action, watch this clip from Java Techie. It demonstrates applying a manifest and then using kubectl get pods and kubectl logs to verify the deployment.
Watch from 08:19 to 10:33. This shows exactly the steps we just took: applying the YAML file, checking the pods that are created, and looking at the logs of a running pod. This is your primary debugging loop.
4. Debugging-First: When Things Go Wrong
Your kubectl get pods command is your first stop. If you see a status other than Running (e.g., ImagePullBackOff, CrashLoopBackOff, Pending), your next step is to use describe.
- Scenario: You make a typo in the image name. The Pod status will be
ImagePullBackOff. - Debug Command:
kubectl describe pod <your-pod-name> - Output: In the
Eventssection at the bottom, you'll see a clear error message likeFailed to pull image "..."andError: image not found. This tells you exactly where the problem is.
Always start with get pods, then describe pod, and finally logs pod (kubectl logs <your-pod-name>) to check for application-level errors.
Conclusion
In this lesson, you moved from having an empty cluster to deploying your first application. You've learned the most fundamental concept in Kubernetes—desired state—and translated that into a practical Deployment manifest.
Key Takeaways:
- A Kubernetes
Deploymentdescribes the desired state for a stateless application. - We define this state in a YAML manifest with four key fields:
apiVersion,kind,metadata, andspec. - The connection between a
Deploymentand itsPodsis made usinglabelsandselectors. - The Pod
templatedefines the blueprint for each replica, including the containerimageandresources. - Your core workflow is: write YAML ->
kubectl apply->kubectl get->kubectl describe.
Preview of the Next Lesson:
Our Pods are running, but they are isolated. They have internal IP addresses that can change at any time, making them inaccessible. In the next lesson, we will write a Service manifest. A Kubernetes Service provides a stable network endpoint (a single, unchanging IP address and DNS name) to access our group of blog-service Pods.