Tip
- This project provides various implementations of the Fibonacci sequence in Rust, including recursive, memoized, iterative, and dynamic programming approaches.
- It also includes a Kubernetes deployment with Helm charts deploying to minikube.
- Cluster has also Prometheus and Grafana installed to monitor the application.
Tip
The Fibonacci sequence is a series of numbers in which each number is the sum of the two preceding ones, usually starting with 0 and 1.
Tip
The sequence starts: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Tip
The Fibonacci sequence is defined by the recurrence relation: F(n) = F(n-1) + F(n-2) with base cases F(0) = 0 and F(1) = 1.
Tip
The Fibonacci sequence grows exponentially, so the recursive implementation is not efficient for large values of n.
Tip
The iterative and dynamic programming implementations are more efficient for large values of n.
Tip
The memoized recursive implementation is more efficient than the simple recursive implementation because it avoids redundant calculations.
Tip
The pattern matching implementation is similar to the simple recursive implementation but uses pattern matching instead of if-else statements.
Tip
The dynamic programming implementation uses an array to store the Fibonacci numbers and avoids redundant calculations.
The following implementations are provided:
fibonacci: A simple recursive implementation.fibonacci_match: A recursive implementation using pattern matching.fibonacci_dp: An implementation using dynamic programming.fibonacci_memo: A memoized recursive implementation.fibonacci_iterative: An iterative implementation.
Important
Before you begin, ensure you have the following tools installed:
- Rust & Cargo (for local builds/verification, optional if you only build in Docker).
- Docker (to build and push container images).
- Helm (to manage Kubernetes deployments).
- Minikube or a Kubernetes Cluster (for testing).
- Docker Hub Account (to push container images).
- Make (for using the Makefile automation - see installation below).
Choose one of these options:
Option 1: Chocolatey
choco install makeOption 2: Scoop
scoop install makeOption 3: Use Git Bash (comes with Git for Windows)
Option 4: Use WSL (Windows Subsystem for Linux)
Important
If you're using GitHub Actions for CI/CD, you need to set up the following secrets:
- Go to your GitHub repository
- Navigate to Settings → Secrets and variables → Actions
- Click New repository secret
- Add the following secrets:
| Secret Name | Description | Example Value |
|---|---|---|
DOCKER_USERNAME |
Your Docker Hub username | yourusername |
DOCKER_PASSWORD |
Your Docker Hub password or access token | dckr_pat_xxxxx |
Tip
Using Docker Hub Access Tokens (Recommended):
- Log in to Docker Hub
- Go to Account Settings → Security → New Access Token
- Create a token with Read, Write, Delete permissions
- Use this token as
DOCKER_PASSWORD(more secure than your actual password)
You can use a .env file for convenience:
-
Copy the example file:
copy .env.example .env -
Edit
.envand fill in your Docker Hub credentials -
Load the variables:
Windows (CMD):
for /F "tokens=*" %i in (.env) do set %iWindows (PowerShell):
Get-Content .env | ForEach-Object {
if ($_ -match '^([^=]+)=(.*)$') {
[Environment]::SetEnvironmentVariable($matches[1], $matches[2])
}
}Linux/Mac:
export $(cat .env | xargs)Warning
Never commit .env file to Git! It's already in .gitignore.
Or set the environment variable before running commands:
Windows (CMD):
set DOCKER_USERNAME=yourusername
docker build -t %DOCKER_USERNAME%/fibonacci_rust:v104 .Windows (PowerShell):
$env:DOCKER_USERNAME = "yourusername"
docker build -t ${env:DOCKER_USERNAME}/fibonacci_rust:v104 .Linux/Mac:
export DOCKER_USERNAME=yourusername
docker build -t ${DOCKER_USERNAME}/fibonacci_rust:v104 .Tip
A Makefile is provided for easy Grafana setup and service management!
Check if services are running:
make check-allPort-forward Grafana:
make grafanaPort-forward all services at once:
make allGenerate test traffic:
make trafficView all available commands:
make helpTip
This is the fastest way to test changes during development. Make sure you have Rust and Cargo installed.
Step 1: Build the project
cargo buildStep 2: Run the application
cargo runStep 3: Access the application
- Open your browser and navigate to
http://localhost:8080 - The application will start on port 8080
Step 4: Test the Fibonacci API You can use curl or Postman to test the endpoints:
curl -X POST http://localhost:8080/fib -H "Content-Type: application/json" -d "{\"n\": 10}"Step 5: Check application health
curl http://localhost:8080/health
curl http://localhost:8080/readyStep 6: View metrics (Prometheus format)
curl http://localhost:8080/metricsNote
The application creates a log file at /var/log/fibonacci.log when running with log4rs configured.
Tip
Use this approach for consistent environment across machines and to simulate production-like deployment.
Step 1: Build the Docker image
docker build -t fibonacci_rust:latest .Step 2: Run the Docker container
docker run -p 8080:8080 --name fibonacci fibonacci_rust:latestStep 3: Access the application
- Open your browser and navigate to
http://localhost:8080
Step 4: View container logs
docker logs fibonacciStep 5: Stop and remove the container
docker stop fibonacci
docker rm fibonaccidocker login --username your_docker_username
docker tag fibonacci_rust:latest your_docker_username/fibonacci_rust:v1.0
docker push your_docker_username/fibonacci_rust:v1.0az login
az acr login --name your_registry_name
docker tag fibonacci_rust:latest your_registry_name.azurecr.io/fibonacci_rust:v1.0
docker push your_registry_name.azurecr.io/fibonacci_rust:v1.0gcloud auth login
gcloud auth configure-docker
docker tag fibonacci_rust:latest gcr.io/your_project_id/fibonacci_rust:v1.0
docker push gcr.io/your_project_id/fibonacci_rust:v1.0aws ecr get-login-password --region your_aws_region | docker login --username AWS --password-stdin your_account_id.dkr.ecr.your_aws_region.amazonaws.com
docker tag fibonacci_rust:latest your_account_id.dkr.ecr.your_aws_region.amazonaws.com/fibonacci_rust:v1.0
docker push your_account_id.dkr.ecr.your_aws_region.amazonaws.com/fibonacci_rust:v1.0docker login your_private_registry_url
docker tag fibonacci_rust:latest your_private_registry_url/fibonacci_rust:v1.0
docker push your_private_registry_url/fibonacci_rust:v1.0Tip
Use this approach for production deployments with Prometheus monitoring and Grafana visualization.
Important
The image has been successfully pushed to Docker Hub:
- Image:
${DOCKER_USERNAME}/fibonacci_rust:v104 - Version: v104 ✅ (Latest - Clean & Fixed)
- Previous Versions:
- v103 - Ultra Fun Edition (rainbow theme)
- v102 - Modern UI with Bootstrap 5
- v101 - Fixed web UI response handling
- v100 - Initial release
- Access: Available at Docker Hub Registry
- Pull Command:
docker pull ${DOCKER_USERNAME}/fibonacci_rust:v104
✅ Changes in v104 - CLEAN & WORKING:
- 🎯 FIXED: Result now displays correctly every time!
- 📐 Vertical Layout - Clean, organized vertical sections
- 🧹 No Duplicated Content - Fixed HTML corruption
- 🚫 No Rainbow Symbols - Professional, clean design
- 🎨 Modern Gradient UI - Purple/blue gradient background
- 💎 Bootstrap 5 - Professional styling
- 📱 Fully Responsive - Works on all devices
- ⚡ Fast & Lightweight - Optimized performance
- 🎯 Loading State - Visual feedback during calculation
- ✨ Smooth Animations - Professional transitions
See the detailed instructions in sections 3. Deploying the Application to Kubernetes below.
Tip
You can build the Docker image using the provided Dockerfile, tag it, and push to Docker Hub. The latest version v104 features a clean, professional UI with working result display!
docker login --username ${DOCKER_USERNAME}
docker build -t ${DOCKER_USERNAME}/fibonacci_rust:v104 .
docker push ${DOCKER_USERNAME}/fibonacci_rust:v104Note
Version History:
- v104 ✅ - Latest (Clean UI - Fixed result display, vertical layout, no duplicates)
- v103 - Ultra Fun Edition (rainbow animations, confetti)
- v102 - Modern UI with Bootstrap 5
- v101 - Fixed web UI response handling
- v100 - Initial release
Tip
✨ UI Features in v104 - CLEAN & PROFESSIONAL:
- ✅ Working Result Display - Shows Fibonacci results correctly
- 📐 Vertical Layout - Clean, organized sections
- 🎨 Modern Gradient - Purple/blue gradient background
- 💎 Bootstrap 5 - Professional component library
- 📱 Responsive Design - Mobile, tablet, desktop optimized
- ⚡ Loading States - Visual feedback during calculations
- 🎯 Form Validation - Real-time input validation (1-50)
- ✨ Smooth Animations - Professional transitions
- 🚫 No Clutter - Clean, focused design without rainbow symbols
Tip
This repository includes a simple Terraform module (in the terraform/ directory) that deploys the fibonacci container into Kubernetes. The key files are:
- main.tf – Terraform configuration.
- Supports deploying the Docker Hub v104 image with clean UI
Tip
Navigate to the terraform/ directory and run the following commands to deploy the application with the v104 image:
terraform initterraform validateterraform apply -var="docker_username=${DOCKER_USERNAME}" -var="docker_image_tag=v104"- Once all resources are deployed you can start the minikube service to access the application.
minikube service fibonacci-service- You can go to this section to see about monitoring 3.5 Monitoring the Application with Prometheus and Grafana
Tip
This repository includes a simple Helm chart (in the fibonacci/ directory, for example) that deploys the fibonacci container into Kubernetes. The key files are:
- Chart.yaml – Chart metadata.
- values.yaml – Default values (e.g., image, replicas, etc.).
- templates/ – Contains Kubernetes manifests (Deployment, Service, etc.).
Tip
Create a secret to pull the image from Docker Hub using environment variables:
Linux/Mac:
kubectl create secret docker-registry regcred \
--docker-server=docker.io \
--docker-username=${DOCKER_USERNAME} \
--docker-password=${DOCKER_PASSWORD} \
--docker-email=${DOCKER_EMAIL}Windows (PowerShell):
kubectl create secret docker-registry regcred `
--docker-server=docker.io `
--docker-username=$env:DOCKER_USERNAME `
--docker-password=$env:DOCKER_PASSWORD `
--docker-email=$env:DOCKER_EMAILWindows (CMD):
kubectl create secret docker-registry regcred --docker-server=docker.io --docker-username=%DOCKER_USERNAME% --docker-password=%DOCKER_PASSWORD% --docker-email=%DOCKER_EMAIL%Note
Make sure to set these environment variables before running the command:
DOCKER_USERNAME: Your Docker Hub usernameDOCKER_PASSWORD: Your Docker Hub password or access tokenDOCKER_EMAIL: Your Docker Hub email
Then reference it in your values.yaml or deployment.yaml:
Tip
Add the following to your deployment.yaml file:
imagePullSecrets:
- name: regcredTip
Navigate to the fibonacci/ directory and install the Helm chart for the first time using the v104 image:
helm install fibonacci . --set image.repository=${DOCKER_USERNAME}/fibonacci_rust --set image.tag=v104Warning
Do not execute helm install again as it will overwrite the existing deployment.
Tip
If you already have the chart installed and want to upgrade it with the v104 image:
helm upgrade --install fibonacci . --set image.repository=${DOCKER_USERNAME}/fibonacci_rust --set image.tag=v104Tip
Check the deployment status:
helm status fibonacci
kubectl get pods
kubectl get services
kubectl get deploymentsTip
Launch a service to expose the application. Your default web browser will open the application.:
minikube service fibonacci-serviceTip
You can access the logs of the pod in /var/log/fibonacci.log go inside the pod and check the logs
kubectl exec -it <your-pod-name> -- /bin/sh
cat fibonacci.logTip
Port forward Prometheus to access the metrics dashboard:
kubectl port-forward svc/prometheus 9090:9090Then visit http://localhost:9090 to access the Prometheus dashboard.
Important
Port forward Grafana to access the dashboard:
kubectl port-forward deployment/grafana 3000:3000Then visit http://localhost:3000 to access the Grafana dashboard.
Default Credentials:
- Username:
admin - Password:
admin
Note
You will be prompted to change the password on first login.
- Log in to Grafana at http://localhost:3000
- Go to Configuration → Data Sources (⚙️ icon on the left sidebar)
- Click "Add data source"
- Select "Prometheus"
- Configure the data source:
- Name:
Prometheus - URL:
http://prometheus:9090 - Leave other settings as default
- Name:
- Click "Save & Test" - you should see a green success message
Tip
The URL http://prometheus:9090 works because Prometheus and Grafana are in the same Kubernetes cluster and can communicate via service names.
Important
A pre-configured dashboard JSON file is included in the project: grafana-dashboard.json
Option 1: Import via JSON File
- In Grafana, click the "+" icon on the left sidebar
- Select "Import"
- Click "Upload JSON file"
- Select the
grafana-dashboard.jsonfile from the project directory - Click "Load"
- Select the Prometheus data source you just created
- Click "Import"
Option 2: Import via JSON Content
- Open
grafana-dashboard.jsonin a text editor - Copy the entire content
- In Grafana, click "+" → "Import"
- Paste the JSON content into the text area
- Click "Load"
- Select the Prometheus data source
- Click "Import"
The Fibonacci Service Dashboard includes the following panels:
📊 Key Metrics:
-
Request Rate (req/s)
- Shows requests per second over time
- Query:
rate(requests_total[1m])
-
HTTP Status Codes (200, 400, 429, 500)
- Tracks success and error rates
- 200: Successful requests
- 400: Invalid input errors
- 429: Rate limit exceeded
- 500: Internal server errors
-
Request Duration - P99, P95, P50
- P99: 99th percentile latency (worst 1% of requests)
- P95: 95th percentile latency (worst 5% of requests)
- P50: Median latency (50th percentile)
- Query:
histogram_quantile(0.99, rate(request_duration_seconds_bucket[1m]))
-
Active Requests
- Number of requests currently being processed
- Helps identify bottlenecks
-
Total Requests
- Cumulative count of all requests since startup
-
Success Rate (%)
- Percentage of requests returning 200 OK
- Formula:
(200 requests / total requests) * 100
-
Average Response Time
- Mean response time across all requests
- Query:
rate(request_duration_seconds_sum[1m]) / rate(request_duration_seconds_count[1m])
-
Rate Limit Reached Count
- How many times the daily limit (1001 requests) was hit
-
Response Size Distribution
- P99 and P50 response sizes in bytes
-
Fibonacci Input Distribution (N values)
- Shows distribution of the 'n' parameter requested by users
Tip
Use the Makefile to generate traffic easily:
make trafficOr manually generate traffic:
# Make multiple requests
for /L %i in (1,1,100) do curl "http://localhost:8080/fibonacci?n=10"Or use PowerShell:
1..100 | ForEach-Object { Invoke-WebRequest "http://localhost:8080/fibonacci?n=10" }Or use PowerShell:
1..100 | ForEach-Object { Invoke-WebRequest "http://localhost:8080/fibonacci?n=10" }Note
After generating traffic, refresh the Grafana dashboard to see the metrics update in real-time!
All metrics exposed by the Fibonacci service:
| Metric Name | Type | Description |
|---|---|---|
requests_total |
Counter | Total number of requests |
request_duration_seconds |
Histogram | Request duration with buckets |
active_requests |
Gauge | Current active requests |
response_size_bytes |
Histogram | Response size distribution |
request_status_codes_total |
Counter | Count by status code (200, 400, 429, 500) |
request_limit_reached_total |
Counter | Times rate limit was reached |
fibonacci_n_distribution |
Histogram | Distribution of input 'n' values |
Tip
You can query these metrics directly in Prometheus at http://localhost:9090 or view them formatted at http://localhost:8080/metrics
Tip
A comprehensive Makefile is provided to simplify Grafana setup and service management!
| Command | Description |
|---|---|
make help |
Show all available commands |
make check-all |
Check if all services are running |
make grafana |
Port-forward Grafana (http://localhost:3000) |
make prometheus |
Port-forward Prometheus (http://localhost:9090) |
make fibonacci |
Port-forward Fibonacci Service (http://localhost:8080) |
make all |
Port-forward all services in separate windows |
make traffic |
Generate 100 test requests to populate metrics |
make dashboard |
Show dashboard JSON file location and info |
make setup-datasource |
Show instructions for Prometheus data source setup |
make import-dashboard |
Show instructions for importing dashboard |
make clean |
Stop all port-forward processes |
make quickstart |
Show quick start guide |
make squash-history |
Squash all git commits into a single commit |
Workflow 1: Quick Setup (Recommended)
# 1. Check all services are running
make check-all
# 2. Start all port-forwards in background
make all
# 3. Follow data source setup instructions
make setup-datasource
# 4. Follow dashboard import instructions
make import-dashboard
# 5. Generate traffic to populate metrics
make trafficWorkflow 2: Manual Control
# Terminal 1: Port-forward Grafana
make grafana
# Terminal 2: Port-forward Fibonacci Service
make fibonacci
# Terminal 3: Generate traffic
make trafficWorkflow 3: View Dashboard Info
# Show dashboard information
make dashboard
# Show setup instructions
make setup-datasource
make import-dashboardWorkflow 4: Cleanup
# Stop all port-forwards
make cleanStep 1: Verify everything is deployed
C:\Users\par_p\OneDrive\Rust\fibonacci> make check-all
"Checking if Grafana pod is running..."
NAME READY STATUS RESTARTS AGE
grafana-996d5648-z5sfv 1/1 Running 0 17m
"Checking if Prometheus pod is running..."
NAME READY STATUS RESTARTS AGE
prometheus-68f955bd68-c2qdq 1/1 Running 0 17m
"Checking if Fibonacci service is running..."
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
fibonacci-service NodePort 10.103.104.242 <none> 8080:30000/TCP 14m
========================================
All services are running!
========================================Step 2: Start port-forwarding
C:\Users\par_p\OneDrive\Rust\fibonacci> make all
Starting port-forward for ALL services...
This will open 3 command windows:
- Grafana: http://localhost:3000
- Prometheus: http://localhost:9090
- Fibonacci: http://localhost:8080
All port-forwards started in separate windows!Step 3: Generate traffic
C:\path\to\fibonacci> make traffic
Generating 100 test requests to populate metrics...
10 requests completed...
25 requests completed...
50 requests completed...
75 requests completed...
100 requests completed!Note
The Makefile works on Windows, Linux, and macOS. On Windows, it uses cmd.exe commands; on Unix systems, it uses shell commands.
Warning
This will uninstall helm release.
helm uninstall fibonacciCaution
This will delete the deployment, secret, service and the minikube cluster.
kubectl delete secret regcred
minikube deleteNote
Yes, it is possible to eliminate all previous commits and keep only a single commit representing the current state of the repository.
The squash-history Makefile target automates this process using Git's orphan branch technique:
make squash-historyThis command:
- Creates a new branch called
clean-historywith no commit history (orphan branch). - Stages all current project files.
- Creates a single
Initial commit (squashed history)commit.
You then replace the target branch with the clean history:
git push --force origin clean-history:mainWarning
git push --force rewrites public history. All collaborators must re-clone or reset their local copies afterwards. Coordinate with your team before running this on a shared branch.
# 1. Create an orphan branch (no history)
git checkout --orphan clean-history
# 2. Stage all files
git add -A
# 3. Create a single commit
git commit -m "Initial commit (squashed history)"
# 4. Replace the main branch (requires force push permission)
git push --force origin clean-history:main






