/SCA-Cloud-Bootcamp-4

This is my final project submission for the She Code Africa Cloud School Bootcamp (Cohort 4). My topic is on Containers & Kubernetes. I will deploy a web app on an Azure managed Kubernetes service (AKS).

Primary LanguageCSS

SCA-Cloud-Bootcamp-4

This is my final project submission for the She Code Africa Cloud School Bootcamp (Cohort 4). My topic is Containers & Kubernetes.

I created the infrastructure:

  • Azure managed Kubernetes service (AKS)
  • Storage account (to keep my Terraform state files, Helm repo) using Terraform, then I deployed a web app on AKS via Azure Pipelines (CI/CD).

Every time I make a push to my git repo, the image is re-built, stored as a build artifact, and then deployed to my AKS cluster.

Architectural Diagram

image

Setting Up the app on my local computer

The application fetches and displays a GitHub user's profile. It calls the Github API, to display the profile of any username typed in the search box.

$ python3-m venv venv
$ source venv/bin/activate
$ pip install --upgrade pip
$ pip install -r requirements.txt
$ python3 main.py
image image

http://127.0.0.1:5500/

Dockerize the app

$ docker login
$ docker build -t <docker-hub-username>/<image-name>:tag .
$ docker push <docker-hub-username>/<image-name>:tag

Setting up my Azure Devops Workspace

  • Create a project in your workspace.
image

Create infrastructure using Terraform

  • Run the scripts in the infrastructure folder.
$ cd terraform
$ az login
$ terraform init
$ terraform fmt
$ terraform validate
$ terraform plan
$ terraform apply
Screenshot 2023-05-20 at 04 52 50

Setup Azure Pipeline

  • Create an Azure Resource Manager service connection.

Create a default Agent pool

  • Guide. This means the tasks and jobs will be executed on your local machine. This allows you to leverage the resources and capabilities of your local machine for building, testing, and deploying your applications.

I did this because I had to request for free parallelism and it will take some days before my request is approved.

image

CI

  • Builds the Docker image and saves it as an artifact. Run the command below (to start the agent pool) before making a push to GitHub. Also, ensure Docker desktop is running in the backgrouund.
$ ./run.sh 
  • Connect your GitHub Repo to Azure DevOps
Screenshot 2023-05-18 at 13 30 25 Screenshot 2023-05-18 at 13 33 31
  • Configuring my CI pipeline: start with a simple workflow option and add extra configuration as needed.
image

CD (Release Pipeline)

Use Helm to deploy your image on the AKS cluster.

  • First, install Helm, the config files can be found in the myhelm folder.
  • Create and apply a secrets.yaml file in the myhelm/templates folder.
$ touch secrets.yaml
$ kubectl -f apply myhelm/templates secrets.yaml
  • Then create a Helm repo and add a Chart to the repo:
$ cd myhelm
$ helm package .
$ helm repo index .
  • Upload the index.yaml and the folder with the .tgz extension, to your Azure storage container created above. Then run:
$ helm repo add <repository-name> <repository-url>

Notes:

  • The is the URL of the index.yaml file stored in the storage container.
  • For every change made to the config files, push the index and zip to storage account
  • Verify chart is available
$ helm search repo <chart-name>
  • Fetch chart information
$ helm repo update 
  • Configuring the CD pipeline Stage 1
Screenshot 2023-05-18 at 18 50 48

Stage 2 image

  • Setting the trigger
Screenshot 2023-05-20 at 04 21 05

Putting it all together

  • Whenever a push is made to the GitHub repository, the CI pipeline is triggered, once the build is successful, the CD pipeline kicks off.
  • You can access your cluster's external IP and port by running:
$ kubectl get services
Screenshot 2023-05-20 at 05 15 33

Live link: http://52.189.27.203:5500/