Containerize and Deploy with Kubernetes
Package a Python web app into a Docker container and deploy it to Kubernetes.
Introduction
30 Second Summary
Every developer has heard "it works on my machine." Containers solve this by packaging your code with everything it needs to run identically on any system.
In this project, you will build a Python web application, package it into a Docker container, and deploy it to a local Kubernetes cluster. You'll experience the complete container lifecycle from code to orchestrated deployment.
What You'll Build
A Python Flask web application that displays its container hostname, packaged into a Docker image and deployed to a local Kubernetes cluster using Docker Desktop's built-in Kubernetes.
By the end of this project, you'll have:
- A Python Flask web application containerized with Docker.
- A custom Docker image built from a Dockerfile you wrote.
- A running Kubernetes deployment accessible in your browser at localhost:30001.
- Secret Mission: Scale your deployment to 3 replicas and watch Kubernetes load-balance traffic between them.
Are there any prerequisites?
None. This project includes full setup instructions for Docker Desktop, Kubernetes, and every tool you need. No prior experience with containers or orchestration is required.
Before We Start
Before We Start...
Install and Configure Docker Desktop
Before you can build containers or deploy to Kubernetes, you need the engine that makes it all possible.
Docker Desktop is a one-click-install application that bundles the Docker Engine, the Docker CLI, and a built-in Kubernetes cluster into a single package. In this step, you will install Docker Desktop on Windows and enable its Kubernetes feature.
In this step, get ready to:
- Install Docker Desktop for Windows in per-user mode.
- Verify Docker is running with two terminal commands.
- Enable Kubernetes inside Docker Desktop.
Download and install Docker Desktop
Docker Desktop is free for personal use and education. The per-user installation mode does not require administrator privileges to install or update.
- Open your browser and navigate to the Docker Desktop for Windows install page:
- https://docs.docker.com/desktop/install/windows-install
- Click the download button at the top of the page to download Docker Desktop Installer.exe.
- Double-click Docker Desktop Installer.exe to run the installer.
- When prompted, choose the Per-user installation mode (recommended). This does not require admin rights.
- Follow the remaining prompts to complete the installation.
What is Docker Desktop?
Docker Desktop is an application that bundles the Docker Engine (the runtime that builds and runs containers), the Docker CLI (the command-line tool you use to interact with Docker), and a built-in Kubernetes cluster. It handles all the complex setup behind the scenes so you can focus on building.
Why per-user mode?
Per-user mode installs Docker Desktop without needing administrator privileges. It uses the WSL 2 backend, which covers the needs of the vast majority of Docker users. This means you can get started even on machines where you do not have admin access.
- Once installation completes, Docker Desktop will launch automatically. If it does not, press the Windows key to open your search bar, type Docker Desktop, and press Enter to open it.
- Accept the Docker Subscription Service Agreement when prompted.
- Wait for Docker Desktop to finish starting up. You will see the Docker Desktop Dashboard with a green status indicator when it is ready.
First-time WSL 2 setup
If this is your first time enabling WSL 2, Windows may prompt you for administrator access once to enable it. This is a one-time requirement. After that, Docker Desktop runs without admin rights.
Docker Desktop won't start?
Make sure your Windows version meets the requirements: Windows 10 64-bit (version 22H2, build 19045 or higher) or Windows 11 64-bit (version 23H2, build 22631 or higher). You also need at least 8GB of system RAM and a 64-bit processor with SLAT.
If you see a message about virtualization, you may need to enable it in your BIOS settings. Search for your laptop or motherboard model plus "enable virtualization" for instructions specific to your machine.
help me troubleshoot Docker Desktop not starting on Windows
Verify Docker is running
With Docker Desktop running, you can now use the Docker CLI in PowerShell to confirm everything is working.
- Open PowerShell by pressing the Windows key, typing PowerShell, and pressing Enter.
- Check your Docker version by running this command:
docker --version
What does this command do?
This prints the installed Docker Engine version number to confirm the docker CLI is available on your system PATH.
You should see a version number printed in the terminal, something like Docker version 28.x.x.
✔️ I see a version number
Docker is installed and ready. Continue to the next verification below.
ⓧ Command not found or error
If PowerShell does not recognize docker, try these fixes:
- Make sure Docker Desktop is running (check for the whale icon in your system tray).
- Close and reopen PowerShell so it picks up the updated PATH.
- If it still fails, restart your computer and try again.
- Run the hello-world container to confirm Docker can pull and run images:
docker run hello-world
What does this command do?
This command pulls a tiny test image from Docker Hub and runs it in a container. The container prints a confirmation message and exits. It proves that Docker can download images, create containers, and run them successfully.
You should see output that begins with Hello from Docker! followed by a message confirming your installation appears to be working correctly.
Seeing a network error?
The docker run hello-world command needs internet access to pull the image from Docker Hub. Check that you are connected to the internet and that no firewall or VPN is blocking Docker.
help me fix a Docker network error when pulling images
Enable Kubernetes in Docker Desktop
Docker Desktop includes a built-in single-node Kubernetes cluster that you can enable with one checkbox. This gives you a real Kubernetes environment on your local machine without any extra tools.
- Open the Docker Desktop Dashboard (click the whale icon in your system tray if it is not already open).
- Click the gear icon in the top-right to open Settings.
- Select the Kubernetes tab in the left sidebar.
- Check the box labeled Enable Kubernetes.
- Click Apply & restart.
What is Kubernetes?
Kubernetes is a container orchestration platform. It automates deploying, scaling, and managing containers across multiple machines. In production, companies use it to keep apps running reliably at scale.
For this project, you are using Docker Desktop's built-in single-node cluster. It behaves the same as a production cluster but runs entirely on your laptop.
Docker Desktop will take a minute or two to download and start the Kubernetes components. Wait until you see a green light beside Kubernetes running in the bottom-left of the Docker Desktop Dashboard.
- Once Kubernetes is running, go back to PowerShell and verify the cluster by running:
kubectl get nodes
What does this command do?
The kubectl tool is the Kubernetes command-line client. Docker Desktop installs it automatically. The get nodes subcommand lists all machines in your cluster. You should see one node named docker-desktop with a status of Ready.
You should see output showing a node named docker-desktop with status Ready.
✔️ I see docker-desktop with status Ready
Your Kubernetes cluster is running and ready for deployments.
ⓧ kubectl is not recognized
Docker Desktop should install kubectl automatically. Try these fixes:
- Close and reopen PowerShell to refresh your PATH.
- Make sure the Kubernetes green light is visible in Docker Desktop before running the command.
- If it still fails, open Docker Desktop Settings, go to the Kubernetes tab, uncheck Enable Kubernetes, click Apply & restart, then re-enable it and restart again.
ⓧ Node shows NotReady
The Kubernetes components are still starting up. Wait another minute and run kubectl get nodes again. If it stays NotReady for more than five minutes, try resetting the Kubernetes cluster from Docker Desktop Settings.
Your Docker and Kubernetes environment is fully set up. Next up, you will build the Python web application that will run inside your containers.
Build Your Web Application
Your Docker and Kubernetes environment is ready to go. Now it's time to write the application you'll containerize and deploy.
In this step, you'll create a simple Python web app using Flask. The app displays a greeting and the hostname of the container serving it. This hostname trick is what will let you see Kubernetes load-balancing in action later.
In this step, get ready to:
- Create a project folder for your app.
- Write a Flask web application that displays the container hostname.
- Create a requirements file listing the Flask dependency.
Create your project folder
Every project needs a home. You'll create a dedicated folder on your Desktop to hold all the files for this project.
- Move to your Desktop by running this command in PowerShell:
cd ~/Desktop
- Create your project folder and move into it by running these commands:
mkdir hello-k8s
cd hello-k8s
- Confirm the folder was created by running:
pwd
You should see a path ending in hello-k8s, confirming you're inside your new project folder.
Not seeing hello-k8s in the path?
Make sure you ran cd ~/Desktop first. If your Desktop is in a non-standard location, try running cd $HOME\Desktop instead.
Help me troubleshoot this issue.
Write the Flask application
Your app is a single Python file that serves an HTML page. The page displays the machine's hostname, which inside a container will be the container's unique ID.
- Create a new file called app.py in your hello-k8s folder. Open it in your text editor (VS Code or Notepad).
- Paste the following code into app.py:
import socket
from flask import Flask
# Create the Flask application
app = Flask(__name__)
# Define the route for the home page
@app.route("/")
def home():
# Get the container's hostname to display on the page
hostname = socket.gethostname()
return f"""
<html>
<head><title>Hello Kubernetes!</title></head>
<body style="font-family: Arial, sans-serif; text-align: center; padding-top: 50px;">
<h1>Hello from Kubernetes!</h1>
<p>Served by container: <strong>{hostname}</strong></p>
<p>If you scale this deployment, refresh to see different hostnames!</p>
</body>
</html>
"""
# Run the app on all network interfaces, port 5000
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
What does this code do?
- socket.gethostname() fetches the name of the machine running the code. Inside a Docker container, this returns the container's unique ID.
- The home() function returns an HTML page that displays this hostname. When you scale to multiple containers later, each one will show a different ID.
- host="0.0.0.0" tells Flask to listen on all network interfaces. This is required for the app to be reachable from outside the container.
- Save app.py.
Seeing red squiggly lines in your editor?
If your editor highlights flask as an unresolved import, that's expected. Flask isn't installed on your machine. It will be installed inside the Docker container later.
Help me understand this import error.
Create the requirements file
Docker needs to know which Python packages to install inside the container. A requirements.txt file lists those dependencies with pinned versions.
- Create a new file called requirements.txt in the same hello-k8s folder.
- Paste the following line into requirements.txt:
flask==3.1.1
Why pin the version?
Pinning flask==3.1.1 ensures that everyone who builds this image gets the exact same version of Flask. Without pinning, a future Flask update could break your app inside the container.
- Save requirements.txt.
- Confirm both files exist by running this in PowerShell:
ls
You should see app.py and requirements.txt listed in the output.
Don't see both files?
Make sure you saved both files into the hello-k8s folder on your Desktop, not a different location. Run pwd to check you're in the right folder.
Help me find my missing files.
Want to test the app locally?
If you have Python installed on your machine, you can run pip install flask==3.1.1 followed by python app.py and visit http://localhost:5000 in your browser. This is optional. Docker will handle running the app in the next step.
✔️ Awesome, I've got everything!
Great. Double check you've saved both files in your hello-k8s folder.
ⓧ I'd like to double check the full code
Here is the complete app.py:
import socket
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
hostname = socket.gethostname()
return f"""
<html>
<head><title>Hello Kubernetes!</title></head>
<body style="font-family: Arial, sans-serif; text-align: center; padding-top: 50px;">
<h1>Hello from Kubernetes!</h1>
<p>Served by container: <strong>{hostname}</strong></p>
<p>If you scale this deployment, refresh to see different hostnames!</p>
</body>
</html>
"""
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)
And the complete requirements.txt:
flask==3.1.1
Your application code is ready. Next up, you'll package it into a Docker container image so it can run anywhere.
Containerize with Docker
You have a working Flask app, but right now it only runs on your machine with your specific Python setup. To make it portable and deployable anywhere, you need to package it into a container.
A container bundles your code, its dependencies, and a runtime environment into a single package that runs identically on any machine. In this step, you will write the instructions Docker needs to build that package, then build and run it.
In this step, get ready to:
- Write a Dockerfile that tells Docker how to package your app.
- Build a Docker image from that Dockerfile.
- Run your app as a container and verify it in the browser.
Write your Dockerfile
A Dockerfile is a text file that contains step-by-step instructions for Docker to build an image. Each instruction adds a layer to the image, starting from a base operating system all the way to your running application.
- Create a new file called Dockerfile (no file extension) inside your hello-k8s folder.
- Paste the following code into Dockerfile:
# Use a lightweight Python image as the starting point
FROM python:3.12-slim
# Set the working directory inside the container
WORKDIR /app
# Copy the dependency list and install packages
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the application code
COPY app.py .
# Tell Docker this container listens on port 5000
EXPOSE 5000
# Start the Flask app when the container runs
CMD ["python", "app.py"]
What does this Dockerfile do?
Each line is an instruction that adds a layer to your container image:
- FROM python:3.12-slim starts from an official Python image that already has Python installed. The slim variant keeps the image small by excluding extras you do not need.
- WORKDIR /app creates a folder inside the container and makes it the active directory for all following commands.
- COPY requirements.txt . and RUN pip install install your dependencies before copying the app code. This ordering lets Docker cache the install step so rebuilds are faster.
- CMD ["python", "app.py"] tells Docker what command to run when a container starts from this image.
- Save Dockerfile.
- Confirm the file exists by running:
ls
You should see app.py, Dockerfile, and requirements.txt listed in the output.
Don't see the Dockerfile?
- Make sure the file is named exactly Dockerfile with a capital D and no extension. It should not be Dockerfile.txt or dockerfile.
- Confirm you saved the file inside the hello-k8s folder, not a parent directory.
- help me find my Dockerfile
✔️ Awesome, I've got everything!
Great. Double check you have saved your Dockerfile before moving on.
ⓧ I'd like to double check the full code
Here is the complete Dockerfile:
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py .
EXPOSE 5000
CMD ["python", "app.py"]
Build your Docker image
A Docker image is the packaged snapshot that Docker creates from your Dockerfile. Once built, you can spin up as many containers from that image as you want.
- Build the image by running this command in your terminal:
docker build -t hello-k8s .
What does this command do?
- docker build reads the Dockerfile in the current directory and executes each instruction.
- -t hello-k8s tags (names) the resulting image so you can reference it later.
- . tells Docker to use the current folder as the build context, meaning Docker can access all the files here.
The build takes about 30 seconds the first time because Docker downloads the python:3.12-slim base image. You should see progress output in your terminal ending with a FINISHED message.
Build failing?
- Make sure Docker Desktop is running. You should see the Docker whale icon in your system tray.
- Check that your terminal is inside the hello-k8s folder where the Dockerfile lives. Run ls to confirm.
- If you see a network error, check your internet connection. Docker needs to download the base image the first time.
- help me fix my Docker build error
Run your container
Your image is built. Now you will start a container from it and map your machine's port 5000 to the container's port 5000 so you can access the app in your browser.
- Start the container by running:
docker run -d -p 5000:5000 hello-k8s
What does this command do?
- docker run creates and starts a new container from the hello-k8s image.
- -d runs the container in detached mode (in the background) so your terminal stays free.
- -p 5000:5000 maps port 5000 on your machine to port 5000 inside the container. This is called port mapping.
Docker prints a long container ID string to your terminal. This confirms the container started successfully.
- Open your browser and go to http://localhost:5000.
You should see a page that says "Hello from Kubernetes!" along with a container hostname like a random string of letters and numbers.
Page not loading?
- Make sure you waited a few seconds after running the command. The Flask app needs a moment to start inside the container.
- Check that the container is actually running by typing docker ps in your terminal. You should see hello-k8s in the list.
- If docker ps shows nothing, run docker ps -a to see stopped containers. The container may have crashed on startup due to a typo in app.py or Dockerfile.
- help me figure out why my Docker container is not running
Your app is now running inside a container. Next up, you will deploy this same container to a local Kubernetes cluster and let Kubernetes manage it for you.
Deploy to Kubernetes
Your Docker container is running and serving your app. Now it is time to hand control over to Kubernetes.
Kubernetes needs a YAML manifest file that describes what to run and how to expose it to the network. You will write this manifest, apply it to your local cluster, and verify that Kubernetes has taken over managing your app.
In this step, get ready to:
- Write a Kubernetes YAML manifest that defines a Deployment and a Service.
- Apply the manifest to your local cluster.
- Verify the deployment, pod, and service are running.
Write the Kubernetes manifest
A Kubernetes manifest is a YAML file that tells the cluster exactly what resources to create. Your manifest will define two resources: a Deployment (which manages your container) and a Service (which makes it accessible on a network port).
- Create a new file called deployment.yaml in your hello-k8s project folder.
- Add the Deployment resource by pasting the following code into the file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-k8s
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: hello-k8s
template:
metadata:
labels:
app: hello-k8s
spec:
containers:
- name: hello-k8s
image: hello-k8s
imagePullPolicy: Never
ports:
- containerPort: 5000
What does this code do?
- kind: Deployment tells Kubernetes you want a managed set of identical pods.
- replicas: 1 means Kubernetes will keep exactly one copy of your container running at all times.
- image: hello-k8s points to the Docker image you built in the previous step.
- imagePullPolicy: Never tells Kubernetes to use your locally built image instead of trying to download one from the internet.
- containerPort: 5000 declares that your app listens on port 5000 inside the container.
You will not see a change yet. The next chunk adds the Service that exposes your app to the browser.
- Below the Deployment code in deployment.yaml, add the following Service resource:
---
apiVersion: v1
kind: Service
metadata:
name: hello-k8s-service
namespace: default
spec:
type: NodePort
selector:
app: hello-k8s
ports:
- port: 5000
targetPort: 5000
nodePort: 30001
What does the Service do?
A Kubernetes Service routes network traffic to your pods. The NodePort type exposes your app on a fixed port on your machine.
- type: NodePort makes the Service accessible from outside the cluster using localhost and a port number.
- nodePort: 30001 is the port you will visit in your browser to reach the app.
- selector: app: hello-k8s tells the Service which pods to send traffic to (any pod with the label app: hello-k8s).
- Save deployment.yaml.
Seeing a YAML syntax error later?
- Make sure the three dashes --- separating the Deployment from the Service sit on their own line with no extra spaces.
- YAML is whitespace-sensitive. Use spaces (not tabs) for indentation, with 2 spaces per level.
- Check that containers: is indented under spec: inside the template block, not the top-level spec.
Why is my deployment.yaml giving a syntax error?
✔️ Awesome, I've got everything!
Great. Double check you have saved deployment.yaml before continuing.
ⓧ I'd like to double check the full code
apiVersion: apps/v1
kind: Deployment
metadata:
name: hello-k8s
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: hello-k8s
template:
metadata:
labels:
app: hello-k8s
spec:
containers:
- name: hello-k8s
image: hello-k8s
imagePullPolicy: Never
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: hello-k8s-service
namespace: default
spec:
type: NodePort
selector:
app: hello-k8s
ports:
- port: 5000
targetPort: 5000
nodePort: 30001
Apply the manifest to your cluster
Your manifest describes what you want. Now you will tell Kubernetes to make it happen.
- Apply the manifest by running this command in PowerShell (make sure you are in the hello-k8s folder):
kubectl apply -f deployment.yaml
What does this command do?
kubectl apply -f deployment.yaml sends your manifest to the Kubernetes API server. Kubernetes reads both resource definitions and creates the Deployment and the Service in your local cluster.
You should see output confirming both resources were created:
deployment.apps/hello-k8s created
service/hello-k8s-service created
Seeing 'connection refused' or 'unable to connect'?
- Open Docker Desktop and check that the Kubernetes status indicator shows a green light. If it is orange or red, Kubernetes is still starting. Wait a minute and try again.
- If you see a context error, switch to the Docker Desktop context by running:
kubectl config use-context docker-desktop
Help me fix a kubectl connection refused error when applying my deployment.yaml.
Verify the deployment is running
Kubernetes creates resources asynchronously. Let's confirm that your Deployment, pod, and Service are all healthy.
- Check the Deployment status by running:
kubectl get deployments
You should see hello-k8s with READY showing 1/1.
- Check the pod by running:
kubectl get pods
You should see one pod with a name starting with hello-k8s- and a STATUS of Running.
- Check the Service by running:
kubectl get services
You should see hello-k8s-service with TYPE set to NodePort and PORT(S) showing 5000:30001/TCP.
Pod status showing something other than Running?
- If you see ErrImageNeverPull, Kubernetes cannot find the hello-k8s image locally. Make sure you built the image with docker build -t hello-k8s . in the previous step.
- If you see ContainerCreating, the pod is still starting. Wait 10-15 seconds and run kubectl get pods again.
- If you see CrashLoopBackOff, the container is crashing. Double check that your app.py and requirements.txt match the code from the previous step.
My Kubernetes pod is not running. Help me troubleshoot.
Your app is now fully managed by Kubernetes. Next up, you will access the app through the NodePort Service and explore useful kubectl commands for inspecting your deployment.
Test and Explore Your Deployment
In the last step, you deployed your app to Kubernetes and confirmed the pods and services are running.
Now it's time to see the app live in your browser and learn how to inspect what's happening inside the cluster. These inspection skills are what separate someone who can deploy from someone who can debug.
In this step, get ready to:
- Access your running app in the browser.
- Inspect pod logs and details with kubectl.
- Tear down the deployment cleanly.
Access the app in your browser
Your NodePort service exposes the app on port 30001 of your local machine. This means you can visit it in any browser just like a regular website.
- Open your web browser.
- Navigate to http://localhost:30001 by typing it into the address bar and pressing Enter.
You should see a page titled "Hello from Kubernetes!" with a line showing the container hostname (a random string like hello-k8s-abc12def3-xyz45).
What is the hostname showing me?
The hostname displayed on the page is the unique name Kubernetes assigned to the pod running your app. Every pod gets its own hostname, which is how you can tell which pod served a request.
When you scale to multiple replicas later, refreshing the page shows different hostnames as Kubernetes load-balances between pods.
Page not loading?
Make sure you are using http:// and not https:// in the URL. Your app does not have TLS configured.
Run kubectl get pods and check that your pod shows Running in the STATUS column. If it shows CrashLoopBackOff, something went wrong with the container startup.
help me debug why my app is not loading at localhost:30001
Inspect your running pod
In production, you rarely have direct access to a container's terminal. Instead, you use kubectl commands to read logs and inspect pod state remotely.
- First, get your pod's name by running this command:
kubectl get pods
You should see output showing your pod's name in the first column (something like hello-k8s-abc12def3-xyz45). Copy that full pod name.
- View the pod's logs by running this command (replacing the pod name with your own):
kubectl logs [[POD_NAME="your pod name from the output above"]]
What does this command do?
The kubectl logs command prints the standard output from a container running inside a pod. For your Flask app, this includes HTTP request logs showing each time someone visited the page.
You should see lines showing GET requests to / with a 200 status code, which confirms your app is serving traffic successfully.
- Now inspect the full details of your pod by running:
kubectl describe pod [[POD_NAME="your pod name from the output above"]]
What does kubectl describe show?
The kubectl describe pod command gives you a detailed view of everything Kubernetes knows about the pod. This includes its IP address, the node it runs on, container status, image used, port mappings, and recent events.
Scroll down to the Events section at the bottom. You should see entries like Scheduled, Pulled, Created, and Started confirming the pod's lifecycle.
Seeing an error with the pod name?
Make sure you copied the full pod name from the kubectl get pods output. The name includes random characters at the end (like hello-k8s-7d4f9b6c5d-x2k8m).
help me fix my kubectl logs or describe command
Tear down the deployment
Knowing how to cleanly remove resources is just as important as creating them. The same YAML manifest you used to create everything can also delete it all in one command.
- Delete the deployment and service by running:
kubectl delete -f deployment.yaml
What does this command do?
The kubectl delete -f deployment.yaml command reads your manifest file and removes every resource defined in it. In your case, that means both the Deployment (which manages the pods) and the Service (which handles networking).
- Verify everything is gone by running:
kubectl get pods
You should see the message No resources found in default namespace. which confirms your deployment has been fully removed.
Still seeing pods?
Pods may take a few seconds to terminate. If you see a pod with status Terminating, wait 10 seconds and run kubectl get pods again.
help me figure out why my pods are still running after kubectl delete
Secret mission
Scale and Load-Balance
You have one pod running your app. But in the real world, a single pod is a single point of failure. Can you scale your deployment to 3 replicas and watch Kubernetes distribute traffic across all of them?
Clean Up Your Resources
Clean Up Your Resources
This project runs entirely on your local machine using Docker Desktop. There are no cloud costs to worry about.
Decide whether to keep your resources running, pause them to come back later, or delete them entirely.
Resources you used:
- Kubernetes deployment (hello-k8s) and service (hello-k8s-service) running in your local cluster.
- Docker image (hello-k8s) stored on your local disk.
- Project folder on your Desktop containing app.py, requirements.txt, Dockerfile, and deployment.yaml.
- Docker Desktop with Kubernetes enabled (uses system memory while running).
Keep everything running
No action needed. Choose this if you are still actively experimenting with Docker and Kubernetes.
- Your Kubernetes deployment continues serving at http://localhost:30001.
- Docker Desktop stays running in the background and Kubernetes remains enabled.
- Your project folder stays on your Desktop for future edits.
Pause - I'll come back to this later
Shut down running processes to free up system memory. Your files and images stay on disk for when you return.
- Delete the Kubernetes deployment to free cluster resources by running:
- Open Docker Desktop.
- Click Settings (the gear icon).
- Select the Kubernetes tab on the left.
- Uncheck Enable Kubernetes.
- Click Apply & restart.
kubectl delete -f deployment.yaml
When you are ready to come back, re-enable Kubernetes in Docker Desktop Settings and re-apply your manifest.
Delete - I don't want to use this again
Remove all project resources and start fresh. Follow each step below.
- Delete the Kubernetes deployment and service by running:
kubectl delete -f deployment.yaml
- Remove all unused Docker images, containers, and build cache by running:
docker system prune -a
Docker will ask you to confirm. Type y and press Enter.
- Delete the project folder from your Desktop. On Windows (PowerShell), run:
cd ~\Desktop
Remove-Item -Recurse -Force .\hello-k8s
- On macOS or Linux, run:
cd ~/Desktop
rm -rf hello-k8s
- Disable Kubernetes in Docker Desktop by opening Settings, selecting the Kubernetes tab, unchecking Enable Kubernetes, and clicking Apply & restart.
That's a Wrap!
That's a Wrap!
Nice work! You have gone from zero to a fully orchestrated container deployment. You now have hands-on experience with the complete container lifecycle: code to image to Kubernetes-managed deployment.
You've learned how to:
- Written a Dockerfile to package a Python Flask application into a custom Docker container image, and ran it as a standalone container with port mapping.
- Deployed your containerized app to a local Kubernetes cluster using a YAML manifest that defined a Deployment and a NodePort Service.
- Used kubectl to inspect pods, view logs, describe resources, and tear down your deployment.
- Secret Mission: Scaled your deployment to 3 replicas and witnessed Kubernetes load-balancing traffic across multiple pods.
Ready to quiz yourself?