Skip to content

Azure CNI from a Virtual Machine containerized app

License

Notifications You must be signed in to change notification settings

epomatti/azure-vm-cni

Repository files navigation

Azure VM CNI

Enabling containers to use Azure Virtual Network capabilities with Azure CNI and Azure Virtual Machines.

💡 The documentation implies that CNI is required for containers to use Virtual Network capabilities, however, after finishing this project I discovered that CNI was not required to use Service Endpoints from a Virtual Machine. Maybe it is already installed or something, did not investigate.

Azure deploy

Set the .auto.tfvars file:

cp config/template.tfvars .auto.tfvars

Create the infrastructure:

terraform init
terraform apply -auto-approve

Confirm that cloud-init has complete successfully.

Manually select the Service Endpoint Policy as it was having circular dependency issues.

Connect via SSH to the virtual machine.

Run the command to star the app container:

sudo docker run -p 8080:8080 \
    -e 'MSSQL_HOSTNAME=sqls-cni.database.windows.net' \
    -e 'MSSQL_PORT=1433' \
    -e 'MSSQL_USERNAME=dbadmin' \
    -e 'MSSQL_PASSWORD=P4ssw0rd!2023' \
    epomatti/azure-vm-cni-app:arm64

Teste the database connection:

curl <vm-ipaddress>:8080/query

Local development

Set the .env file.

Start the database:

docker run -p 1433:1433 -e ACCEPT_EULA=Y -e [email protected] mcr.microsoft.com/mssql/server:2022-latest

Run the application:

cd app

go run .