Capstone Project - Docker and Kubernetes A Docker and Kubernetes capstone project can be a great way to showcase your skills in containeriza...
Capstone Project - Docker and Kubernetes
A Docker and Kubernetes capstone project can be a great way to showcase your skills in containerization and orchestration. Here's a project idea along with a solution outline:
Project Idea: Building and Deploying a Scalable Web Application
Objective: Create a scalable web application that demonstrates containerization with Docker and orchestration with Kubernetes. The project involves building a simple web app, containerizing it with Docker, and deploying it on a Kubernetes cluster.
Solution Outline
1. Web Application
HTML application served by an Apache web server. This project will involve setting up a basic HTML application, containerizing it with Docker, and then deploying it on a Kubernetes cluster.
Project Outline
- Create a Simple HTML Application
- Dockerize the HTML Application with Apache
- Deploy to Kubernetes
1. Create a Simple HTML Application
index.html
:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Simple HTML App</title>
</head>
<body>
<h1>Hello, Kubernetes!</h1>
<p>This is a simple HTML application served by Apache.</p>
</body>
</html>
2. Dockerize the HTML Application with Apache
Create a Dockerfile to set up an Apache server and serve your HTML file.
Dockerfile
:
# Use the official Apache HTTP server image from the Docker Hub FROM httpd:2.4 # Copy the HTML file to the Apache web server's default directory COPY index.html /usr/local/apache2/htdocs/ # Expose port 80 to allow traffic to the web server EXPOSE 80
Build the Docker image:
docker build -t simple-html-app .
Run the Docker container locally to test:
docker run -p 8080:80 simple-html-app
You should be able to visit http://localhost:8080
and see your HTML page.
3. Deploy to Kubernetes
Create Kubernetes configuration files for deployment and service.
deployment.yaml
:
apiVersion: apps/v1kind: Deployment
metadata:
name: simple-html-app-deployment
spec:
replicas: 2
selector:
matchLabels:
app: simple-html-app
template:
metadata:
labels:
app: simple-html-app
spec:
containers:
- name: simple-html-app
image: simple-html-app:latest
ports:
- containerPort: 80
service.yaml
:
apiVersion: v1kind: Service
metadata:
name: simple-html-app-service
spec:
type: LoadBalancer
ports:
- port: 80
targetPort: 80
selector:
app: simple-html-app
3. Deploy to Kubernetes
Push Docker Image to a Registry: Push the Docker image to a container registry like Docker Hub or a private registry.
docker tag simple-html-app yourdockerhubusername/simple-html-app:latestdocker push yourdockerhubusername/simple-html-app:latest
Apply Kubernetes Configurations: Ensure you have a running Kubernetes cluster (e.g., Minikube, Docker Desktop Kubernetes, GKE, EKS, or AKS).
kubectl apply -f deployment.yamlkubectl apply -f service.yaml kubectl apply -f ingress.yaml
Verify Deployment: Check the status of the deployment and service.
kubectl get deploymentskubectl get services kubectl get pods kubectl get ingress
4. Access the Application
LoadBalancer: Get the external IP of your service:
kubectl get servicesAccess the application via the external IP.
Ingress: Configure your local
/etc/hosts
file to mapsimple-html-app.local
to the Ingress controller IP.
Summary
- Build a simple HTML application.
- Dockerize the application with Apache.
- Push the Docker image to a container registry.
- Deploy to Kubernetes using deployment and service configurations.
- Access the application using either a LoadBalancer or Ingress.
This project will give you a solid understanding of deploying web applications in a Kubernetes environment, including containerization with Docker and service management with Kubernetes.
COMMENTS