Skip to content

Infrastructure as Code (IaC)

Deploy the KloudMate agent across any cloud provider or on-premises infrastructure using Infrastructure as Code (IaC) and automation tools.

If your outbound traffic is restricted, see Before you start for the URLs and permissions to allow first.

MethodBest ForCloud Support
cloud-initNew VMs, ASGs, Scale SetsAll providers
AnsibleExisting VM fleetsAll providers + on-prem
Terraform moduleIaaC-managed infrastructureAll providers
PackerPre-baked machine imagesAWS, GCP, Azure

To provision a new VM or Auto-scaling group, use cloud-init through User Data or Custom Data. For faster boot times, use Packer to pre-bake the image and cloud-init for config only.

For an existing fleet, use an Ansible playbook.

If you already use Terraform, use the Terraform module.

Works on every provider that supports cloud-init (AWS, GCP, Azure, DigitalOcean, Alibaba, Hetzner, Vultr, Linode, etc.).

# Encode and attach to launch template
base64 -w0 cloud-init/cloud-init.yaml > /tmp/userdata.b64

aws ec2 create-launch-template \
  --launch-template-name kmagent-template \
  --launch-template-data '{
    "UserData": "'$(cat /tmp/userdata.b64)'"
  }'

Use Ansible to deploy the KloudMate agent to existing VM fleets.

Navigate to the Ansible directory

cd ansible/

Set your API key

export KM_API_KEY="your-kloudmate-api-key"

Edit your inventory

Add your hosts to the inventory file:

vim inventories/production.ini

Deploy

ansible-playbook -i inventories/production.ini deploy-kmagent.yml \
  -e "km_api_key=$KM_API_KEY km_endpoint=https://otel.kloudmate.com"

Instead of static inventory files, use cloud-native dynamic inventory plugins:

pip install boto3
ansible-playbook -i aws_ec2.yml deploy-kmagent.yml

Example aws_ec2.yml configuration:

plugin: amazon.aws.aws_ec2
regions:
  - us-east-1
  - us-west-2
  - ap-south-1
filters:
  tag:Environment: production
  instance-state-name: running
keyed_groups:
  - key: tags.Role
    prefix: role
  - key: placement.region
    prefix: region
compose:
  ansible_host: private_ip_address
# Upgrade agent on all hosts
ansible-playbook deploy-kmagent.yml --tags upgrade \
  -e "kmagent_version=1.2.0"

# Only reconfigure (no reinstall)
ansible-playbook deploy-kmagent.yml --tags configure

# Uninstall from specific hosts
ansible-playbook deploy-kmagent.yml \
  -e "kmagent_state=absent" --limit "gcp"

# Check agent status across fleet
ansible all -i inventories/production.ini -m shell \
  -a "systemctl status kmagent | head -5"

Embed kmagent into your Terraform deployments across any provider using the user-data module.

module "kmagent" {
  source      = "./modules/user-data"
  km_api_key  = var.km_api_key
  km_endpoint = "https://otel.kloudmate.com"
  kmagent_tags = {
    env  = "production"
    team = "platform"
  }
}

Best when boot speed matters. The agent binary is baked into the image, so there’s no install step at boot. Only the config (the API key) is injected.

Navigate to the Packer directory

cd packer/

Build your images

packer build -only=amazon-ebs.kmagent \
  -var 'kmagent_version=1.2.0' \
  kmagent-image.pkr.hcl

Deploy

Use the resulting image in your Launch Template / Instance Template, with minimal user-data that only injects the API key.

ProviderServiceRetrieval Command
AWSSSM Parameter Storeaws ssm get-parameter --name /kloudmate/api-key --with-decryption
AWSSecrets Manageraws secretsmanager get-secret-value --secret-id kloudmate-api-key
GCPSecret Managergcloud secrets versions access latest --secret=kloudmate-api-key
AzureKey Vaultaz keyvault secret show --name kloudmate-api-key --vault-name myvault
DigitalOceanReserved env varsSet via doctl or Terraform
AlibabaKMSaliyun kms GetSecretValue --SecretName kloudmate-api-key

kmagent-deploy/

kmagent-deploy/
├── ansible/
│   ├── ansible.cfg
│   ├── deploy-kmagent.yml          # Main playbook
│   ├── inventories/
│   │   └── production.ini          # Static inventory (edit with your hosts)
│   └── roles/
│       └── kmagent/
│           ├── defaults/main.yml   # Configurable variables
│           ├── handlers/main.yml   # Service reload/restart
│           ├── tasks/main.yml      # Install, configure, upgrade, uninstall
│           └── templates/
│               ├── agent.yaml.j2   # Agent config
│               └── kmagent.service.j2  # systemd unit
└── terraform/
    └── modules/
        └── user-data/
            └── main.tf              # Reusable user-data module