You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A demonstration project that uses Terraform to provision an Azure Kubernetes Service [AKS] cluster and installs Ondat - a software-defined, cloud native storage platform for Kubernetes.
The goal of this project is to automate the process of creating, managing and destroying an AKS cluster with terraform.
During the creation of the cluster, a kubeconfig file is generated, which is used to deploy Ondat using the kubectl-storageos plugin.
Below is a quick overview of how the directory is organised and brief configuration file descriptions.
.├── README.md # readme with instructions on how to provision an AKS cluster.├── data.tf # data sources from provisioned resources.├── main.tf # defined resources for provisioning an AKS cluster.├── monitoring.tf # defined resources for provisioning Azure Log Analytics.├── output.tf # output values for provisioned resources. ├── variables.tf # input variables for customising resources.└── versions.tf # defined provider versions to be used.
Ensure that a Service Principal with the role Contributor is created first for terraform.
# make a note of your Subscription ID.
$ az account list | grep "id"# create a Contributor Service Principal for Terraform and# make a note of the following key value pairs;# `appId`, `password` and `tenant`
$ az ad sp create-for-rbac \
--role="Contributor" \
--scopes="/subscriptions/YOUR_SUBSCRIPTION_ID"
Ensure that the correct Azure environment variables are set.
# set the required Azure environment variables with the values noted earlier.
$ export ARM_CLIENT_ID="YOUR_APP_ID"
$ export ARM_SUBSCRIPTION_ID="YOUR_SUBSCRIPTION_ID"
$ export ARM_TENANT_ID="YOUR_TENANT_ID"
$ export ARM_CLIENT_SECRET="YOUR_PASSWORD"
Step 2 - terraform Configuration
Ensure that the terraform CLI is installed on your local machine and is in your path.
Apple M1 users may get the following error message when they run terraform init on their machine.
Error: Incompatible provider version
│
│ Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your current platform, darwin_arm64.
│
│ Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions of this provider may have different platforms supported.
╵
This is due to the hashicorp/template provider being deprecated, but some providers still depend on it. To address this issue, apply the following workaround solution.
# clone the template provider repository.
$ git clone [email protected]:hashicorp/terraform-provider-template.git
# navigate into the directory.
$ cd terraform-provider-template/
# build the template provider from source (requires Golang to be installed).
$ go build
# make the generated binary executable.
$ chmod -v +x terraform-provider-template
# create the following directory and move the binary into `darwin_arm64/`.
$ mkdir -v ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/
$ mv -v terraform-provider-template ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/
# go back to the `terraform-gke-ondat-demo/` directory containing # the configuration files and initialise again.
$ terraform init
Ensure that the kubectl CLI is installed on your local machine and is in your path.
Ensure that the kubectl-storageos plugin CLI is installed on your local machine and is in your path.
Ensure that the storageos CLI is installed on your local machine and is in your path.
Step 4 - Input Variables Configuration (Optional)
By default, from a high level view - the following resources will be provisioned without making changes;
AKS Cluster
3 nodes in the default pool.
2 nodes in a separate node pool.
Log Analytics Solution & Workspace using Container Insights
For users who would like to use different values such as a different region, node size, disk size or Kubernetes version before provisioning, review the variables.tf configuration file and apply your desired values first.
Quick-start & Usage
# clone the repository.
$ git clone [email protected]:hubvu/terraform-kubernetes-ondat-demo.git
# navigate into the `aks/` directory.
$ cd terraform-kubernetes-ondat-demo/aks/
# initialise the working directory containing the configuration files.
$ terraform init
# validate the configuration files in the working directory.
$ terraform validate
# create an execution plan first.
$ terraform plan
# execute the actions proposed in a plan and enter your PROJECT_ID.
$ terraform apply
# after the cluster has been provisioned, inspect the pods with # kubectl and the generated kubeconfig file.
$ export KUBECONFIG="${PWD}/kubeconfig"# or use `az` to get the cluster credentials automatically added # to your `$HOME/.kube/config`.
$ az aks get-credentials --resource-group aks-ondat-demo-resources --name ondat-cluster
$ kubectl get pods --all-namespaces
# destroy the environment created with terraform once you # are finished testing out AKS & Ondat.
$ terraform destroy