This project demonstrates how to deploy a custom web application on a Kubernetes cluster using Nginx, manage DNS using DuckDNS, and integrate Velero for backup and restore operations. The application runs on a Google Kubernetes Engine (GKE) cluster with a static IP and a custom domain provided by DuckDNS.
In this project, we:
- Create a custom web application deployed using Nginx on a GKE cluster.
- Map a DuckDNS subdomain to the GKE service using a reserved static IP.
- Set up Velero to back up the web application's namespace and restore it after deletion.
- Google Cloud account with access to Google Kubernetes Engine (GKE)
- gcloud and kubectl CLI installed
- Docker for building custom images
- A DuckDNS account (free dynamic DNS provider)
- Velero CLI installed
First, create a GKE cluster:
gcloud container clusters create my-cluster \
--num-nodes=3 \
--zone us-east1-bConnect your local environment to the GKE cluster:
gcloud container clusters get-credentials my-cluster --zone us-east1-b-
Create a Custom Web Page:
Save the following content in a file named
index.html:<!DOCTYPE html> <html> <head> <title>My Kubernetes Web App</title> <style> body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; } h1 { color: #333; } p { color: #666; } </style> </head> <body> <h1>Welcome to My Custom Web App on Kubernetes!</h1> <p>This page is running on a Kubernetes cluster using Nginx.</p> <p>Check out my projects on <a href="https://github.com/your-github-username">GitHub</a>.</p> </body> </html>
-
Create a Docker Image:
Create a
Dockerfilefor Nginx:FROM nginx:alpine COPY index.html /usr/share/nginx/html/index.html
Build and push the Docker image to Docker Hub:
docker build -t <your-dockerhub-username>/custom-nginx . docker push <your-dockerhub-username>/custom-nginx
-
Deploy the Nginx Application in GKE:
Create a Kubernetes deployment using your custom image:
kubectl create namespace my-web-app kubectl create deployment nginx --image=<your-dockerhub-username>/custom-nginx --namespace=my-web-app kubectl expose deployment nginx --port=80 --target-port=80 --type=LoadBalancer --namespace=my-web-app
-
Reserve a Static IP in GCP:
gcloud compute addresses create nginx-static-ip --region us-east1
Update the Nginx service to use the static IP:
kubectl patch svc nginx -n my-web-app -p '{"spec": {"loadBalancerIP": "35.196.170.189"}}'
-
Sign up for a free account at DuckDNS.
-
Create a subdomain (e.g.,
kushalesh.duckdns.org). -
Map the subdomain to your static IP (
35.196.170.189). -
Verify DNS propagation:
nslookup kushalesh.duckdns.org
Now, you can access your web app at http://kushalesh.duckdns.org.
-
Install Velero in your GKE cluster:
velero install \ --provider gcp \ --bucket <your-gcs-bucket-name> \ --secret-file ./key.json \ --backup-location-config serviceAccount=./key.json \ --use-volume-snapshots=false \ --plugins velero/velero-plugin-for-gcp:v1.5.0 \ --wait
-
Verify Velero Installation:
kubectl get pods -n velero
-
Create a Backup of the Namespace:
velero backup create my-web-app-backup --include-namespaces my-web-app
-
Simulate a Disaster:
Delete the namespace:
kubectl delete namespace my-web-app
-
Restore the Backup:
velero restore create --from-backup my-web-app-backup
-
Verify the Restoration:
kubectl get all --namespace=my-web-app
Your web application should be restored and accessible again via http://kushalesh.duckdns.org.
This project showcases how to:
- Deploy a custom web app using Nginx on GKE.
- Use DuckDNS to manage DNS for a Kubernetes service with a static IP.
- Implement Velero for Kubernetes backup and restore functionality.