Skip to content

Commit

Permalink
Merge pull request #10 from Altonhe/feature/aks
Browse files Browse the repository at this point in the history
azure: add aks deployment
  • Loading branch information
aaronbrethorst committed Aug 20, 2024
2 parents da5698b + 9622236 commit b647fc5
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fi
- name: Run chart-testing (lint)
run: ct lint --validate-maintainers=false --target-branch main
run: ct lint --validate-maintainers=false --check-version-increment=false --target-branch main

- name: Create kind cluster
uses: helm/kind-action@v1.10.0
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repo is using [Opentofu](https://opentofu.org/) and other tools to create c

| | VM | Docker | K8s |
|-----------------------|------------|-----------------|--------------|
| Microsoft Azure | VM ✅ | ACI ✅ | AKS 🚧 |
| Microsoft Azure | VM ✅ | ACI ✅ | AKS |
| Amazon Web Services | EC2 ✅ | ECS(Fargate) ✅ | EKS 🚧 |
| Google Cloud Platform | GCE ✅ | Cloud Run ✅ | GKE 🚧 |
| Render || DOCKER ✅(See 1) ||
Expand Down
12 changes: 5 additions & 7 deletions charts/onebusaway/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ version.BuildInfo{Version:"v3.14.3", GitCommit:"f03cc04caaa8f6d7c3e67cf918929150

RUN the following command to install Ingress Nginx:
```bash
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx

helm repo update

helm install nginx-ingress ingress-nginx/ingress-nginx
helm upgrade --install ingress-nginx ingress-nginx \
--repo https://kubernetes.github.io/ingress-nginx \
--namespace ingress-nginx --create-namespace
```

3. Configure your domain
Expand All @@ -35,13 +33,13 @@ kubectl get svc -n ingress-nginx

4. Configure the application

Modify the `charts/values.yaml` file to configure the application. You can find the parameters meaning in [onebusaway-docker](https://github.com/OneBusAway/onebusaway-docker/#deployment-parameters).
Modify the `onebusaway/values.yaml` file to configure the application. You can find the parameters meaning in [onebusaway-docker](https://github.com/OneBusAway/onebusaway-docker/#deployment-parameters).

5. Deploy the application

You can use this command to deploy the application:
```bash
helm install onebusaway charts/
helm install onebusaway charts/onebusaway
```
Then you can check the status of the deployment by running:
```bash
Expand Down
13 changes: 8 additions & 5 deletions charts/onebusaway/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,24 @@ spec:
volumeMounts:
- mountPath: /bundle
name: bundle-volume

- name: wait-for-db
image: busybox
command: [ 'sh', '-c', 'until nc -z -v -w30 oba-database 3306; do echo "Waiting for database..."; sleep 5; done' ]

containers:
- name: oba-app
image: {{ .Values.image.oba.app.repository }}:{{ .Values.image.oba.app.tag }}
env:
- name: JDBC_URL
value: jdbc:mysql://oba-database.{{ .Values.namespace }}.svc.cluster.local:3306/oba_database
value: jdbc:mysql://oba-database:3306/oba_database
- name: JDBC_USER
value: oba_user
- name: JDBC_PASSWORD
valueFrom:
secretKeyRef:
name: oba-secrets
key: JDBC_PASSWORD
- name: GTFS_URL
value: {{ .Values.env.GTFS_URL }}
- name: TEST_API_KEY
value: {{ .Values.env.TEST_API_KEY }}
- name: VEHICLE_POSITIONS_URL
Expand Down Expand Up @@ -73,14 +76,14 @@ spec:
httpGet:
path: /onebusaway-api-webapp/api/where/current-time.json?key=org.onebusaway.iphone
port: 8080
initialDelaySeconds: 30
initialDelaySeconds: 60
periodSeconds: 10
failureThreshold: 3
readinessProbe:
httpGet:
path: /onebusaway-api-webapp/api/where/current-time.json?key=org.onebusaway.iphone
port: 8080
initialDelaySeconds: 30
initialDelaySeconds: 60
periodSeconds: 10
failureThreshold: 3
volumes:
Expand Down
1 change: 1 addition & 0 deletions charts/onebusaway/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ metadata:
{{- toYaml .Values.ingress.annotations | nindent 4 }}
{{- end }}
spec:
ingressClassName: nginx
rules:
- host: {{ .Values.ingress.host }}
http:
Expand Down
13 changes: 13 additions & 0 deletions charts/onebusaway/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ spec:
- protocol: TCP
port: 3306
targetPort: 3306
---
apiVersion: v1
kind: Service
metadata:
name: oba-app
namespace: {{ .Values.namespace }}
spec:
selector:
app: oba-app
ports:
- protocol: TCP
port: 8080
targetPort: 8080
2 changes: 1 addition & 1 deletion charts/onebusaway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ hpa:

ingress:
enabled: true
host: example.oba.com
host: oba.dmr.gg
annotations: {}
tls: false
tlsSecret: ""
Expand Down
19 changes: 19 additions & 0 deletions modules/azure-aks/.terraform.lock.hcl

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

37 changes: 37 additions & 0 deletions modules/azure-aks/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "main" {
name = var.resource_group_name
location = var.location
}

resource "azurerm_kubernetes_cluster" "main" {
name = var.aks_cluster_name
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
dns_prefix = var.dns_prefix

default_node_pool {
name = "agentpool"
node_count = 2
vm_size = "Standard_DS2_v2"
}

identity {
type = "SystemAssigned"
}

tags = var.tags
}

resource "azurerm_kubernetes_cluster_node_pool" "additional_node_pool" {
count = 0
name = "nodepool"
kubernetes_cluster_id = azurerm_kubernetes_cluster.main.id
vm_size = "Standard_DS2_v2"
node_count = 2
}


16 changes: 16 additions & 0 deletions modules/azure-aks/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
output "kube_config" {
value = azurerm_kubernetes_cluster.main.kube_config_raw
sensitive = true
}

output "resource_group_name" {
value = azurerm_resource_group.main.name
}

output "aks_cluster_name" {
value = azurerm_kubernetes_cluster.main.name
}

output "kube_config_path" {
value = "${path.module}/kubeconfig_aks"
}
81 changes: 81 additions & 0 deletions modules/azure-aks/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Deployment Guide for Azure AKS

Azure Kubernetes Service (AKS) is a managed Kubernetes service provided by Azure, it provides a wide range of features and integrations with other Azure services. This guide will show you how to deploy Onebusaway server on Azure AKS.

## Prerequisites

1. An Azure account, if you don't have one, you can create a free account [here](https://azure.microsoft.com/en-us/free/).
2. Azure CLI, you can install it by following the instructions [here](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).
3. Opentofu, an open-source Terraform alternative, you can install it by following the instructions [here](https://opentofu.org/docs/intro/install/).
4. Make sure you install *ALL* the prerequisites before you start the deployment.

## Steps

1. Clone this repository to your local machine, you can run
```bash
git clone
```

2. Change the directory to `modules/azure-aks`, you can use command
```bash
cd onebusaway-deployment/modules/azure-aks
```

3. Login to your Azure account using Azure CLI
```bash
az login
```

4. Initialize the project, this will download the necessary plugins and providers for the project
```bash
tofu init
```

5. Deploy the project
```bash
tofu apply
```

6. Configure kubectl to connect to the AKS cluster
```bash
az aks get-credentials --resource-group $(tofu output -raw resource_group_name) --name $(tofu output -raw aks_cluster_name)

# check context
kubectl config get-contexts
```

7. Access Kubernetes Dashboard
```bash
az aks browse --resource-group $(tofu output -raw resource_group_name) --name $(tofu output -raw aks_cluster_name)
```

8. Install Ingress Nginx

Here is the [recommended way](https://kubernetes.github.io/ingress-nginx/deploy/#azure) to install Ingress Nginx on AKS:
```bash
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.11.1/deploy/static/provider/cloud/deploy.yaml
```

9. Configure your domain

You should add a DNS record to your domain to point to the IP address of the Ingress Nginx controller. You can find the IP address by running:
```bash
kubectl get svc -n ingress-nginx
```
If you are using Cloudflare, you can follow the instructions [here](https://developers.cloudflare.com/dns/manage-dns-records/how-to/create-dns-records).

10. deploy OneBusAway server

Modify the `onebusaway/values.yaml` file to configure the application. You can find the parameters meaning in [onebusaway-docker](https://github.com/OneBusAway/onebusaway-docker/#deployment-parameters).
You can use this command to deploy the application:
```bash
helm install onebusaway ../../charts/onebusaway
```
Then you can check the status of the deployment by running:
```bash
kubectl get pods -n oba
```

11. Access the OneBusAway server

You can access the OneBusAway server by visiting the domain you configured in step 9.
31 changes: 31 additions & 0 deletions modules/azure-aks/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
variable "location" {
description = "The location where the resources will be created."
default = "East US"
type = string
}

variable "resource_group_name" {
description = "The name of the resource group"
default = "aks-rg"
type = string
}

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

variable "dns_prefix" {
description = "The DNS prefix for the AKS cluster."
default = "aks"
type = string
}

variable "tags" {
description = "Tags to apply to resources"
type = map(string)
default = {
environment = "dev"
}
}

0 comments on commit b647fc5

Please sign in to comment.