Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a172d79
Revert "updates repo with files needed for students"
chyjuls Jan 13, 2024
e902dfc
My Dockerfile added to my repo
chyjuls Jan 14, 2024
3d0e211
Updates the terraform-project and all modules
chyjuls Jan 14, 2024
266d8cb
aks-terraform directory now contains only modules directory
chyjuls Jan 16, 2024
cbd147a
Add .DS_Store to .gitignore
chyjuls Jan 16, 2024
b705f61
Update README.md
chyjuls Jan 16, 2024
1986822
Update README.md
chyjuls Jan 16, 2024
21842aa
Updates the terraform project folder with aks-cluster-module directory
chyjuls Jan 16, 2024
8fe2032
Merge pull request #6 from chyjuls/terraform-branch
chyjuls Jan 16, 2024
2734c93
Terraform project updated, app now provisioned on aks
chyjuls Jan 17, 2024
78e06e2
Merge pull request #7 from chyjuls/terraform-branch
chyjuls Jan 17, 2024
00f3f80
Update README.md
chyjuls Jan 17, 2024
eaf1308
Updates app deployment with AKS
chyjuls Jan 18, 2024
fa3053a
Merge pull request #8 from chyjuls/terraform-branch
chyjuls Jan 18, 2024
07da443
Updates README.md
chyjuls Jan 18, 2024
261354f
Update README.md
chyjuls Jan 18, 2024
83d16f5
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
aa4dab3
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
8394061
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
eb2acb8
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
9104135
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
7ef3ab5
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
ac85d0c
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 19, 2024
a23ddf7
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 22, 2024
dec2298
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 22, 2024
a8aed4f
Updates Dockerfile
chyjuls Jan 22, 2024
7d52d09
Merge pull request #9 from chyjuls/terraform-branch
chyjuls Jan 22, 2024
43caf17
Removes the incorrect syntax /ubuntu from file
chyjuls Jan 22, 2024
6d2ea23
Merge pull request #10 from chyjuls/terraform-branch
chyjuls Jan 22, 2024
914f6e5
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 22, 2024
522fe1e
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 22, 2024
0e2e066
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 22, 2024
36a2466
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 22, 2024
259d33c
Updates the application-manifest.yaml file
chyjuls Jan 22, 2024
6b99621
Merge pull request #11 from chyjuls/terraform-branch
chyjuls Jan 22, 2024
3fe9d4a
Remove azure-pipelines-1.yml
chyjuls Jan 22, 2024
07473ee
Merge pull request #12 from chyjuls/terraform-branch
chyjuls Jan 22, 2024
dab6c26
Updates README.md with latest project tasks
chyjuls Jan 22, 2024
120d976
Update README.md
chyjuls Jan 22, 2024
2ae0fc5
Update README.md
chyjuls Jan 27, 2024
21b198d
Update README.md
chyjuls Jan 28, 2024
2be901e
Updates app.py and requirements.txt with azure key vault packages and…
chyjuls Jan 29, 2024
f7829af
Updates all files in the directory
chyjuls Jan 29, 2024
a84ce38
Merge pull request #13 from chyjuls/terraform-branch
chyjuls Jan 29, 2024
5994611
Updates app.py file
chyjuls Jan 29, 2024
dca8318
Updates app.py with vault name
chyjuls Jan 31, 2024
3c8fcdf
Merge pull request #14 from chyjuls/terraform-branch
chyjuls Jan 31, 2024
b2de60b
Updates file with correct docker image name
chyjuls Jan 31, 2024
e67928b
Merge pull request #15 from chyjuls/terraform-branch
chyjuls Jan 31, 2024
0c913c1
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 31, 2024
9d4db31
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 31, 2024
103924a
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 31, 2024
e1629fb
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 31, 2024
2652391
Update azure-pipelines.yml for Azure Pipelines
chyjuls Jan 31, 2024
90bb42e
Updates both files with latest at image tag
chyjuls Jan 31, 2024
053fc4a
Updates file with correct docker image tag
chyjuls Jan 31, 2024
552bb61
Merge branch 'main' into terraform-branch
chyjuls Jan 31, 2024
b16375c
Updates the aks-terraform sub dir
chyjuls Jan 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
36 changes: 36 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Use an official Python runtime as a parent image
# Using a specific image for M1/M2 chip Mac users
ARG ARCH

FROM python:3.9
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.9.10-slim-buster

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Install system dependencies and ODBC driver
RUN apt-get update && apt-get install -y \
unixodbc unixodbc-dev odbcinst odbcinst1debian2 libpq-dev gcc && \
apt-get install -y gnupg && \
apt-get install -y wget && \
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | apt-key add - && \
wget -qO- https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list && \
apt-get update && \
ACCEPT_EULA=Y apt-get install -y msodbcsql18 && \
# apt-get purge -y --auto-remove wget && \
apt-get clean

# Install pip and setuptools
RUN pip install --upgrade pip setuptools

# Install Python packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

# Expose port 5000 (change to your desired port)
EXPOSE 5000

# Run app.py when the container launches
CMD ["python", "app.py"]
281 changes: 280 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Web-App-DevOps-Project

Welcome to the Web App DevOps Project repo! This application allows you to efficiently manage and track orders for a potential business. It provides an intuitive user interface for viewing existing orders and adding new ones.
Welcome to the Web App DevOps Project repo! This application allows you to efficiently manage and track orders for a potential business. It provides an intuitive user interface for viewing existing orders and adding new ones. This is the finally project for AI core students who are on the DevOps pathway.Although the repo is forked, files have been replaced with my personal project files.

## Table of Contents

Expand Down Expand Up @@ -53,9 +53,288 @@ To run the application, you simply need to run the `app.py` script in this repos

- **Database:** The application employs an Azure SQL Database as its database system to store order-related data.



## Terraform Project Documentation

**Overview**

Terraform by HashiCorp is an Infrastructure as Code (IaC) tool used for building, changing, and versioning infrastructure safely and efficiently. It supports various cloud providers like Azure, AWS, and Google Cloud. Terraform uses declarative configuration files that describe the desired state of your infrastructure.

**Key Concepts**

Infrastructure as Code (IaC): Manage infrastructure using configuration files rather than through manual processes.

Providers: Plugins that interact with APIs of cloud providers, services, or other tools (e.g., Azure, AWS).
Resources: Components of your infrastructure such as virtual networks, compute instances, or higher-level components like DNS records.
Modules: Reusable, encapsulated Terraform configurations for creating sets of resources that are used together.
State: Terraform records information about what infrastructure is created in a state file, allowing for consistent management of resources.
Terraform Workflow
Initialize:

Run terraform init in your project directory.
This command sets up Terraform's working directory, downloads providers, and prepares the backend for state storage.
Writing Configuration:

Define your infrastructure in configuration files (.tf).
Resources, variables, outputs, and provider configurations are declared here.
Planning:

Execute terraform plan.
Terraform reads configuration files and creates an execution plan, detailing what actions it will perform to reach the desired state.
Applying:

Run terraform apply.
Terraform will execute the plan to create, update, or delete resources as per the configuration.
Maintaining State:

Terraform maintains a state file to map resources to the configuration and keep track of metadata.
The state file is critical for Terraform to function correctly and should be handled with care.
Modifying Infrastructure:

Update configuration files as needed.
Rerun terraform plan and terraform apply to implement changes.
Destroying Infrastructure:

To remove all resources managed by Terraform, use terraform destroy.

**Best Practices**

Version Control: Keep your Terraform configurations in a version control system (like Git).
Modularization: Use modules to organize and reuse code.
Secrets Management: Avoid hardcoding sensitive information. Use environment variables or secret management tools.
Review Plans: Carefully review execution plans before applying changes.


## AKS Cluster Provisioning with Terraform

**Overview**

This project automates the deployment of an Azure Kubernetes Service (AKS) cluster using Terraform, an Infrastructure as Code tool. The project is structured into modules, with specific focus on the aks-cluster-module for creating and managing the AKS cluster.

**Prerequisites**

Azure account and Azure CLI installed and configured
Terraform v0.12+ installed

**Module Structure**

aks-cluster-module: Contains Terraform configurations to set up the AKS cluster in Azure.
Usage

**Step 1: Initialize the Module**

Navigate to the aks-cluster-module directory and run the initialization command:

cd modules/aks-cluster-module
terraform init

**Step 2: Configuration**

Edit the variables.tf file to configure the desired settings for your AKS cluster.

**Step 3: Apply the Configuration**

Run the following commands to apply the configuration:

terraform plan
terraform apply

### Inputs and Outputs

**Input Variables**

aks_cluster_name: Name of the AKS cluster.
cluster_location: Azure region where the AKS cluster will be deployed.
dns_prefix: DNS prefix for the AKS cluster.
kubernetes_version: Version of Kubernetes for the AKS cluster.
service_principal_client_id: Client ID for the service principal.
service_principal_secret: Client Secret for the service principal.
Additional networking-related variables.

**Output Variables**

aks_cluster_name: The name of the provisioned AKS cluster.
aks_cluster_id: The ID of the provisioned AKS cluster.
aks_kubeconfig: Kubernetes configuration file for the AKS cluster.


# Infrastructure Provisioning with Terraform

**Overview**

This project utilizes Terraform for the automated provisioning of infrastructure in Azure, specifically focusing on setting up an Azure Kubernetes Service (AKS) cluster and associated networking resources.

**Infrastructure Components**

Azure Resource Group: Serves as a logical container for grouping related resources.
Virtual Network (VNet): Provides networking for AKS, including control plane and worker node subnets.
Subnets: Two subnets, one for the control plane and one for the worker nodes.
Network Security Group (NSG): Manages network security rules for secure access to the AKS cluster.
AKS Cluster: The central Kubernetes cluster managed by Azure.
Setup and Configuration
Terraform is used to define and manage the above resources.
The configuration is divided into modules for better organization and reusability.
Variables are used to ensure configurability and flexibility of the setup.
Troubleshooting Steps Undertaken
Throughout the setup, several issues were encountered and resolved:

Service Principal Authentication: Initially faced issues with Azure Service Principal permissions. Resolved by assigning the appropriate roles to the Service Principal.

Resource Provider Registration: Encountered a MissingSubscriptionRegistration error. This was fixed by manually registering the Microsoft.ContainerService provider with the Azure subscription.

Permission Issues for Resource Group Creation: Faced AuthorizationFailed errors when attempting to create resource groups. This was resolved by ensuring the Service Principal had sufficient permissions.

Namespace Registration: Addressed errors related to the subscription not being registered to use certain Azure services (namespaces).

**Commands Used**

terraform init: To initialize the Terraform environment.
terraform plan: To preview the changes before applying.
terraform apply: To apply the changes and provision the infrastructure.
Conclusion
The project demonstrates the power of Infrastructure as Code (IaC) using Terraform, showcasing how complex infrastructure can be provisioned, managed, and troubleshooted systematically.

# Kubernetes Deployment Documentation

### Deployment and Service Manifests

This application is deployed on Azure Kubernetes Service (AKS) using Kubernetes manifests. These manifests define the desired state of our application's deployment and service in the cluster.

### Key Components:
Deployment Manifest: The deployment manifest (deployment.yaml) specifies our application's deployment configuration. It includes the following key settings:

**Pod Template**: Defines the container image to use (chyjuls/web-delivery:v1) and necessary environment variables.
**Replicas**: Sets the number of pod replicas for high availability.
**Resource Requests/Limits**: Configures CPU and memory resources for each pod.
**Readiness and Liveness Probes**: Ensures that the application is running correctly and is ready to receive traffic.
**Service Manifest**: The service manifest (service.yaml) defines how the application's pods are exposed within the cluster. It includes:
**Type**: Determines how the service is exposed. For internal use, we use ClusterIP; for external access, LoadBalancer can be used.
**Port Mapping**: Maps the port from the pod to the service.

### Deployment Strategy

For our application, we've chosen a rolling update deployment strategy. This approach ensures zero downtime during updates, gradually replacing instances of the older version of our application with the new version.

**Benefits**:
Zero Downtime: Ensures that the application remains available to users during deployment.
Rollback Capabilities: Allows for easy rollback to the previous version if issues arise.
Testing and Validation
Post-deployment, we conducted several tests to ensure the application's functionality and reliability:

**Connectivity Test**: Verified that the application's pods are accessible and running as expected using kubectl get pods.
**Functionality Test**: Used port forwarding (kubectl port-forward) to temporarily access the application and test its core functionalities, including the orders table and Add Order feature.

### Internal and External Access

**Internal Access**:
For internal users, the application can be accessed through an internal load balancer or ingress controller within the AKS cluster. This approach allows employees to access the application without exposing it to the public internet.

We plan to set up an ingress controller that routes internal traffic to the application based on URL paths.

**External Access**:

To make the application accessible to external users, we can expose it through an external load balancer or ingress controller with proper security measures in place.

**Key considerations for external access include**:
- TLS/SSL Certificates: For secure HTTPS access.
- Authentication and Authorization: To control access to the application.
- Monitoring and Logging: To track usage and potential security incidents.



# CI/CD Pipeline Setup

## Overview
This project includes a Continuous Integration/Continuous Deployment (CI/CD) pipeline, which automates the process of testing, building, and deploying the application. The pipeline is defined in the azure-pipeline.yaml file and utilizes Azure DevOps for execution.

### azure-pipeline.yaml**

The azure-pipeline.yaml file defines the pipeline's stages, jobs, and steps. It is structured as follows:

**Trigger**: Specifies the branch(es) that will trigger the pipeline.
**Variables**: Defines the variables used across the pipeline.
**Stages**: Organizes the pipeline into distinct stages such as Build, Test, and Deploy.
**Build Stage**: Compiles the code, runs tests, and builds the Docker image. The image is then pushed to a Docker registry.
**Deploy Stage**: Handles the deployment of the built image to the Kubernetes cluster.

### Kubernetes Manifest File

The Kubernetes manifest file, located at [path-to-manifest-file], is crucial for the deployment process. It defines the desired state of the application in the Kubernetes cluster. Key components include:

**Deployment**: Specifies the container image to use, the number of replicas, and configuration like environment variables and resource limits.
**Service**: Defines how the application is exposed within the Kubernetes cluster or to the outside world, like LoadBalancer or NodePort services.

### CI/CD Pipeline Flow

**Code Commit**: A commit to the specified branch triggers the pipeline.
**Build**: The application is built, and a Docker image is created.
**Test**: Automated tests are run to ensure code reliability.
**Docker Push**: The Docker image is pushed to the registry.
**Deployment**: The application is deployed to the AKS cluster using the Kubernetes manifest file.
**Post-Deployment**: The pipeline performs any post-deployment steps like health checks or notifications.

### Conclusion
The CI/CD pipeline ensures that every code change is automatically tested and deployed, maintaining the reliability and stability of the application. This automation streamlines the development process, reduces manual errors, and ensures quicker delivery of features and fixes.



# Monitoring Strategy for AKS Cluster


## Metrics Explorer Charts
The AKS cluster monitoring utilizes Azure Monitor's Metrics Explorer to visualize key performance indicators. Below are the specific charts utilized, their significance, and interpretation guidelines:

1. Average Node CPU Usage

**Significance**: This chart tracks the CPU usage across all nodes, providing insights into the computational load and identifying potential bottlenecks.
**Metrics Tracked**: CPU utilization percentage.
Interpretation: Values nearing 100% indicate high CPU load, suggesting the need for scaling or optimization.

2. Average Node Memory Usage

**Significance**: Monitors memory consumption, crucial for ensuring applications have sufficient resources and for detecting memory leaks.
**Metrics Tracked**: Memory utilization percentage.
Interpretation: High memory usage close to the node capacity may require scaling or investigating potential memory leaks.

3. Pod Count by Phase

**Significance**: Offers a snapshot of pod distribution by their lifecycle phase, useful for understanding cluster workload and deployment health.
**Metrics Tracked**: Count of pods in phases like Running, Pending, Failed, etc.
Interpretation: An unusual increase in Pending or Failed pods may indicate issues with scheduling or application errors.

## Log Analytics

Azure Log Analytics is used to parse and analyze logs from the AKS cluster. Key logs include:

1. Node and Pod Logs
**Content**: Include metrics on operations, performance, and errors at both the node and pod levels.
**Relevance**: Helps in diagnosing system-level and application-level issues.

2. Container Logs
**Content**: Capture stdout and stderr from containers, including application logs.
**Relevance**: Critical for troubleshooting application-specific issues.


## Alarm Configurations

1. CPU Usage Alarm
**Condition**: Triggered when CPU usage exceeds 80% for over 5 minutes.
**Threshold**: >80% CPU utilization.
**Response Strategy**: Investigate running pods and services for optimization or scale up the cluster.

2. Memory Usage Alarm
**Condition**: Fires when memory usage surpasses 80% for a continuous 5-minute window.
**Threshold**: >80% memory utilization.
**Response Strategy**: Check for memory-intensive applications, consider scaling or optimizing pod configurations.




## Contributors

- [Maya Iuga]([https://github.com/yourusername](https://github.com/maya-a-iuga))
- C.Ugorji (AI core DevOps Student)

## License

Expand Down
Binary file added aks-terraform/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions aks-terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.tfstate
*.tfvars
.terraform/
21 changes: 21 additions & 0 deletions aks-terraform/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading