Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
6b1b32a
first commit (adding glab pipe gen and creating artifact function)
ultymatom Jun 22, 2022
54a04e1
adding gitlab-ci file
ultymatom Jun 22, 2022
edf91dc
fixing some little errors
ultymatom Jul 7, 2022
82ff220
Add files via upload
prathibhapadma Sep 5, 2022
295c337
Update main.tf
prathibhapadma Sep 5, 2022
df6cf1d
Delete scripts/pipelines/gitlab/templates/common/aks directory
prathibhapadma Sep 5, 2022
bd1195a
Delete scripts/pipelines/gitlab/templates/common/common/kubernetes di…
prathibhapadma Sep 5, 2022
6fb30ff
Add files via upload
prathibhapadma Sep 5, 2022
aebbf7c
update
prathibhapadma Sep 8, 2022
13a55e2
updated
prathibhapadma Sep 8, 2022
f17540f
updated
prathibhapadma Sep 8, 2022
200680d
updated with document
prathibhapadma Sep 12, 2022
c0a8216
automatic commit dor docs
prathibhapadma Sep 12, 2022
d59666d
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 12, 2022
319380c
automatic commit dor docs
prathibhapadma Sep 12, 2022
cf5e4fa
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 12, 2022
601df90
automatic commit dor docs
prathibhapadma Sep 12, 2022
eac3b5d
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 12, 2022
6f05bd1
automatic commit dor docs
prathibhapadma Sep 12, 2022
85a1d85
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 12, 2022
44bd026
automatic commit dor docs
prathibhapadma Sep 12, 2022
42b59d0
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 12, 2022
3183a7b
automatic commit dor docs
prathibhapadma Sep 12, 2022
a196af9
Update aks-provisioning.yml.template
prathibhapadma Sep 12, 2022
20b5efb
Merge branch 'master' into feature/gitlab-aks-provision
prathibhapadma Sep 12, 2022
84bd870
Automatic generation of documentation
prathibhapadma Sep 12, 2022
f300186
updated with minor changes
prathibhapadma Sep 13, 2022
09f064e
Automatic generation of documentation
prathibhapadma Sep 13, 2022
e0bb056
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 13, 2022
5e01a15
Update aks-provisioning.yml.template
prathibhapadma Sep 13, 2022
93191de
Update aks-provisioning.yml.template
prathibhapadma Sep 20, 2022
67128fe
Update aks-provisioning.yml.template
prathibhapadma Sep 21, 2022
54b952c
Update setup-aks-provisioning-pipeline.asciidoc
prathibhapadma Sep 22, 2022
4164892
Automatic generation of documentation
prathibhapadma Sep 22, 2022
000ceaf
updated
prathibhapadma Sep 22, 2022
525bea3
Merge branch 'master' into feature/gitlab-aks-provision
prathibhapadma Sep 23, 2022
e409601
Merge branch 'master' into feature/gitlab-aks-provision
prathibhapadma Oct 18, 2022
e322cf7
fixed with line ending checks
prathibhapadma Oct 18, 2022
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
38 changes: 24 additions & 14 deletions documentation/azure-devops/setup-aks-provisioning-pipeline.asciidoc
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
= Setting up a Azure AKS provisioning pipeline on Azure DevOps
:provider: Azure Devops
:pipeline_type: pipeline
:trigger_sentence_azure:
:pipeline_type2: pipeline
:path_provider: azure-devops
:aks_variables_path: Azure DevOps > Pipelines > Library > 'aks-variables
= Setting up a Azure AKS provisioning {pipeline_type} on {provider}

In this section we will create a pipeline which will provision an Azure AKS cluster. This pipeline will be configured to be manually triggered by the user. As part of AKS cluster provisioning, a NGINX Ingress controller is deployed and a variable group with the name `aks-variables` is created, which contains, among others, the DNS name of the Ingress controller, that you you will need to add as CNAME record on the domains used in your application Ingress manifest files. Refer to the appendix for more details.
In this section we will create a {pipeline_type} which will provision an Azure AKS cluster. This {pipeline_type} will be configured to be manually triggered by the user. As part of AKS cluster provisioning, a NGINX Ingress controller is deployed and a variable group with the name `aks-variables` is created, which contains, among others, the DNS name of the Ingress controller, that you you will need to add as CNAME record on the domains used in your application Ingress manifest files. Refer to the appendix for more details.

The creation of the pipeline will follow the project workflow, so a new branch named `feature/aks-provisioning` will be created, the YAML file for the pipeline and the terraform files for creating the cluster will be pushed to it.
The creation of the {pipeline_type} will follow the project workflow, so a new branch named `feature/aks-provisioning` will be created, the YAML file for the {pipeline_type} and the terraform files for creating the cluster will be pushed to it.

Then, a Pull Request (PR) will be created in order to merge the new branch into the appropiate branch (provided in `-b` flag). The PR will be automatically merged if the repository policies are met. If the merge is not possible, either the PR URL will be shown as output, or it will be opened in your web browser if using `-w` flag.

The script located at `/scripts/pipelines/azure-devops/pipeline_generator.sh` will automatically create this new branch, create the AKS provisioning pipeline based on the YAML template, create the Pull Request and, if it is possible, merge this new branch into the specified branch.
The script located at `/scripts/pipelines/{path_provider}/pipeline_generator.sh` will automatically create this new branch, create the AKS provisioning {pipeline_type} based on the YAML template, create the Pull Request and, if it is possible, merge this new branch into the specified branch.

== Prerequisites

* Install the https://marketplace.visualstudio.com/items?itemName=ms-devlabs.custom-terraform-tasks[Terraform extension] for Azure DevOps.
* Create a https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#create-a-service-connection[service connection] to Azure Resource Manager and name it `aks-connection`. If you already have a service connection available or you need a specific connection name, please update `aks-pipeline.cfg` accordingly.
* Install the https://marketplace.visualstudio.com/items?itemName=ms-devlabs.custom-terraform-tasks[Terraform extension] for Azure DevOps.
* Create a https://docs.microsoft.com/en-us/azure/devops/pipelines/library/service-endpoints?view=azure-devops&tabs=yaml#create-a-service-connection[service connection] to Azure Resource Manager and name it `aks-connection`. If you already have a service connection available or you need a specific connection name, please update `aks-pipeline.cfg` accordingly.



* An Azure resource group in the desired cluster location (e.g. `westeurope`). You can use an existing one or create a new one with the following command:

```
Expand All @@ -32,7 +41,7 @@ az storage container create -n <storage container name> --account-name <storage

* This script will commit and push the corresponding YAML template into your repository, so please be sure your local repository is up-to-date (i.e you have pulled the latest changes with `git pull`).

== Creating the pipeline using provided script
== Creating the {pipeline_type} using provided script

Before executing the script you will need to customize some input variables about the environment. To do so, you can either edit `terraform.tfvars` file or take advantage of the `set-terraform-variables.sh` script located at `/scripts/environment-provisioning/azure/aks`, which allows you to create or update values for the required variables, passing them as flags. As a full example:

Expand All @@ -55,16 +64,16 @@ pipeline_generator.sh \
[-w]
```

NOTE: The config file for the AKS provisioning pipeline is located at `/scripts/pipelines/azure-devops/templates/aks/aks-pipeline.cfg`.
NOTE: The config file for the AKS provisioning {pipeline_type} is located at `/scripts/pipelines/{path_provider}/templates/aks/aks-pipeline.cfg`.

=== Flags
```
-c, --config-file [Required] Configuration file containing pipeline definition.
-n, --pipeline-name [Required] Name that will be set to the pipeline.
-d, --local-directory [Required] Local directory of your project (the path should always be using '/' and not '\').
--cluster-name [Required] Name for the cluster.
--resource-group [Required] Name of the resource group for the cluster.
--storage--account [Required] Name of the storage account for the cluster.
--resource-group [Required] Name of the resource group for the cluster.
--storage--account [Required] Name of the storage account for the cluster.
--storage-container [Required] Name of the storage container where the Terraform state of the cluster will be stored.
--rancher Install Rancher to manage the cluster.
-b, --target-branch Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided.
Expand All @@ -74,7 +83,8 @@ NOTE: The config file for the AKS provisioning pipeline is located at `/scripts/
=== Example

```
./pipeline_generator.sh -c ./templates/aks/aks-pipeline.cfg -n aks-provisioning -d C:/Users/$USERNAME/Desktop/quarkus-project --cluster-name devon-hangar --resource-group devonfw --storage-account hangar --storage-container aks-state --rancher -b develop -w
./pipeline_generator.sh -c ./templates/aks/aks-pipeline.cfg -n aks-provisioning -d C:/Users/$USERNAME/Desktop/quarkus-project --cluster-name devon-hangar --resource-group devonfw --storage-account hangar --storage-container aks-state --rancher -b develop -w

```

NOTE: Rancher is installed on the cluster after provisioning when using the above command.
Expand All @@ -83,7 +93,7 @@ NOTE: Rancher is installed on the cluster after provisioning when using the abov

NOTE: Make sure you have https://kubernetes.io/docs/tasks/tools/#kubectl[kubectl] installed.

In order to interact with your cluster you will need to download the artifact `kubeconfig` generated by the cluster provisioning pipeline on the location it is expected by default (`~/.kube/config`) or either:
In order to interact with your cluster you will need to download the artifact `kubeconfig` generated by the cluster provisioning {pipeline_type} on the location it is expected by default (`~/.kube/config`) or either:

```
# via environment variable (you can add this on your profile)
Expand All @@ -94,7 +104,7 @@ kubectl <command>
kubectl <command> --kubeconfig=<path to downloaded kubeconfig>
```

To get the DNS name of the NGINX Ingress controller on the EKS cluster, go into Azure DevOps > Pipelines > Library > `aks-variables`.
To get the DNS name of the NGINX Ingress controller on the AKS cluster, go into {aks_variables_path}.

Rancher, if installed, will be available on `https://<ingress controller domain>/dashboard`. You will be asked for an initial password, which can be retrieved with:

Expand All @@ -104,4 +114,4 @@ kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{

=== Appendix: Destroying the cluster

To destroy the provisioned resources, set `operation` pipeline variable value to `destroy` and run the pipeline.
To destroy the provisioned resources, set `operation` {pipeline_type} variable value to `destroy` and run the {pipeline_type}.
99 changes: 99 additions & 0 deletions documentation/gitlab/setup-aks-provisioning-pipeline.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
:provider: Gitlab
:pipeline_type: pipeline
:trigger_sentence_gitlab:
:pipeline_type2: Gitlab pipeline
:path_provider: gitlab
:aks_variables_path: Group > settings > ci_cd > Variables
= Setting up a Azure AKS provisioning {pipeline_type} on {provider}

In this section we will create a {pipeline_type} which will provision an Azure AKS cluster. This {pipeline_type} will be configured to be manually triggered by the user. As part of AKS cluster provisioning, a NGINX Ingress controller is deployed and a variable group with the name `aks-variables` is created, which contains, among others, the DNS name of the Ingress controller, that you you will need to add as CNAME record on the domains used in your application Ingress manifest files. Refer to the appendix for more details.

The creation of the {pipeline_type} will follow the project workflow, so a new branch named `feature/aks-provisioning` will be created, the YAML file for the {pipeline_type} and the terraform files for creating the cluster will be pushed to it.

Then, a Pull Request (PR) will be created in order to merge the new branch into the appropiate branch (provided in `-b` flag). The PR will be automatically merged if the repository policies are met. If the merge is not possible, either the PR URL will be shown as output, or it will be opened in your web browser if using `-w` flag.

The script located at `/scripts/pipelines/{path_provider}/pipeline_generator.sh` will automatically create this new branch, create the AKS provisioning {pipeline_type} based on the YAML template, create the Pull Request and, if it is possible, merge this new branch into the specified branch.

== Prerequisites


* Add AZURE credentials as https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-project[Variables] in your repository and name it `AZURE_USERNAME`, `AZURE_PASSWORD`. If you already have a available credentials or you need a specific credentials connection, please update `aks-provisioning.yml` accordingly.

* Create a Gitlab personal access token https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html#create-a-personal-access-token[PAT], Store in environment variable as `GITLAB_PAT`.

* An Azure resource group in the desired cluster location (e.g. `westeurope`). You can use an existing one or create a new one with the following command:

```
az group create -n <resource group name> -l <location>
```

* This script will commit and push the corresponding YAML template into your repository, so please be sure your local repository is up-to-date (i.e you have pulled the latest changes with `git pull`).

== Creating the {pipeline_type} using provided script

Before executing the script you will need to customize some input variables about the environment. To do so, you can either edit `terraform.tfvars` file or take advantage of the `set-terraform-variables.sh` script located at `/scripts/environment-provisioning/azure/aks`, which allows you to create or update values for the required variables, passing them as flags. As a full example:

```
./set-terraform-variables.sh --location <location> --resource_group_name <resource group name> --instance_type <worker instance type> --worker_node_count <number of worker nodes> --dns_prefix <dns prefix>
```

=== Usage
```
pipeline_generator.sh \
-c <config file path> \
-d <project local path> \
--cluster-name <cluster name> \
--storage-container <storage container name> \
[--rancher] \
[-b <branch>] \
[-w]
```

NOTE: The config file for the AKS provisioning {pipeline_type} is located at `/scripts/pipelines/{path_provider}/templates/aks/aks-pipeline.cfg`.

=== Flags
```
-c, --config-file [Required] Configuration file containing pipeline definition.
-d, --local-directory [Required] Local directory of your project (the path should always be using '/' and not '\').
--cluster-name [Required] Name for the cluster.
--storage-container [Required] Name of the storage container where the Terraform state of the cluster will be stored.
--rancher Install Rancher to manage the cluster.
-b, --target-branch Name of the branch to which the Pull Request will target. PR is not created if the flag is not provided.
-w Open the Pull Request on the web browser if it cannot be automatically merged. Requires -b flag.
```

=== Example

```

./pipeline_generator.sh -c ./templates/aks/aks-pipeline.cfg -d C:/Users/$USERNAME/Desktop/quarkus-project --cluster-name devon-hangar --storage-container aks-state --rancher -b develop -w
```

NOTE: Rancher is installed on the cluster after provisioning when using the above command.

=== Appendix: Interacting with the cluster

NOTE: Make sure you have https://kubernetes.io/docs/tasks/tools/#kubectl[kubectl] installed.

In order to interact with your cluster you will need to download the artifact `kubeconfig` generated by the cluster provisioning {pipeline_type} on the location it is expected by default (`~/.kube/config`) or either:

```
# via environment variable (you can add this on your profile)
export KUBECONFIG=<path to downloaded kubeconfig>
kubectl <command>

# via command-line flag
kubectl <command> --kubeconfig=<path to downloaded kubeconfig>
```

To get the DNS name of the NGINX Ingress controller on the AKS cluster, go into {aks_variables_path}.

Rancher, if installed, will be available on `https://<ingress controller domain>/dashboard`. You will be asked for an initial password, which can be retrieved with:

```
kubectl get secret --namespace cattle-system bootstrap-secret -o go-template='{{.data.bootstrapPassword|base64decode}}{{"\n"}}'
```

=== Appendix: Destroying the cluster

To destroy the provisioned resources, set `operation` {pipeline_type} variable value to `destroy` and run the {pipeline_type}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:provider: Azure Devops
:pipeline_type: pipeline
:trigger_sentence_azure:
:pipeline_type2: pipeline
:path_provider: azure-devops
:aks_variables_path: Azure DevOps > Pipelines > Library > 'aks-variables
include::../common_templates/setup-aks-provisioning-pipeline.asciidoc[]
Loading