Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[simple-app] Add management of common Datadog Agent labels, annotatio…
…ns and environment variables (#30) **What did I want?** To provide a standard and easy mechanism for configuring our Pods to work with the Datadog Agent and pass the appropriate metrics back to Datadog. **What did I do?** I've added in customizations for setting common environment variables, annotations and labels. Depending on whether or not we're running the Istio mesh or not, the behavior is slightly different. **Proof** ## Scenario 1: `istio.enabled=false`, `datadog.enabled=true`, `datadog.scrapeMetrics=true` ```diff install.go:173: [debug] Original chart version: "" install.go:190: [debug] CHART PATH: /Users/diranged/git/nextdoor/k8s-charts/charts/simple-app --- orig 2021-06-22 08:19:44.000000000 -0700 +++ new 2021-06-22 09:43:38.000000000 -0700 @@ -8,11 +8,22 @@ metadata: name: simple-app-ingress-access labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: policyTypes: [Ingress] podSelector: @@ -32,11 +43,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # --- # Source: simple-app/templates/service.yaml apiVersion: v1 @@ -44,11 +66,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: type: ClusterIP ports: @@ -70,11 +103,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: replicas: 1 selector: @@ -84,12 +128,32 @@ template: metadata: annotations: - labels: - helm.sh/chart: simple-app-0.10.0 + ad.datadoghq.com/simple-app.check_names: ['prometheus'] + ad.datadoghq.com/simple-app.init_configs: '[{}]' + ad.datadoghq.com/simple-app.instances: |- + [ + { + "prometheus_url": "http://%%host%%:9090/metrics", + "namespace": "eks" + } + ] + labels: + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: serviceAccountName: simple-app securityContext: @@ -100,6 +164,30 @@ {} image: nginx:latest imagePullPolicy: IfNotPresent + env: + # https://www.datadoghq.com/blog/monitor-kubernetes-docker/#instrument-your-code-to-send-metrics-to-dogstatsd + - name: DOGSTATSD_HOST_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + # https://docs.datadoghq.com/agent/docker/apm/?tab=standard#docker-apm-agent-environment-variables + - name: DD_AGENT_HOST + valueFrom: + fieldRef: + fieldPath: status.hostIP + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes#full-configuration + - name: DD_ENV + valueFrom: + fieldRef: + fieldPath: metadata.labels['tags.datadoghq.com/env'] + - name: DD_SERVICE + valueFrom: + fieldRef: + fieldPath: metadata.labels['tags.datadoghq.com/service'] + - name: DD_VERSION + valueFrom: + fieldRef: + fieldPath: metadata.labels['tags.datadoghq.com/version'] resources: {} ports: @@ -127,11 +215,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # annotations: spec: rules: @@ -337,11 +436,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: selector: matchLabels: @@ -386,11 +496,22 @@ metadata: name: "simple-app-test-connection" labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # annotations: "helm.sh/hook": test spec: ``` ## Scenario 2: `istio.enabled=true`, `datadog.enabled=true,` `datadog.scrapeMetrics=true` ```diff install.go:173: [debug] Original chart version: "" install.go:190: [debug] CHART PATH: /Users/diranged/git/nextdoor/k8s-charts/charts/simple-app --- orig 2021-06-22 08:19:44.000000000 -0700 +++ new 2021-06-22 09:44:42.000000000 -0700 @@ -8,11 +8,22 @@ metadata: name: simple-app-ingress-access labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: policyTypes: [Ingress] podSelector: @@ -32,11 +43,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # --- # Source: simple-app/templates/service.yaml apiVersion: v1 @@ -44,11 +66,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: type: ClusterIP ports: @@ -70,11 +103,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: replicas: 1 selector: @@ -84,12 +128,36 @@ template: metadata: annotations: - labels: - helm.sh/chart: simple-app-0.10.0 + proxy.istio.io/config: '{ "holdApplicationUntilProxyStarts": true }' + prometheus.io/scrape: "true" + prometheus.io/port: "9090" + prometheus.io/path: /metrics + ad.datadoghq.com/istio-proxy.check_names: ['prometheus'] + ad.datadoghq.com/istio-proxy.init_configs: '[{}]' + ad.datadoghq.com/istio-proxy.instances: |- + [ + { + "prometheus_url": "http://%%host%%:15020/stats/prometheus", + "namespace": "eks" + } + ] + labels: + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # spec: serviceAccountName: simple-app securityContext: @@ -100,6 +168,30 @@ {} image: nginx:latest imagePullPolicy: IfNotPresent + env: + # https://www.datadoghq.com/blog/monitor-kubernetes-docker/#instrument-your-code-to-send-metrics-to-dogstatsd + - name: DOGSTATSD_HOST_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + # https://docs.datadoghq.com/agent/docker/apm/?tab=standard#docker-apm-agent-environment-variables + - name: DD_AGENT_HOST + valueFrom: + fieldRef: + fieldPath: status.hostIP + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes#full-configuration + - name: DD_ENV + valueFrom: + fieldRef: + fieldPath: metadata.labels['tags.datadoghq.com/env'] + - name: DD_SERVICE + valueFrom: + fieldRef: + fieldPath: metadata.labels['tags.datadoghq.com/service'] + - name: DD_VERSION + valueFrom: + fieldRef: + fieldPath: metadata.labels['tags.datadoghq.com/version'] resources: {} ports: @@ -127,11 +219,22 @@ metadata: name: simple-app labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # annotations: spec: rules: @@ -331,27 +434,6 @@ name: redis protocol: REDIS --- -# Source: simple-app/templates/servicemonitor.yaml -apiVersion: monitoring.coreos.com/v1 -kind: ServiceMonitor -metadata: - name: simple-app - labels: - helm.sh/chart: simple-app-0.10.0 - app.kubernetes.io/version: "latest" - app.kubernetes.io/managed-by: Helm - app.kubernetes.io/name: simple-app - app.kubernetes.io/instance: simple-app -spec: - selector: - matchLabels: - app.kubernetes.io/name: simple-app - app.kubernetes.io/instance: simple-app - endpoints: - - port: metrics - path: /metrics - scheme: http ---- # Source: simple-app/charts/istio-endpoints/templates/sidecar.yaml apiVersion: networking.istio.io/v1beta1 kind: Sidecar @@ -386,11 +468,22 @@ metadata: name: "simple-app-test-connection" labels: - helm.sh/chart: simple-app-0.10.0 + helm.sh/chart: simple-app-0.11.0 app.kubernetes.io/version: "latest" app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: simple-app app.kubernetes.io/instance: simple-app + # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging/?tab=kubernetes + tags.datadoghq.com/env: "dev" + tags.datadoghq.com/service: "simple-app" + tags.datadoghq.com/version: "latest" + # + # https://docs.datadoghq.com/agent/cluster_agent/admission_controller/ + # (Disabled for now, here for future reference. Disabled because we can get + # the same value through the Kubernetes downward API, which doesn't introduce + # a potential Pod launching failure point.) + # admission.datadoghq.com/enabled: "true" + # annotations: "helm.sh/hook": test spec: ```
- Loading branch information