This article shows a step by step of how i accomplished my final project fro the She Code Africa Cloud School Program 2023.
I managed to complete the project within a few days and with technologies such as Docker, Azure Container registry ,Azure kubernetes Service and Azure SQL Database.
I decide to use terraform to provison the infrastructure which included :
- Azure Container Registry
- Azure Kubernetes Service
- Azure SQL Database with sample database
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.65"
}
random = {
source = "hashicorp/random"
version = "3.1.0"
}
}
}
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "emmilly-rg" {
name = "emmilly_mssql_acr_aks_rg"
location = "South Africa North"
}
resource "azurerm_container_registry" "emmilly-acr" {
name = "emmillyacr"
sku = "Premium"
resource_group_name = azurerm_resource_group.emmilly-rg.name
location = azurerm_resource_group.emmilly-rg.location
}
resource "azurerm_kubernetes_cluster" "emmilly-k8s-cluster" {
name = "emmilly-aks"
location = azurerm_resource_group.emmilly-rg.location
resource_group_name = azurerm_resource_group.emmilly-rg.name
dns_prefix = "emmilly-dns"
public_network_access_enabled = true
network_profile {
network_plugin = "kubenet"
load_balancer_sku = "standard"
}
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"
}
identity {
type = "SystemAssigned"
}
tags = {
Environment = "Production"
}
}
resource "azurerm_role_assignment" "enablePulling" {
principal_id = azurerm_kubernetes_cluster.emmilly-k8s-cluster.kubelet_identity[0].object_id
role_definition_name = "AcrPull"
scope = azurerm_container_registry.emmilly-acr.id
skip_service_principal_aad_check = true
}
resource "azurerm_mssql_server" "test-server" {
name = "sqltest-server-emmilly"
resource_group_name = azurerm_resource_group.emmilly-rg.name
location = azurerm_resource_group.emmilly-rg.location
version = "12.0"
administrator_login = "emmilly"
administrator_login_password = "emily@256"
minimum_tls_version = "1.2"
}
resource "azurerm_mssql_database" "test-db" {
name = "sqltest"
server_id = azurerm_mssql_server.test-server.id
collation = "SQL_Latin1_General_CP1_CI_AS"
license_type = "LicenseIncluded"
read_scale = false
sku_name = "S0"
zone_redundant = false
sample_name = "AdventureWorksLT"
tags = {
dev = "Production"
}
}
output "client_certificate" {
value = azurerm_kubernetes_cluster.emmilly-k8s-cluster.kube_config.0.client_certificate
}
output "kube_config" {
value = azurerm_kubernetes_cluster.emmilly-k8s-cluster.kube_config_raw
sensitive = true
}
So after i wrote the terraform file, i validated and applied the file using.
Initialise terraform in the terminal.
terraform init
terraform validate
terraform apply -auto-approve
After provisioning the resources, i could see them on my portal.
Next i added a docker file to my node js application and built an image from it and tag it
docker build . -t shecloud
docker tag shecloud <loginservername/shecloud>
Check built images with
docker images
Next we had to log into the regisrty using docker
docker login <login server name>
To see your server username an password, enable the button.
To see your registry loginserver
docker push shecloud <loginservername>/shecloud
After pushing, we should be able to see out image under repositories in the Azure Container registry.
Next login to be able to deploy to kubernetes.
az login
az account set --subscription xxxxxx-xxxx-xxxx-xxxxxx
az aks get-credentials --resource-group <resource group nae> --name <aks name>
kubectl get nodes
Next i deployed using this yaml file.
apiVersion: apps/v1
kind: Deployment
metadata:
name: azure-shecloud
spec:
replicas: 1
selector:
matchLabels:
app: azure-shecloud
template:
metadata:
labels:
app: azure-shecloud
spec:
nodeSelector:
"kubernetes.io/os": linux
containers:
- name: azure-shecloud
image: emmillyacr.azurecr.io/shecloud:latest
env:
- name: ALLOW_EMPTY_PASSWORD
value: "yes"
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 3000
name: azure-shecloud
---
apiVersion: v1
kind: Service
metadata:
name: azure-shecloud
spec:
type: LoadBalancer
ports:
- port: 3000
selector:
app: azure-shecloud
---
kubectl apply -f node_sql.yaml
Net to see the external ip Of the app we use
kubectl get svc
Next we move to the portal to the database server network allow ips access.
NB: be sure to tick the box allowing services access server.
Click save to save the changes .
When we check the External ip 20.87.94.72:3000
Top comments (0)