Skip to content

Infrastructure as Code (IaC)

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

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

If you are provisioning a new VM or Auto-scaling group, you should use cloud-init via User Data/Custom Data. If you want faster boot times, use Packer to pre-bake the image and cloud-init for config only.

If you are managing an existing fleet, use an Ansible playbook.

If you are managing infrastructure with 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)'"
  }'

Ansible is perfect for deploying 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"

You can easily embed kmagent into your Terraform deployments across any provider using our 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 you want zero install-time latency. The agent binary is baked into the image; only the config (API key) is injected at boot.

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