From 5b65a5118b3633870df7527cbf271e70d9d7a675 Mon Sep 17 00:00:00 2001 From: Altonhe Date: Fri, 16 Aug 2024 21:40:20 -0400 Subject: [PATCH 1/3] azure: add aks deployment --- README.md | 2 +- charts/onebusaway/readme.md | 12 ++- charts/onebusaway/templates/deployment.yaml | 13 ++-- charts/onebusaway/templates/ingress.yaml | 1 + charts/onebusaway/templates/service.yaml | 13 ++++ charts/onebusaway/values.yaml | 2 +- modules/azure-aks/.terraform.lock.hcl | 19 +++++ modules/azure-aks/main.tf | 37 ++++++++++ modules/azure-aks/outputs.tf | 16 ++++ modules/azure-aks/readme.md | 81 +++++++++++++++++++++ modules/azure-aks/variables.tf | 27 +++++++ 11 files changed, 209 insertions(+), 14 deletions(-) create mode 100644 modules/azure-aks/.terraform.lock.hcl create mode 100644 modules/azure-aks/main.tf create mode 100644 modules/azure-aks/outputs.tf create mode 100644 modules/azure-aks/readme.md create mode 100644 modules/azure-aks/variables.tf diff --git a/README.md b/README.md index 07de079..864e312 100644 --- a/README.md +++ b/README.md @@ -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) | ❌ | diff --git a/charts/onebusaway/readme.md b/charts/onebusaway/readme.md index e2e1fd5..701b174 100644 --- a/charts/onebusaway/readme.md +++ b/charts/onebusaway/readme.md @@ -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 @@ -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 diff --git a/charts/onebusaway/templates/deployment.yaml b/charts/onebusaway/templates/deployment.yaml index 043287b..091105d 100644 --- a/charts/onebusaway/templates/deployment.yaml +++ b/charts/onebusaway/templates/deployment.yaml @@ -26,12 +26,17 @@ 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 @@ -39,8 +44,6 @@ spec: 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 @@ -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: diff --git a/charts/onebusaway/templates/ingress.yaml b/charts/onebusaway/templates/ingress.yaml index 038783b..cd587cd 100644 --- a/charts/onebusaway/templates/ingress.yaml +++ b/charts/onebusaway/templates/ingress.yaml @@ -8,6 +8,7 @@ metadata: {{- toYaml .Values.ingress.annotations | nindent 4 }} {{- end }} spec: + ingressClassName: nginx rules: - host: {{ .Values.ingress.host }} http: diff --git a/charts/onebusaway/templates/service.yaml b/charts/onebusaway/templates/service.yaml index a6eda1b..07d1336 100644 --- a/charts/onebusaway/templates/service.yaml +++ b/charts/onebusaway/templates/service.yaml @@ -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 diff --git a/charts/onebusaway/values.yaml b/charts/onebusaway/values.yaml index 22314b2..efe80b8 100644 --- a/charts/onebusaway/values.yaml +++ b/charts/onebusaway/values.yaml @@ -32,7 +32,7 @@ hpa: ingress: enabled: true - host: example.oba.com + host: oba.dmr.gg annotations: {} tls: false tlsSecret: "" diff --git a/modules/azure-aks/.terraform.lock.hcl b/modules/azure-aks/.terraform.lock.hcl new file mode 100644 index 0000000..ca26ba8 --- /dev/null +++ b/modules/azure-aks/.terraform.lock.hcl @@ -0,0 +1,19 @@ +# This file is maintained automatically by "tofu init". +# Manual edits may be lost in future updates. + +provider "registry.opentofu.org/hashicorp/azurerm" { + version = "3.115.0" + hashes = [ + "h1:FX3ktF0lka9MdZKIpCDsvO5NV/o2ete3vE5Nny2eoFI=", + "zh:00b8e98d1750929141b5e24673e28f1118cf87a75775039a20c5a54bbbae9a16", + "zh:13583356c26d116e2a6bd74ee78e4964f17629fd3909192d089edada657af4ab", + "zh:315ec12e48d6f905b3007e4238a195d9ba02385daaf972c9dd2554a42eeadb10", + "zh:35da8e78207339dbb9223effcc9e2235d8da54a9b51f02ee1b2ebbcf021491c1", + "zh:557367d6e803a0eb0c3c7ae0de37700a2972e86c9bfbf8c06ebae0e2ad7a8788", + "zh:69f0e00f4d8f0b324f841da84ac2c47da54d8d59df70b88073fd2d95d857d8b2", + "zh:9e36ff4646da1525e8c02a37cd37c8ec3c30de3482a3a4962a5b0e4b01fc336e", + "zh:a129ea257420370e4f1f0165908ecc74e745dd88bde91ee5e8b840b16f4fd480", + "zh:c5535f4bf8338bfa351b945cf85980b6b2c4a3b1db4453205cc029c64ef7c0a5", + "zh:da9973d5d7cb78ea0f90bf056c54b49f64b8d2d69db46bfac5be801bf2082de4", + ] +} diff --git a/modules/azure-aks/main.tf b/modules/azure-aks/main.tf new file mode 100644 index 0000000..89025ed --- /dev/null +++ b/modules/azure-aks/main.tf @@ -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 +} + + diff --git a/modules/azure-aks/outputs.tf b/modules/azure-aks/outputs.tf new file mode 100644 index 0000000..e28b050 --- /dev/null +++ b/modules/azure-aks/outputs.tf @@ -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" +} \ No newline at end of file diff --git a/modules/azure-aks/readme.md b/modules/azure-aks/readme.md new file mode 100644 index 0000000..e011a27 --- /dev/null +++ b/modules/azure-aks/readme.md @@ -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. diff --git a/modules/azure-aks/variables.tf b/modules/azure-aks/variables.tf new file mode 100644 index 0000000..89de072 --- /dev/null +++ b/modules/azure-aks/variables.tf @@ -0,0 +1,27 @@ +variable "location" { + description = "The location where the resources will be created." + default = "East US" +} + +variable "resource_group_name" { + description = "The name of the resource group" + default = "aks-rg" +} + +variable "aks_cluster_name" { + description = "The name of the AKS cluster." + default = "aks-cluster" +} + +variable "dns_prefix" { + description = "The DNS prefix for the AKS cluster." + default = "aks" +} + +variable "tags" { + description = "Tags to apply to resources" + type = map(string) + default = { + environment = "dev" + } +} From 1386373835e1683f54d29bbe1c1a3fa31a0c876b Mon Sep 17 00:00:00 2001 From: Altonhe Date: Fri, 16 Aug 2024 21:42:25 -0400 Subject: [PATCH 2/3] fix lint --- modules/azure-aks/variables.tf | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/azure-aks/variables.tf b/modules/azure-aks/variables.tf index 89de072..7c32e1b 100644 --- a/modules/azure-aks/variables.tf +++ b/modules/azure-aks/variables.tf @@ -1,21 +1,25 @@ 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" { From 962223637016a2d9829a8bcd1fa0d6f1fac594c8 Mon Sep 17 00:00:00 2001 From: Altonhe Date: Fri, 16 Aug 2024 21:44:09 -0400 Subject: [PATCH 3/3] fix lint --- .github/workflows/lint-test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-test.yaml b/.github/workflows/lint-test.yaml index d4297fe..8ef1787 100644 --- a/.github/workflows/lint-test.yaml +++ b/.github/workflows/lint-test.yaml @@ -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