0

I've been having difficulty adding the --web.enable-lifecycle flag to prometheus, to enable the lifecycle api.

I have this working locally with docker compose, like so:

  prometheus:
    image: prom/prometheus
    volumes:
      - ./tmp/prometheus:/prometheus
      - ./prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
      - ./prometheus/targets:/etc/prometheus/targets
    networks:
      - localprom
    ports:
      - 9090:9090
    command:
      - --web.enable-lifecycle
      - --config.file=/etc/prometheus/prometheus.yml

But Azure's YAML format for creating/updating container instances is a little different than docker. Here is my YAML file:

apiVersion: 2021-10-01
location: useast
name: my-prometheus-container-instances
tags: { environment: development }
type: Microsoft.ContainerInstance/containerGroups

properties:
  containers:
    - name: prometheus
      properties:
        image: prom/prometheus:v2.45.6
        command:
          - /bin/prometheus
          - --config.file=/etc/prometheus/prometheus.yml
          - --web.enable-lifecycle
        resources:
          requests:
            cpu: 1
            memoryInGb: 1.5
        ports:
          - port: 9090
        volumeMounts:
          - name: prometheus-fileshare-volume
            mountPath: /etc/prometheus/

  subnetIds:
    - id: MY_SUBNET_ID

  osType: Linux
  volumes:
    - name: prometheus-fileshare-volume
      azureFile:
        shareName: prometheus-fileshare
        readOnly: true
        storageAccountName: prometheus-storage-account
        storageAccountKey: MY_ACCESS_KEY

  RestartPolicy: OnFailure
  ipAddress:
    type: Private
    ports:
      - protocol: tcp
        port: 9090

Note that the Azure YAML file requires - /bin/prometheus in the command array, while docker does not. Without this, prometheus will not start after deploying. I've also confirmed that the --config.file command is working, wondering if there is something else that may be stopping me from enabling the lifecycle API after deploying to Azure.

1 Answer 1

1
+50

To enable the Prometheus lifecycle API in an Azure Container Instance using a YAML configuration, you need to make sure that the command array is properly configured and that all necessary parameters are correctly passed.

Create a storage account

az storage account create --name prometheusstorageacct --resource-group arkorg --location eastus --sku Standard_LRS

enter image description here

Create a fileshare

az storage share create --name prometheusfileshare --account-name prometheusstorageacct

enter image description here

Get the storage key enter image description here

Create your Prometheus Configuration Files. I am just using a basic example, you edit as per your own requirement.

prometheus.yml:

global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds.

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  # Example job to scrape metrics from a target
  - job_name: 'example'
    static_configs:
      - targets: ['example.com:80']

targets.yml:

- targets:
  - 'target1.example.com:9100'
  - 'target2.example.com:9100'

enter image description here

Upload Configuration Files to Azure File Share

az storage file upload --share-name prometheusfileshare --source ./prometheus.yml --account-name prometheusstorageacct --account-key $STORAGE_KEY
az storage file upload --share-name prometheusfileshare --source ./targets.yml --account-name prometheusstorageacct --account-key $STORAGE_KEY

enter image description here

Create the Azure Container Instance

apiVersion: 2021-10-01
location: eastus
name: my-prometheus-container-instances
type: Microsoft.ContainerInstance/containerGroups
properties:
  containers:
    - name: prometheus
      properties:
        image: prom/prometheus:v2.45.6
        command:
          - /bin/prometheus
          - --config.file=/etc/prometheus/prometheus.yml
          - --web.enable-lifecycle
        resources:
          requests:
            cpu: 1
            memoryInGb: 1.5
        ports:
          - port: 9090
        volumeMounts:
          - name: prometheus-fileshare-volume
            mountPath: /etc/prometheus/
  osType: Linux
  volumes:
    - name: prometheus-fileshare-volume
      azureFile:
        shareName: prometheusfileshare
        readOnly: true
        storageAccountName: prometheusstorageacct
        storageAccountKey: ...6tNg==
  restartPolicy: OnFailure
  ipAddress:
    type: Public
    ports:
      - protocol: tcp
        port: 9090

Deploy the Azure Container Instance

az container create --resource-group arkorg --file prometheus-aci.yaml

enter image description here

Verify and access Prometheus

az container show --resource-group arkorg --name my-prometheus-container-instances

enter image description here

access prometheus by getting the IP

az container show --resource-group arkorg --name my-prometheus-container-instances --query "ipAddress.ip" --output tsv

enter image description here

go to your browser and put the IP you see as output for the above command

http://<container-ip>:9090.

enter image description here

you can verify your lifecycle using something like

curl -X POST http://52.188.24.225:9090/-/reload

Reference-

prometheus | Prometheus

4
  • Can you highlight how what you've done is different from the attempt of the OP, please?
    – markalex
    Commented Jul 15 at 9:55
  • 1
    In OPs attempt it is not clear whether he/she ensured that the storage account and file share were correctly set up and accessible by the ACI. My solution explicitly uploads the necessary config files to File share and correctly mounts these volumes to the Prometheus container. The command array is explicitly set to include --web.enable-lifecycle and --config.file=/etc/prometheus/prometheus.yml, ensuring Prometheus starts with the correct configuration.
    – Arko
    Commented Jul 15 at 10:19
  • I can confrim that my file share and storage account are properly set up. I've confirmed this by adding targets to my prometheus config file in my fileshare, and seeing them added to the prometheus browser GUI when going to the IP/port. I can also see in the Azure Container Instance logs that the config file is loaded properly. I'm not however seeing any reference to the lifecycle API being enabled. I'm also not sure if I'm suppose to see a log referring to this if it's working properly.
    – Greggo
    Commented Jul 15 at 11:35
  • 1
    My issue ended up being confusion on my end. We have mutliple test virtual networks set up with different container instances, and I was looking at the wrong instance. I'll approve this answer is it's extremely detailed and after spending a lot of time looking around for this kind of answer, I think it will be extremely useful for people in the future.
    – Greggo
    Commented Jul 19 at 16:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.