Skip to content

paraskuk/Fibonacci-Rust-Kubernetes-Deployment-Command-Line-POC-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Rust_programming_language_black_logo svg

Rust App that calculates the Fibonacci sequence and deploys it to Kubernetes

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 using Helm charts using minikube.

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.

Tip

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.

Prerequisites

Important

Before you begin, ensure you have the following tools installed:

  1. Rust & Cargo (for local builds/verification, optional if you only build in Docker).
  2. Docker (to build and push container images).
  3. Helm (to manage Kubernetes deployments).
  4. Minikube or a Kubernetes Cluster (for testing).
  5. Docker Hub Account (to push container images).

1. Building the Rust Application Locally (Optional)

You can verify that the application compiles and runs locally:

Tip

You can build the Rust application using Cargo:

cargo run --package fibonacci --bin fibonacci -- 10

# Output:
Time taken by fibonacci_match: ...
Time taken by fibonacci_memo: ...
Time taken by fibonacci_iterative: ...

2. Building the Docker Image

Tip

You can build the Docker image using the provided Dockerfile Tag the image after its building Using your username login to Docker Hub and push the image to Docker Hub.

docker build -t fibonacci_rust:latest .
docker tag fibonacci_rust:latest ${DOCKER_USERNAME}/fibonacci_rust:latest
docker login --username ${DOCKER_USERNAME}
docker push ${DOCKER_USERNAME}/fibonacci_rust:latest
docker tag fibonacci_rust:latest ${DOCKER_USERNAME}/fibonacci_rust:v2
docker push ${DOCKER_USERNAME}/fibonacci_rust:v2

3. Deploying the Application to Kubernetes

3.0 Deploy using Manifests

Tip

You can deploy the application to Kubernetes using the provided deployment.yaml file:

kubectl apply -f deployment.yaml

3.1 Or Deploy via Helm Charts - Helm Chart Overview

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.).

3.2 Creating Secret

Tip

Create a secret to pull the image from Docker Hub:

kubectl create secret docker-registry regcred \
--docker-server=docker.io \
--docker-username=myusername \
--docker-password=MY_PERSONAL_ACCESS_TOKEN \
[email protected]

Then reference it in your values.yaml or deployment.yaml:

Tip

Add the following to your deployment.yaml file:

imagePullSecrets:
- name: regcred

3.3 Install Helm Chart

Tip

Navigate to the fibonacci/ directory and install the Helm chart for the first time:

helm install fibonacci .

Tip

If you already have the chart installed and want to upgrade it:

helm upgrade --install fibonacci .

Tip

Check the deployment status:

helm status fibonacci
kubectl get pods

3.4 Accessing the Application

This program just prints to the STDOUT

Tip

You can access the logs of the fibonacci-deployment pod to see the output.

kubectl logs deployment/fibonacci-deployment

4 .Cleaning Up

Warning

This will uninstall helm release.

helm uninstall fibonacci

Caution

This will delete the deployment and service and the minikube cluster.

kubectl delete secret regcred
minkube delete

About

Command Line POC App in Rust with Kubernetes Deployment

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published