A cloud-native infrastructure project that deploys a simple World Clock Dashboard App to Azure Kubernetes Service (AKS)
The branch is for a more secure setup that restricts access to the AKS API server to a private VNet and uses a self-hosted GitHub Actions runner (within the same VNet) when there is a need to access it during CI/CD, eliminating the need to expose the cluster publicly.
This project is designed to demonstrate cloud engineering skills, including Infrastructure as Code (IaC), containerization, orchestration, monitoring and CI/CD automation.
This project demonstrates a deployment of a simple API written in Python that returns the current UTC time of various locations around the world and a Vite frontend that displays them. It includes the use of the following:
- API: Simple Flask API that returns current UTC time for various locations
- Frontend: Vite application that displays the time data from the API
- Containerisation: Docker for test-running and building the application container
- Orchestration: Kubernetes for container orchestration
- Cloud Infrastructure: Azure Kubernetes Service (AKS) for hosting the application
- Networking: Azure Load Balancer and NGINX Ingress Controller for traffic management
- CI/CD: GitHub Actions for automated deployment
- Monitoring: Microsoft Log Analytics and kube-prometheus-stack (Prometheus and Grafana) for monitoring and observability
- Security: GitHub Secrets, Network Security Group, Microsoft Azure Role Based Access Control, Network policies and isolating API Server access to a private VNet
- Infrastructure as Code: The use of Terraform and Bash scripts running Microsoft Azure CLI and GitHub CLI commands for scripting/automation purposes
- SSL/TLS:
Before getting started, ensure you have installed and configured the following tools and services for your local machine and CI/CD environment:
- Microsoft Azure CLI
- GitHub CLI
- Terraform >= 1.12.2
- kubelogin
- kubectl
- Helm
- Docker
- Microsoft Azure Account with a student or paid subscription and appropriate permissions (an Owner role is preferable)
- Docker Hub Account as a container registry
- GitHub Repository for version control and CI/CD automation
- Microsoft Azure subscription with
Ownerrole is preferable - Permission to create and manage Microsoft Azure AD groups and service principals
Fork this repository to your GitHub account (to fork other branches too, untick the copy only main branch option)
git clone https://github.com/VictortheGreat7/self-hosted-full-stack.git YOUR-CHOSEN-REPO-NAME/
cd YOUR-CHOSEN-REPO-NAMECreate a service principal for GitHub Actions:
# Login to Microsoft Azure
az login --use-device-code
# Update the service_principal.sh script variables with your details before running it. You can find it here:
cd terraform/bash_scripts
# Run the service principal creation script
chmod +x service_principal.sh
./service_principal.shRequired Variables:
SERVICE_PRINCIPAL_NAME: Choose a unique nameSCOPE: Your Microsoft Azure subscription IDGITHUB_NAME: Your GitHub usernameGITHUB_REPO: Your repository name
A secrets.yaml file will be created in whatever repository you execute the script, with the details of the created service principal
Set up the required GitHub repository secrets. You can use the provided script:
chmod +x gh_secret.sh
# Edit the script with your secret values first
./gh_secret.shRequired Values/Secrets:
AZURE_CREDENTIALS: JSON object with Microsoft Azure service principal detailsARM_CLIENT_ID: Microsoft Azure service principal client IDARM_CLIENT_SECRET: Microsoft Azure service principal client secretARM_SUBSCRIPTION_ID: Your Microsoft Azure subscription IDARM_TENANT_ID: Your Microsoft Azure tenant IDMY_USER_OBJECT_ID: Your Microsoft Azure AD user object IDRUNNER_TOKEN: GitHub Actions runner token for the self-hosted runner. Find out howhere. The cloud-init file for the runner vm already follows the instructions listed. All you need to do is copy the time-limited token with ./config.sh in the configure step. Just make sure you select Linux x64 architecture
DOCKER_USERNAME: Docker Hub usernameDOCKER_PASSWORD: Docker Hub password/token
Note: For the needed Microsoft Azure account details, check secrets.yaml created by the Service Principal creation step.
Edit the following files with your specific details:
# Update these variables
RESOURCE_GROUP_NAME="" # Change this
STORAGE_ACCOUNT_NAME="" # Choose a unique name
CONTAINER_NAME="tfstate"
REGION="eastus"terraform {
backend "azurerm" {
resource_group_name = "" # Update this
storage_account_name = "" # Update this
container_name = "tfstate"
key = "terraform.tfstate"
}
}provider "azurerm" {
features {}
subscription_id = "YOUR-SUBSCRIPTION-ID" # Update this
}Uncomment or add on-push trigger in .github/workflows/build.yaml and ensure other workflows will not trigger on push (except the app is up and you need to apply changes will integrate.yaml).
# on:
# push:
# branches:
# - mainPush your changes to trigger the GitHub Actions workflow:
git add .
git commit -m "[YOUR COMMIT MESSAGE]"
git push origin mainThe workflow will:
- Build and test the Docker image
- Push the image to Docker Hub
- Provision part of Microsoft Azure infrastructure needed including the self-hosted runner with Terraform using a GitHub hosted Actions runner
- Provision the rest of the infrastructure using the self-hosted runner
- Deploy the application to AKS
Important: You can only connect to the cluster rom your self-hosted runner. There is also an ssh command in the outputs printed after a successful terraform apply that you can use to connect to the self-hosted runner for any sort of troubleshooting or the other.
If you prefer to deploy manually and you have updated the configuraton as specified above:
cd terraform/bash_scripts
chmod +x pre-apply.sh
./pre-apply.shcd ../
terraform init
terraform apply# Move microservice configs
cd deploy/
mv * ../
cd ../
# Create SSH keys for the self-hosted runner
ssh-keygen -t rsa -b 4096 -C "github-selfhosted-runner" -f ssh_keys/id_rsa
# Apply microservice deployment
terraform init
terraform applyIn the outputs printed after a successful terraform apply, you will see the ingress IP of the deployed API. You can test it using:
curl http://<your-ingress-ip>or with just http://<your-ingress-ip> in your browser.
Important: You can only connect to the cluster in this scenario from you self-hosted runner. There is also an ssh command in the outputs printed after a successful terraform apply that you can use to connect to the self-hosted runner for any sort of troubleshooting.
# Backend
cd backend
pip install -r requirements.txt
python app.py
# Frontend (in a new terminal)
cd frontend
npm install
npm run devAccess the application
Frontend: http://localhost:5173 (or the port shown in terminal)
API: http://localhost:5000/world-clocks
# Build the backend image
cd backend
docker build -t kronos:backend .
docker run -d -p 5000:5000 --name kronos-backend-local kronos:backend
# Build the frontend image
cd frontend
docker build -t kronos:frontend .
docker run -d -p 5173:80 --name kronos-frontend-local kronos:frontend
# Test the endpoint
curl http://localhost:5000/world-clocks
# and access http://localhost:80 in your browser to check frontend
# Clean up
docker stop kronos-frontend-local
docker stop kronos-backend-local
docker rm kronos-frontend-local
docker rm kronos-backend-localThe project includes comprehensive monitoring:
- Grafana Dashboard: Visual monitoring interface
- Prometheus: Metrics scraping
- Microsoft Azure Log Analytics: Centralized logging
Access your Grafana dashboard through the terraform ingress outputs after deployment.
- Network Policies: Restrict namespace communication to an as-needed basis
- GitHub Secrets: Secure storage of sensitive tokens
- Service Principals: Secure access for GitHub Actions
- Microsoft Azure RBAC: Role-based access control
- Network Security Groups: Microsoft Azure Network-level security
- Private Subnets: Isolated network segments
- Private Cluster: Restricted access to the Kubernetes API server
# Get AKS credentials
az aks get-credentials --resource-group RESOURCE_GROUP --name CLUSTER_NAME
# Kubernetes Authentication
kubelogin convert-kubeconfig -l azurecli
# Check application status
kubectl get all -n time-api
# View logs
kubectl logs -f deployment/time-api -n time-apiTo destroy all Terraform resources:
Using GitHub Actions: Trigger the "Destroy Infrastructure" workflow manually from the GitHub Actions tab.
Manual Cleanup:
cd terraform
terraform destroyNote: This will permanently delete all Microsoft Azure resources created with terraform apply.
self-hosted-full-stack/
βββ .github/
β βββ workflows/ # GitHub Actions CI/CD pipelines
β βββ build.yaml # Main deployment workflow
β βββ destroy.yaml # Resource cleanup workflow
β βββ integrate.yaml # Subsequent infrastructure/deployment changes workflow
βββ backend/ # Flask API application
β βββ app.py # Flask application entry point
β βββ Dockerfile # Backend container image definition
β βββ requirements.txt # Python dependencies
βββ frontend/ # Vite React application
β βββ public/ # Static assets
β βββ src/ # React source code
β β βββ assets/ # Images and other assets
β β βββ components/ # React components
β β β βββ CityCard.css # City card styles
β β β βββ CityCard.jsx # City card component
β β β βββ ClockOrbit.css # Clock orbit animation styles
β β β βββ ClockOrbit.jsx # Clock orbit component
β β β βββ Dashboard.css # Dashboard styles
β β β βββ Dashboard.jsx # Dashboard component
β β βββ App.css # Application styles
β β βββ App.jsx # Main App component
β β βββ index.css # Global styles
β β βββ main.jsx # Application entry point
β βββ .env # Local environment variables
β βββ .env.production # Production environment variables
β βββ .gitignore # Frontend-specific Git ignore rules
β βββ Dockerfile # Frontend container image definition
β βββ eslint.config.js # ESLint configuration
β βββ index.html # HTML template
β βββ nginx.conf # NGINX configuration for production
β βββ package.json # Node.js dependencies and scripts
β βββ README.md # Frontend documentation
β βββ vite.config.js # Vite build configuration
βββ screenshots/ # Project screenshots and documentation images
βββ terraform/ # Infrastructure as Code (IaC) and automation
β βββ bash_scripts/ # Helper automation scripts
β β βββ get-aks-cred.sh # Script to retrieve AKS credentials
β β βββ gh_secret.sh # GitHub secrets management script
β β βββ pre-apply.sh # Pre-apply script for Terraform backend setup
β β βββ service_principal.sh # Azure service principal creation script
β βββ deploy/ # Application deployment Terraform modules
β β βββ data.tf # Data sources for existing resources
β β βββ deploy.tf # Application deployment resources
β β βββ ingress.tf # Ingress controller and routing configuration
β β βββ monitoring.tf # Monitoring and observability stack (Prometheus/Grafana)
β β βββ netpolicy.tf # Kubernetes network policies
β β βββ permissions.tf # Azure RBAC permissions configuration
β β βββ provision.tf # Kubernetes cluster provisioning resources
β βββ ssh_keys/ # SSH keys for self-hosted runner access
β β βββ id_rsa # Private SSH key (git-ignored)
β β βββ id_rsa.pub # Public SSH key
β βββ .terraform.lock.hcl # Terraform dependency lock file
β βββ backend.tf # Terraform remote state backend configuration
β βββ cloud-init.yaml.tpl # Cloud-init template for self-hosted GitHub runner setup
β βββ main.tf # Main Terraform entry point (AKS cluster, resource groups, runner VM)
β βββ network.tf # Azure networking configuration (VNet, subnets, NSG)
β βββ outputs.tf # Terraform output values
β βββ providers.tf # Terraform provider configurations
β βββ terraform.tfvars.json # Terraform variable values (auto-generated from GitHub secrets)
β βββ variables.tf # Terraform variable definitions
βββ .gitignore # Root Git ignore rules
βββ Dockerfile # Legacy/root Dockerfile (if applicable)
βββ gh_secret.sh # Root-level GitHub secrets setup script
βββ README.md # Project documentation- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and commit:
git commit -am 'Add feature' - Push to the branch:
git push origin feature-name - Submit a pull request
If you encounter issues:
- Check the Troubleshooting section
- Review the GitHub Actions logs
- Check Microsoft Azure portal for resource status
- Open an issue in this repository
- Microsoft Azure Documentation
- Docker Documentation
- GitHub Actions Documentation
- Terraform Documentation
- Terraform Microsoft Azure Provider
- Terraform Kubernetes Provider
- Terraform Helm Provider
- Terraform kubectl Provider
- Terraform NGINX Ingress Controller Module
- Azure Kubernetes Service Documentation
- Kubernetes Documentation
- Let's Encrypt Documentation
Disclaimer: This project is designed for learning and demonstration purposes. For production use, consider additional security hardening, cost optimization, and compliance requirements specific to your organization.