Injecting DDTrace via DataKit Operator¶
Usage Instructions¶
- Download and install DataKit-Operator in the target Kubernetes cluster.
-
Add the following ConfigMap configuration to the Operator:
{ "server_listen": "0.0.0.0:9543", // Service listening address "log_level": "info", // Log level "admission_inject_v2": { // Injection config v2 (operator version >= v1.7.0) "ddtraces": [ // DDTrace configuration array { // Fill in DDTrace injection config here... }, { // Can inject another DDTrace config... } ] }, "admission_inject": { // Injection config v1 "ddtrace": { // Fill in DDTrace injection config here... // For v1 config, operator only supports injecting one DDTrace config. v2 is recommended for flexibility. } }, }DDTrace injection has the following configurable fields:
Field Type Description Required Example Value envsobject Environment variable map Y4 See example below imagestring DDTrace image address Y2 See example below label_selectorsarray Label selector array Y1 ["app=nginx", "tier=frontend"]languagestring Supported language type (optional java)Y3 "java"namespace_selectorsarray Namespace selector, supports regex Y1 ["prod-*", "test"]resourcesobject Resource limit configuration N See example below enabled_namespacesobject Select target Kubernetes namespace and set development language Y Deprecated in 1.7.0 admission_inject_v2enabled_labelselectorsobject Select target using Kubernetes label Y Deprecated in 1.7.0 admission_inject_v2Here is an example:
{ "namespace_selectors": [], "label_selectors": [], "image": "pubrepo.guance.com/datakit-operator/dd-lib-java-init:v1.55.10-ext", "language": "java", "envs": { "DD_AGENT_HOST": "datakit-service.datakit.svc.cluster.local", "DD_TRACE_AGENT_PORT": "9529", "DD_JMXFETCH_STATSD_HOST": "datakit-service.datakit.svc.cluster.local", "DD_JMXFETCH_STATSD_PORT": "8125", "DD_SERVICE": "{fieldRef:metadata.labels['service']}", "POD_NAME": "{fieldRef:metadata.name}", "POD_NAMESPACE": "{fieldRef:metadata.namespace}", "NODE_NAME": "{fieldRef:spec.nodeName}", "DD_TAGS": "pod_name:$(POD_NAME),pod_namespace:$(POD_NAMESPACE),host:$(NODE_NAME)" }, "resources": { "requests": { "cpu": "100m", "memory": "64Mi" }, "limits": { "cpu": "500m", "memory": "512Mi" } } }
Handling Special Deployments¶
The Operator configuration above is for DDTrace injection across the entire cluster. Sometimes this one-size-fits-all approach is not suitable for certain specific Deployments. Therefore, we can make some Annotation markings for these Deployments individually:
The Operator can recognize the following two Annotations:
admission.datakit/ddtrace.enabled: Marks whether to enable injection in a single Deployment standard. Fill in"true"to enable injection,"false"to block injection. If blocked, the Operator will ignore injecting this Deployment.admission.datakit/java-lib.version: Specifies a specific DDTrace version.
Annotation Example¶
Mark whether to inject in Deployment:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
labels:
app: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
annotations:
admission.datakit/ddtrace.enabled: "true"
spec:
containers:
- name: my-app
image: my-app:1.2.3
ports:
- containerPort: 80
Inject specific version of dd-java-lib into Deployment 5:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-app-deployment
labels:
app: my-app
spec:
replicas: 1
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app
annotations:
admission.datakit/java-lib.version: "v1.55.10-ext"
spec:
containers:
- name: my-app
image: my-app:1.2.3
ports:
- containerPort: 80
Create resources using the yaml file:
Verify as follows:
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
my-app-deployment-7bd8dd85f-fzmt2 1/1 Running 0 4s
$ kubectl get pod my-app-deployment-7bd8dd85f-fzmt2 -o=jsonpath={.spec.initContainers\[\*\].name}
datakit-lib-init
-
This field must be filled; otherwise, the Operator will reject the injection. ↩↩
-
Although the Operator has a built-in default image address, users generally need to copy the image to the internal network for offline environments and then use the internal image address. ↩
-
The language selected here must match the content of the corresponding DDTrace image. If it does not match, the injection will fail. ↩
-
These environment variable settings are crucial and directly affect the final data outcome. For the supported
fieldReflist here, see here. ↩ -
What is replaced here is a different version of the same image address in the Operator ConfigMap; different image addresses cannot be switched here. ↩