Posted on Leave a comment

Azure Linux virtual machine not booting – disk issue

There could be cases that you have not configured the disk correctly inside a Linux azure virtual machine , or the disk mount point to change because of a disk increase. This circumstance will make your virtual machine fail and boot into emergency mode. In order to fix this issue you should first get a terminal windows on the Azure virtual machine as you cannot ssh. This can be done by selecting Help -> Serial Console

By checking the boot logs you can find the issue which in my case is the mounting of the data disk. The data disk is added as an entry on /etc/fstab but the mount point changed and Linux filesystem cannot locate it.

In order to resolve this issue you should mount the disk using the UUID to be 100% sure for the mount point. First locate the disk by using

fdisk -l

After locating the mount point run blkid command to find the UUID of the disk.

blkid

When you find the UUID use it in your /etc/fstab file instead of the mount point as shown below.

Posted on Leave a comment

Deploying kubernetes applications with 2-clicks | Azure DevOps & Terraform

When you read the title you may think that this article can be a clickbait. That’s the reason you should continue reading until this end to figure out that deploying k8s application with Azure DevOps and terraform can be very easy when you create everything through infrastructure as code.

In this example we will utilize Azure DevOps pipelines and terraform to deploy a yaml definition on an AKS cluster that runs on Azure. For this output we will need three steps.

The first step is to create an AKS cluster on Azure. When we have the infrastructure ready we can then continue and bind Azure DevOps pipelines with the AKS resource so that we can deploy on the cluster. The last step is to have the yaml definition of the application that we need to deploy and run the application deployment process inside azure devops.

The project is structure as shown in the below picture.

  • The code folder contains the yaml k8s definition file.
  • The iac_aks creates the AKS cluster inside Azure
  • The iac_devops creates the Azure Devops resources needed (Service connection with AKS)
  • And finally the azure-pipeline and application-pipeline are the pipelines that will run the automation and do the job.

In order to try out the example the first think that you need to do is to create a variable group inside azure devops and store two values. The first value will be the secret Personal access token that will be used to create the Azure DevOps resources. The second one is the URL of your Azure DevOps organization.

When those are set you will need to change the tfvars files and add the names that you prefer for the resources creation. Finally you can have your deployment ready with just two clicks. One for the infra pipelines and one for the application pipeline.

Code is hosted on Github
https://github.com/geralexgr/globalazuregreece2024

Posted on Leave a comment

Pass terraform provider variables as secrets

Many times you need to provide values in provider information when using terraform. Lets take as an example the below code block. The azuredevops provider needs some variables in order to deploy successfully and we need to pass those values as secrets because they contain sensitive information.

terraform {
required_providers {
azuredevops = {
source = "microsoft/azuredevops"
version = ">=1.0.0"
}
}
}

provider "azuredevops" {
org_service_url = URL
personal_access_token = TOKEN
}

We should never hardcode such information in the application as this information may get leaked. In order to pass those as secrets we will need to create a variable group or standalone variables and place the secrets there.

Then we will need to create some terraform variables and pass the values for those through the pipeline.

variable "org_service_url" {
description = "The URL of your Azure DevOps organization."
}

variable "personal_access_token" {
description = "The personal access token for authentication."
}

The provider block should be updated accordingly.

provider "azuredevops" {
org_service_url = var.org_service_url
personal_access_token = var.personal_access_token
}

Finally we pass those values through the pipeline step by providing those with -var argument on terraform.

    - task: TerraformTaskV4@4
displayName: terraform apply
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/src/iac_devops'
commandOptions: '-var="org_service_url=$(URL)" -var="personal_access_token=$(PAT)"'
environmentServiceNameAzureRM: 'SUBSCRIPTION'

Finally the pipeline will succeed.

Posted on Leave a comment

The subscription is not registered to use namespace ‘Microsoft.ContainerService’.

When you deploy on Azure using terraform you may encounter the below error.

The subscription is not registered to use namespace ‘Microsoft.ContainerService’. See https://aka.ms/rps-not-found for how to register subscriptions.

In order to resolve issue you should go inside azure portal and under your subscription you should navigate into Resource Providers. Then you should search for the specific provider that is not registered (in my example in was ContainerService) and click register.

When you press register you will see that the provider is going to be in Registering state.

Finally the deployment will succeed after the above change.