DataKit Operator¶
DataKit Operator uses a Kubernetes Admission Webhook to inject tracing, log collection, and profiling components into newly created Pods. It also provides in-cluster Pod query and DataKit central election coordination APIs.
Overview¶
Injection occurs during the Pod CREATE phase and does not modify running Pods. After changing the Operator configuration, an injection image, or workload Annotations, recreate the Pod for the change to take effect.
Admission is fail-open: if injection fails, the Operator logs the error but does not block creation of the application Pod. The webhook in the deployment manifest also uses failurePolicy: Ignore.
Features and Guides¶
| Feature | Description |
|---|---|
| Beacon automatic injection | Java, Node.js, and Python |
| OpenTelemetry automatic injection | Java, Node.js, and Python |
| DDTrace automatic injection | Java, Node.js, Python, and PHP |
| logfwd injection | Forward application log files to DataKit through a sidecar in the Pod |
| Flameshot injection | Profile Java, Python, or Go processes on a schedule or when CPU or memory reaches a threshold |
| Legacy Profiler injection | Sample Java applications with async-profiler and CPython applications with py-spy |
| Logging configuration injection | Collect logs directly with DataKit on the node. The Operator sets datakit/logs and mounts directories for file logs. |
| Cluster API | Proxies queries for Pod data in the cluster, reducing direct access to the API Server from DataKit |
| Central election coordination | Uses Kubernetes Leases to select the Collection Leader among DataKit instances in the cluster |
Prerequisites¶
- Kubernetes must support
admissionregistration.k8s.io/v1; Kubernetes v1.24 or later is recommended. - The
MutatingAdmissionWebhookAdmission Controller must be enabled in the cluster. - Cluster nodes must be able to pull the configured images. In offline environments, synchronize the images to a private registry in advance.
Installation¶
If the datakit namespace does not exist, create it with kubectl create namespace datakit. Then download and apply the datakit-operator.yaml.
Helm 3.0 or later is required.
helm install datakit-operator datakit-operator \
--repo https://pubrepo.guance.com/chartrepo/datakit-operator \
-n datakit --create-namespace
Upgrade a Helm release
Before upgrading, export your custom values.
To use the image version from the new chart, remove any old pinned image.tag. A custom configmap.jsonconfig replaces the new chart’s default rules. By default, helm get values exports only user-supplied values. If you rely on the old chart’s default DDTrace Java rule, back up the active jsonconfig before upgrading and include that rule in the new configuration.
Attention
- The Operator binary and deployment manifest must be used together. When upgrading the Operator, update the YAML or Helm Chart at the same time. To enable only central election, you can also add permissions using the incremental upgrade instructions.
- If
InvalidImageNameoccurs or an image cannot be pulled, check the image address, registry permissions, and node network.
Verify the installation¶
Wait for the Operator to become ready, then test injection with the default Java Beacon rule. The server-side dry run goes through the cluster’s webhook without saving a Pod or pulling an image.
kubectl -n datakit rollout status deployment/datakit-operator --timeout=2m
kubectl -n default run datakit-injection-check \
--image=eclipse-temurin:17-jre \
--annotations='admission.datakit/beacon-java-lib.version=1.3.4' \
--dry-run=server -o jsonpath='{.spec.initContainers[*].name}{"\n"}'
If the output includes datakit-beacon-lib-init, the webhook injected Beacon into this request. If you customized the rules, adjust the namespace, labels, and annotations to match. If the expected init container is missing, see Troubleshoot injection.
Configuration¶
Check the rules configured in the cluster. To enable another feature, add the rule from its guide to the existing configuration and keep the rules for other features.
For a single-manifest deployment, edit data.jsonconfig in the datakit-operator-config ConfigMap. For Helm, edit configmap.jsonconfig in your values and upgrade the release. After editing the ConfigMap directly, restart the Operator, then recreate the application Pods that need the new rules.
Since v1.7.0, injection rules are configured under admission_inject_v2. The release includes a default Java Beacon rule. The otels and ddtraces lists are empty by default.
Upgrade an existing configuration¶
Back up the active jsonconfig before upgrading. Keeping it preserves your rules. If you adopt the new defaults, check the following for each workload.
- Beacon. For workloads that used
admission.datakit/beacon-language=java, add the version annotation required by the default rule or configure the Operator to match existing labels. - DDTrace and OTel. To keep using either probe, copy its rules and ensure Beacon does not select those workloads first. To switch to Beacon, verify the DataKit
opentelemetryinput, configure Beacon, and recreate the Pods. - logfwd and Flameshot. The default rules match the namespace exactly with
^default$. Add selectors for other namespaces you still need, such asdefault-test. Flameshot also requiresprocesses.
The legacy admission_inject configuration remains supported. A valid ddtrace, logfwd, or profiler entry in the legacy configuration overrides the corresponding v2 rules. Do not maintain two valid configurations for the same feature during an upgrade.
Injection Rules¶
In the Operator YAML, namespace_selectors matches the Pod’s namespace and label_selectors matches its existing labels. For features that support check_annotation, the rule then determines whether the Pod also needs an annotation.
| Operator rule | What to change in the workload |
|---|---|
check_annotation: false (default) |
Keep the existing namespace and labels, such as app=order-service. Matching Pods receive the injection without changes to the workload YAML. |
check_annotation: true |
Add the annotation required by the feature to the Pod template of each matching workload you want to instrument. |
Selector Configuration¶
namespace_selectors and label_selectors are both arrays:
- Multiple selectors in the same array are matched with OR.
- When both arrays are configured, both the Namespace and Label dimensions must match.
- Configure at least one selector list for injection. If you configure only one, a match in that list is sufficient.
- Logging configuration injection (
admission_mutate.loggings) requires both selector lists.
namespace_selectors uses Go regular expressions. The string "*" is shorthand for matching all Namespaces; use ^ and $ for exact matches. label_selectors uses Kubernetes Label Selector syntax and extends =, ==, and != with glob matching.
The following rule matches only Pods in the production Namespace that have the app=order-service label:
The Operator checks Beacon, OpenTelemetry, then DDTrace. For each probe it selects the first rule whose selectors and annotation requirements the Pod meets. Use selectors to distinguish workloads by language because the Operator does not detect the application language.
Annotation Configuration¶
Add Annotations to the Pod or to .spec.template.metadata.annotations in a controller such as a Deployment.
| Annotation | Purpose |
|---|---|
admission.datakit/enabled |
Controls all Operator changes to the Pod; has the highest priority |
admission.datakit/tracing.enabled |
Controls Beacon, OTel, and DDTrace together. Setting it to false still allows features such as logfwd |
admission.datakit/beacon.enabled |
Controls Beacon injection |
admission.datakit/otel.enabled |
Controls OTel injection |
admission.datakit/ddtrace.enabled |
Controls DDTrace injection |
admission.datakit/logfwd.enabled |
Controls logfwd injection |
admission.datakit/flameshot.enabled |
Controls Flameshot injection |
admission.datakit/profiler.enabled |
Controls legacy Profiler injection |
Set a switch to false to disable that feature. Missing or unparseable values default to true. A Pod with true must still meet the rule’s selector and annotation requirements.
check_annotation¶
| Feature | Annotation required when check_annotation: true |
|---|---|
| Beacon | admission.datakit/beacon-<language>-lib.version |
| OTel | admission.datakit/otel-<language>-lib.version |
| DDTrace | admission.datakit/<language>-lib.version |
| Profiler | admission.datakit/<language>-profiler.version |
| logfwd | admission.datakit/logfwd.instances |
A nonempty version value replaces the tag in image and keeps the registry and image name. The logfwd annotation supplies the logging configuration.
Image Pull Policy¶
In an admission_inject_v2 rule, set image_pull_policy alongside image. Allowed values are Always (default), IfNotPresent, and Never.
For example, configure the corresponding rule in admission_inject_v2.beacons as follows:
{
"name": "beacon-java",
"language": "java",
"namespace_selectors": ["^default$"],
"label_selectors": ["app=order-service"],
"image": "ghcr.io/beacon-observability/beacon-java:1.3.4",
"image_pull_policy": "IfNotPresent"
}
IfNotPresent reuses the local image when it is already present on the node; Never requires the image to be available on the node in advance. Use fixed versions to avoid reusing an old cached image with a mutable tag. This setting controls newly injected containers only. Helm's image.pullPolicy still controls only the Operator's own image.
After changing the configuration, restart the Operator and recreate the application Pods. Existing containers keep their pull policies. The deprecated admission_inject retains the default Always; to use the new setting, remove any active legacy configuration that overrides the corresponding v2 rules.
Environment Variable Value References¶
The envs field in an injection rule supports literal values and placeholders that are converted to native Kubernetes fieldRef, resourceFieldRef, and secretKeyRef references.
| Format | Description |
|---|---|
{fieldRef:metadata.name} |
Pod name |
{fieldRef:metadata.namespace} |
Pod Namespace |
{fieldRef:metadata.uid} |
Pod UID |
{fieldRef:metadata.annotations['<KEY>']} |
Specified Pod Annotation |
{fieldRef:metadata.labels['<KEY>']} |
Specified Pod Label |
{fieldRef:spec.serviceAccountName} |
ServiceAccount name |
{fieldRef:spec.nodeName} |
Node name |
{fieldRef:status.hostIP} |
Primary node IP |
{fieldRef:status.hostIPs} |
Dual-stack node IPs |
{fieldRef:status.podIP} |
Primary Pod IP |
{resourceFieldRef:limits.cpu} |
CPU limit of the first application container, in thousandths of a CPU core |
{resourceFieldRef:limits.memory} |
Memory limit of the first application container, in MiB |
{resourceFieldRef:requests.cpu} |
CPU request of the first application container, in thousandths of a CPU core |
{resourceFieldRef:requests.memory} |
Memory request of the first application container, in MiB |
{secretKeyRef:<SECRET_NAME>.<KEY>} |
Secret key in the Pod's Namespace |
Environment variables preserve configuration order. Later values can reference earlier variables using Kubernetes $(VAR) syntax:
{
"envs": {
"POD_NAME": "{fieldRef:metadata.name}",
"POD_NAMESPACE": "{fieldRef:metadata.namespace}",
"RESOURCE_TAGS": "pod_name=$(POD_NAME),pod_namespace=$(POD_NAMESPACE)"
}
}
Unrecognized placeholders are injected as ordinary strings. resourceFieldRef references only the first application container. If that container does not declare the corresponding request or limit, the environment variable is not injected.
{secretKeyRef:*}¶
The Secret reference format is:
For example:
{
"envs": {
"ACCESS_KEY_ID": "{secretKeyRef:flameshot-oss.access_key_id}",
"ACCESS_KEY_SECRET": "{secretKeyRef:flameshot-oss.access_key_secret}"
}
}
The Operator does not read the Secret; Kubernetes resolves the reference when the container starts. The Secret must be in the same Namespace as the application Pod. If the Secret or key does not exist, the Pod enters CreateContainerConfigError. Because . separates the Secret name from the key, the Secret name in this format cannot contain ..
Cluster API¶
DataKit Operator v1.8.1 and later provide the Cluster API. This API uses the Operator's Pod informer cache to proxy Pod data queries, reducing direct access to the API Server from each DataKit instance.
The Cluster API is enabled by default. At startup, the Operator checks whether its ServiceAccount has permission to read Pods. If permission is insufficient, the related routes are not registered. Before the Pod cache is synchronized, or if synchronization fails, the API returns 503, while other features continue to run. The minimum required permissions are:
The API uses the Operator Service. Its default address is https://datakit-operator.datakit.svc:443:
| Endpoint | Description |
|---|---|
/v1/cluster/api/v1/pods |
Queries all Pods |
/v1/cluster/api/v1/namespaces/{namespace}/pods |
Queries Pods in a specified Namespace |
/v1/cluster/api/v1/namespaces/{namespace}/pods/{name} |
Queries a specified Pod |
Starting with v1.8.9, use view=ebpf-v1 to obtain a reduced Pod representation for eBPF:
DataKit Central Election¶
Starting with DataKit Operator v1.9.1, DataKit Operator can replace DataWay/Kodo as the central election service for DataKit. This replaces only the election service; collected data is still uploaded through DataWay.
This feature is available only in Kubernetes. DataKit Operator and DataKit must run in the same Kubernetes cluster.
Before enabling the feature, note:
- Compatible versions: DataKit Operator v1.9.1 or later and DataKit 2.12.0 or later are required. Configure the environment variables manually.
- Lease and RBAC permissions: DataKit Operator stores election state in Kubernetes Leases and requires the corresponding read/write permissions. Lease is a native Kubernetes resource. No CRD installation or manual Lease creation is needed; DataKit Operator creates Leases on demand.
Enable Central Election¶
First upgrade DataKit Operator and grant the required permissions. Then configure the following environment variables consistently on every DataKit in the same election group and restart DataKit:
- name: ENV_ENABLE_ELECTION
value: "true"
- name: ENV_ELECTION_OPERATOR_URL
value: "https://datakit-operator.datakit.svc:443"
The example uses the default Service and namespace. Adjust the address for a custom deployment.
DataKit decides whether to use DataKit Operator only at startup. If the address is unset, the version is unsupported, permissions are missing, or the service is temporarily unavailable, DataKit continues to use DataWay/Kodo election. It does not switch services at runtime. Restart DataKit to reassess after changing the configuration or restoring DataKit Operator.
Before switching election services, confirm that DataKit Operator's election feature is available. Stop all DataKits in the same election group, apply the same configuration, and then start them again. Check their startup logs to confirm that they all use the same election service, avoiding duplicate collection caused by mixing services during a normal rolling update.
Add Permissions to an Existing Deployment¶
The new default YAML and Helm Chart include the Lease Role/RoleBinding. Existing deployments do not need to replace the entire YAML: after upgrading DataKit Operator, apply the following RBAC separately. Save it as datakit-operator-election-rbac.yaml. For a custom namespace or ServiceAccount, adjust metadata.namespace, subjects.namespace, and subjects.name. Leases are created in the Kubernetes namespace where DataKit Operator runs.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: datakit-operator-election
namespace: datakit
rules:
- apiGroups: ["coordination.k8s.io"]
resources: ["leases"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: datakit-operator-election
namespace: datakit
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: datakit-operator-election
subjects:
- kind: ServiceAccount
name: datakit-operator
namespace: datakit
kubectl apply -f datakit-operator-election-rbac.yaml
kubectl -n datakit rollout restart deployment/datakit-operator
kubectl -n datakit rollout status deployment/datakit-operator
After granting the permissions, configure and restart DataKit as described above. A missing Lease object is not an error. Missing Lease permissions make central election unavailable but do not affect other DataKit Operator services.
FAQ¶
Disable Pod Changes¶
Add the following to the Pod template:
Why Did Injection Not Take Effect?¶
Check the following in order:
- Whether the Pod was recreated after the configuration update.
- Whether its Namespace and Label match the same rule.
- Check whether the global
admission.datakit/enabledswitch or the feature switch isfalse. For Beacon, OpenTelemetry, or DDTrace, also checkadmission.datakit/tracing.enabled. - When
check_annotation: true, whether the correct version or configuration Annotation is present. - Whether the Operator logs contain warnings about selectors, images, environment variables, or security context conflicts.
If the Pod is stuck in initialization, inspect the init container events and logs. For an image pull failure, check the image address, node connectivity, and registry credentials.
What Should I Consider on AWS EKS?¶
The EKS control plane must be able to access port 9543 on the Operator webhook. If injection does not take effect, check whether the cluster security groups and network policies allow traffic in that direction.
DDTrace is a tracing project initiated and open-sourced by Datadog. Copyright belongs to Datadog and other contributors. Guance supports DDTrace data ingestion. Use of DDTrace is subject to the applicable project's open-source license.