- 
                Notifications
    
You must be signed in to change notification settings  - Fork 119
 
Description
It would be great if agents could read kubernetes data from environment variables and add it automatically to metadata sent to APM Server. This would work both for kubernetes setups where APM Server runs self-hosted and in the future where APM Server could be hosted.
I'll file a separate issue for the APM Server work.
Users set the environment variables through the DownwardAPI.
Here's a table mapping the environment variable to the metadata event field:
| Environment variable | Field name | 
|---|---|
| KUBERNETES_NODE_NAME | system.kubernetes.node.name | 
| KUBERNETES_POD_NAME | system.kubernetes.pod.name | 
| KUBERNETES_NAMESPACE | system.kubernetes.namespace | 
| KUBERNETES_POD_UID | system.kubernetes.pod.uid | 
Elasticsearch documents will use kubernetes.node.name (and not system.kubernetes.node.name) etc., so it aligns with the fields generated by filebeat, except for a few:
container.*fields which we don't seem to have access to unfortunately.annotations: off by default in filebeat because people use them to store all sorts of large objectslabels: could be very useful down the line, but lets start without as an MVP
Here's how a user would add the environment variables to their kubernetes pod spec:
         - name: KUBERNETES_NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: KUBERNETES_POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: KUBERNETES_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: KUBERNETES_POD_UID
            valueFrom:
              fieldRef:
                fieldPath: metadata.uid
@elastic/apm-agent-devs Please link your issue or PR and then mark the checkbox when the implementation is merged:
- - Java - Read k8s data from environment variables apm-agent-java#344
 - - Python Add kubernetes metadata to system data apm-agent-python#347
 - - Ruby - Read k8s data from environment variables apm-agent-ruby#252
 - - Go - Add k8s pod metadata apm-agent-go#329
 - - dotNet - Report kubernetes system metadata apm-agent-dotnet#181
 - - Node.js - feat: add Kubernetes data to metadata apm-nodejs-http-client#34
 - - Documentation - Docs: add kubernetes metadata apm-server#1650
 - - APM Server Allow APM Server to receive k8s/container information from agents apm-server#1621
 
Potential additional fields that we should not do now
| Environment variable | Field name | 
|---|---|
| KUBERNETES_POD_IP | system.kubernetes.pod.ip | 
| KUBERNETES_NODE_IP | system.kubernetes.node.ip | 
| KUBERNETES_LABELS_* | system.kubernetes.labels.* | 
          - name: KUBERNETES_POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          - name: KUBERNETES_NODE_IP
            valueFrom:
              fieldRef:
                fieldPath: status.hostIP
          - name: KUBERNETES_LABELS_APP
            valueFrom:
              fieldRef:
                fieldPath: metadata.labels['app']