Injecting Flameshot with DataKit Operator¶
Starting with v1.7.0, DataKit Operator supports injecting the Flameshot Sidecar. Flameshot can collect Profiling data from Java, Python, and Go applications on a schedule or when resource thresholds are reached. It replaces the legacy Profiler injection.
Prerequisites¶
- Install DataKit Operator and deploy DataKit in the cluster.
- The Profile collector is enabled in DataKit.
- The target Pod's security policy allows the Sidecar to add the
SYS_PTRACEcapability.
Operator Configuration¶
In the Operator’s admission_inject_v2.flameshots rules, use namespace_selectors and label_selectors to select Pods and processes to select processes for profiling. The release template matches only default and leaves processes empty. To enable profiling there, edit that rule or place a more specific rule before it.
{
"admission_inject_v2": {
"flameshots": [
{
"name": "flameshot-java",
"namespace_selectors": ["^production$"],
"label_selectors": ["app=java-demo"],
"image": "pubrepo.guance.com/datakit/flameshot:0.2.4",
"envs": {
"FLAMESHOT_DATAKIT_ADDR": "http://datakit-service.datakit:9529/profiling/v1/input",
"FLAMESHOT_PROFILING_PATH": "/flameshot-data",
"FLAMESHOT_HTTP_LOCAL_IP": "{fieldRef:status.podIP}",
"FLAMESHOT_HTTP_LOCAL_PORT": "8089"
},
"processes": "[{\"service\":\"java-demo\",\"language\":\"java\",\"command\":\"^java\\\\b.*app\\\\.jar$\",\"events\":\"cpu\",\"duration\":\"30s\",\"cpu_usage_percent\":80}]",
"enable_prometheus_annotations": true
}
]
}
}
This rule selects Pods in production with the existing label app=java-demo. Both selectors must match. The workload needs no dedicated label or version annotation.
| Field | Description |
|---|---|
name |
Rule name, recommended for locating relevant logs |
namespace_selectors |
Array of Namespace regular expressions |
label_selectors |
Array of Pod Label Selectors |
image |
Flameshot Sidecar image |
envs |
Sidecar environment variables |
processes |
Required and cannot be empty; JSON array string containing process matching and collection policies |
enable_prometheus_annotations |
Whether to add Flameshot metric collection Annotations automatically; defaults to false |
resources |
Sidecar resource configuration; defaults are used when missing or invalid |
FLAMESHOT_PROFILING_PATH and a valid FLAMESHOT_HTTP_LOCAL_PORT are required for injection. If either is missing, or if processes is empty, the Operator skips injection and logs a warning.
Flameshot uses the first matching rule. To exclude one workload, set admission.datakit/flameshot.enabled: "false" on its Pod template.
Injection Result¶
The new Pod contains a datakit-flameshot sidecar and shares its process namespace. The sidecar uses SYS_PTRACE to access target processes and reads profiling files from the shared FLAMESHOT_PROFILING_PATH directory. The Operator sets the Pod’s restartPolicy to Always.
Collection Configuration¶
The example profiles the Java process for 30 seconds when CPU usage reaches 80%, using the service name java-demo. To also profile periodically, set FLAMESHOT_AUTO_PROFILING in envs, for example to 5m. Adjust the command pattern and service name in processes to match your application.
| Environment variable | Description |
|---|---|
FLAMESHOT_DATAKIT_ADDR |
DataKit Profiling receiver address |
FLAMESHOT_MONITOR_INTERVAL |
Process and resource monitoring interval |
FLAMESHOT_LOG_LEVEL |
Flameshot log level |
FLAMESHOT_PROFILING_PATH |
Shared directory for temporary Profiling files; required for injection |
FLAMESHOT_HTTP_LOCAL_IP |
Flameshot HTTP listen IP |
FLAMESHOT_HTTP_LOCAL_PORT |
Flameshot HTTP and metrics port; required for injection |
FLAMESHOT_SERVICE |
Overrides service in all process rules |
FLAMESHOT_TAGS |
Global Profiling tags |
FLAMESHOT_POD_CPU_LIMIT |
Pod CPU limit, in thousandths of a CPU core |
FLAMESHOT_POD_MEM_LIMIT |
Pod memory limit, in MiB |
For language-specific process matching, profiling events, and thresholds, see the Flameshot guide.
Prometheus Annotations¶
To collect Flameshot’s own metrics, enable Pod annotation discovery in DataKit KubernetesPrometheus and set enable_prometheus_annotations: true on the Operator rule. The Operator adds the following Pod annotations. Profiling works independently of these annotations.
prometheus.io/scrape: "true"
prometheus.io/port: "8089"
prometheus.io/scheme: "http"
prometheus.io/path: "/metrics"
prometheus.io/param_measurement: "flameshot"
The port comes from FLAMESHOT_HTTP_LOCAL_PORT. If the Pod already contains any Annotation beginning with prometheus.io/, the Operator preserves the user configuration and does not add these Annotations.
Deployment Example¶
Prepare the production namespace. The example assumes the application starts with java -jar /app/app.jar. Use your application image and startup command, and update the command pattern in the Operator rule to match.
apiVersion: apps/v1
kind: Deployment
metadata:
name: java-demo
namespace: production
spec:
replicas: 1
selector:
matchLabels:
app: java-demo
template:
metadata:
labels:
app: java-demo
spec:
containers:
- name: app
image: example/java-demo:1.0.0
command: ["java", "-jar", "/app/app.jar"]
After editing the Operator ConfigMap directly, restart the Operator and create or recreate the target Pods. Check for the injected sidecar.
kubectl -n production get pod -l app=java-demo -o jsonpath='{.items[0].spec.containers[*].name}'
kubectl -n production logs -l app=java-demo -c datakit-flameshot
The container list should include datakit-flameshot. Once the CPU threshold is reached and sampling finishes, look for service java-demo on the Guance Profiling page. If profiles are missing, check the process command, trigger threshold, and connectivity from the sidecar to the DataKit endpoint.