Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file added Docker Image documentation.odt
Binary file not shown.
21 changes: 21 additions & 0 deletions aks-terraform/aks-cluster-module/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
resource "azurerm_kubernetes_cluster" "aks-cluster" {
name = var.aks_cluster_name
location = var.cluster_location
resource_group_name = var.resource_group_name
dns_prefix = var.dns_prefix
kubernetes_version = var.kubernetes_version
}

default_node_pool {
name = "default"
node_count = 1
vm_size = "standard_DS2_v2"
enable_auto_scaling = true
min_count = 1
max_count = 3
}

service_principal {
client_id = var.service_principal_client_id
client_secret = var.service_principal_secret
}
14 changes: 14 additions & 0 deletions aks-terraform/aks-cluster-module/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "aks_cluster_name" {
description = "Name of the AKS cluster"
value =
}

output "aks_cluster_id" {
description = "ID of the AKS cluster"
value =
}

output "aks_kubeconfig" {
description = "Kubeconfig file for accessing the AKS cluster."
value =
}
64 changes: 64 additions & 0 deletions aks-terraform/aks-cluster-module/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# input variables

variable "aks_cluster_name" {
description = "The name of the AKS cluster to be created."
  type        = string
default = "aks-cluster"
 }

variable "cluster_location" {
description = "Specfies the Azure region where the AKS cluster would be deployed to"
type = string
default = "UK South"
}

variable "dns_prefix" {
description = "Defines the DNS prefix of cluster"
type = string
}

variable "kubernetes_version" {
description = "Specifies which Kubernetes version the cluster would use"
type = string
default = "1.26.6"
}

variable "service_principal_client_id" {
description = "Provides the Client ID for the service principal associated with cluster"
type = string
default = "549b492c-2de8-4e83-84fe-d55e63b066bf"
}

varaible "service_principal_secret" {
description = "Supplies the Client secret for the service principal"
type = string
default = "KHL8Q~a954lzhfeG.Qqut942LABjem28J_cMwdgY"
}

# Adding the following output variables from networking module as input
# varables.

output "vnet_id" {
description = "For storing the id of the previously created vnet"
value = azure_resource_group.aks_vnet.name
}

output "control_plane_subnet_id" {
description = "For storing the ID of the control plane subnet within the Vnet"
value = azure_resource_group.aks_vnet.control_plane_subnet.name
}

output "worker_node_subnet_id" {
description = "For storing the ID of the worker node subnet within the Vnet"
value = azure_resource_group.aks_vnet.worker_node_subnet.name
}

output "networking_resource_group_name" {
description = Azure Resource Group where the networking resources were provisioned in."
value = var.azure_resource_group.name
}

output "aks_nsg_id" {
description = "store the ID of the Network Security Group (NSG)."
value = azure_resource_group.aks-nsg.name
}
40 changes: 40 additions & 0 deletions aks-terraform/application-manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apiVersion: apps/v1
kind: Deployment
metadata:
  name: flask-app-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: flask-app
  template:
    metadata:
      labels:
        app: flask-app
    spec:
      containers:
        - name: web-app-container
          image: <whule>/flask-app:v1
          ports:
          - containerPort: 5000
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 1
      maxSurge: 1

---

apiVersion: v1
kind: service
metadata:
  name: flask-app-service
spec:
    selector:
    matchLabels:
      app: flask-app
  ports:
- protocol: TCP
port: 80 # port for iternal communication within the cluster location
  targetport: 5000 # port exposed by your computer
type: ClusterIP
16 changes: 16 additions & 0 deletions aks-terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azure"
      version = "=3.0.0"
    }
  }
}

provider "azurerm" {
  features {}
  client_id       = "549b492c-2de8-4e83-84fe-d55e63b066bf"
  client_secret   = "KHL8Q~a954lzhfeG.Qqut942LABjem28J_cMwdgY"
  subscription_id = "8ab233ac-c619-4888-bf7a-422ea867b8d8"
  tenant_id       = "47d4542c-f112-47f4-92c7-a838d8a5e8ef"
}
57 changes: 57 additions & 0 deletions aks-terraform/network-module/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
resource "azure_resource_group" "aks-resources" {
name = var.resource_group_name
location = "UK South"
}

resource "virtual_network" "aks-vnet" {
name = "aks-vnet"
address_space = ["10.0.0.0/16"]
}

resource "control_plane_subnet" "control-plane-subnet"{
name = "control-plane-subnet"
virtual_network_name = virtual_network.aks_net.name

}
resource "worker_node_subnet" "worker-node-subnet" {
name = "worker-node-subnet"
virtual_network_name = virtual_network.aks-vnet.name
address_prefixes = ["10.0.1.0/24"]

}

resource "network_security_group" "aks-nsg" {
name = "aks-nsg"
resource_group_name = var.resource_group_name
location = var.location
}

resource "network_security_rule" "kube-apiserver-rule" {
name = "kube-apiserver-rule"
resource_group_name = "var.resource_group_name"
networking_security_group_name = network_security_group.aks_nsg.name
priority = 1001
direction = "Inbound"
access = "Allow"
protocol = "TCP"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"

}

resource "network_security_rule" "ssh-rule" {
name = "ssh-rule"
resource_group_name = "var.resource_group_name"
network_security_group_name = network_security_group.aks_nsg.name
priority = 1002
direction = "Inbound"
access = Allow
protocol = "TCP"
source_port_range = "*"
destination_port_range = "80"
source_address_prefix = "*"
destination_address_prefix = "*"

}
26 changes: 26 additions & 0 deletions aks-terraform/network-module/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
output "vnet_id" {
description = "For storing the ID of the previously created vnet"
value = azure_resource_group.aks-vnet.name
}

output "control_plane_subnet_id" {
description = "For storing the Id of the control plane subnet within the vnet"
value = azure_resource_group.aks-vnet.control_plane_subnet_id.name

}

output "worker_node_subnet_id" {
description = "For storing the Id of the worker node subnet within the vnet"
value = azure_resource_group.aks-vnet.worker_node_subnet_id.name
}

output "networking_resource_group_name" {
description = "Azure resource group for provisioning the network group"
value = var.resource_group_name.default
}

output "aks_nsg_id" {
description = " To store the ID of the network security group (NSG)"
value = azure_resource_group.aks_nsg.name

}
17 changes: 17 additions & 0 deletions aks-terraform/network-module/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "resource_group_name" {
description = "The name of the Azure Resource group"
type = string
default = "aks-resource"
}

variable "location" {
description = "Azure region where the networking resources will be deployed"
type = string
default = "UK South"
}

variable "vnet_address_space" {
description = "Specifies the address space for the virtual network (Vnet)"
type = list(string)
default = ["10.0.0.0/16"]
}
13 changes: 9 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Initialise Flask App
app = Flask(__name__)

# database connection
# database connection
server = 'devops-project-server.database.windows.net'
database = 'orders-db'
username = 'maya'
Expand Down Expand Up @@ -39,6 +39,7 @@
class Order(Base):
__tablename__ = 'orders'
date_uuid = Column('date_uuid', String, primary_key=True)
delivery_date = column('Delivery Date', DateTime)
user_id = Column('User ID', String, primary_key=True)
card_number = Column('Card Number', String)
store_code = Column('Store Code', String)
Expand Down Expand Up @@ -78,14 +79,17 @@ def display_orders():
@app.route('/add_order', methods=['POST'])
def add_order():
date_uuid = request.form.get('date_uuid')
delivery_date = request.form['delivery_date']
user_id = request.form.get('user_id')
card_number = request.form.get('card_number')
store_code = request.form.get('store_code')
product_code = request.form.get('product_code')
product_quantity = request.form.get('product_quantity')
order_date = request.form.get('order_date')
shipping_date = request.form.get('shipping_date')




# Create a session to interact with the database
session = Session()

Expand All @@ -98,7 +102,8 @@ def add_order():
product_code=product_code,
product_quantity=product_quantity,
order_date=order_date,
shipping_date=shipping_date
shipping_date=shipping_date,
delivery_date=delivery_date
)

# Add the new order to the session and commit to the database
Expand All @@ -109,4 +114,4 @@ def add_order():

# run the app
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)
app.run(host='0.0.0.0', port=5000, debug=True)
18 changes: 18 additions & 0 deletions docker-image-documentation.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Docker Image documentation

Created a docker container image named dockerfile to include the following steps:
• Step 1 - Use an official Python runtime as a parent image. (used `python:3.8-slim`)
• Step 2 - Set the working directory in the container. Used WORKDIR /app.
• Step 3 - Copy the application files in the container. Used the command (COPY . .)
• Step 4 - Install system dependencies and ODBC driver.
• Step 5 - Install pip and setuptools.
• Step 6 - Install Python packages specified in requirements.txt.
• Step 7 - Expose port (EXPOSE 5000)
• Step 8 - Define Startup Command (CMD ["python", "app.py"])
Next, build the docker container image with the command:
>docker build -t dockerfile .
Next, run the docker container using the command that includes the exposed port as in the docker image:
>docker run -p 5000:5000 dockerfile
Next, Open a web browser and go to http://127.0.0.1:5000 to interact with the application within the Docker container to confirm the application works.
Next, Tag and push the docker container image to docker hub. First login to docker using the command in the command line: docker tag dockerfile whule/dockerfile (note that dockerfile is the name of the docker container image).
Then push the container image to docker hub with this command: docker push whule/dockerfile (Note that whule is my docker hub userid and dockerfile is the docker container image name)
32 changes: 32 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# TODO: Step 1 - Use an official Python runtime as a parent image. You can use `python:3.8-slim`.
FROM python:3.8-slim-buster

# TODO: Step 2 - Set the working directory in the container
WORKDIR /app

# TODO: Step 3 Copy the application files in the container
COPY . .

# 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

# TODO: Step 4 - Install Python packages specified in requirements.txt
RUN pip install -r requirements.txt

# TODO: Step 5 - Expose port
EXPOSE 5000

# TODO: Step 6 - Define Startup Command
CMD ["python", "app.py"]
Loading