Home > OS >  How to debug Unknown field error in Kubernetes?
How to debug Unknown field error in Kubernetes?

Time:05-14

This might be rookie question. I am not well versed with kubernetes. I added this to my deployment.yaml

ad.datadoghq.com/helm-chart.check_names: |
          ["openmetrics"]
ad.datadoghq.com/helm-chart.init_configs: |
          [{}]
ad.datadoghq.com/helm-chart.instances: |
          [
            {
              "prometheus_url": "http://%%host%%:7071/metrics",
              "namespace": "custom-metrics",
              "metrics": [ "jvm*" ]
            }
          ]

But I get this error

error validating data: [ValidationError(Deployment.spec.template.metadata): unknown field "ad.datadoghq.com/helm-chart.check_names" in io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta, ValidationError(Deployment.spec.template.metadata)

What does this error mean? Does it mean that I need to define ad.datadoghq.com/helm-chart.check_names somewhere? If so, where?

CodePudding user response:

You are probably adding this in a wrong place - according to your error messages - you're adding this to Deployment.spec.template.metadata

you can check official helm deployment template and this example on documentation - values such ad.datadoghq.com/helm-chart.check_names are annotations, so these needs to be defined under path Deployment.spec.template.metadata.annotations

annotations: a map of string keys and values that can be used by external tooling to store and retrieve arbitrary metadata about this object (see the annotations docs)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: datadog-cluster-agent
  namespace: default
spec:
  selector:
    matchLabels:
      app: datadog-cluster-agent
  template:
    metadata: # <- not directly under 'metadata'
      labels:
        app: datadog-cluster-agent
      name: datadog-agent
      annotations: # <- add here
        ad.datadoghq.com/datadog-cluster-agent.check_names: '["prometheus"]'
        ad.datadoghq.com/datadog-cluster-agent.init_configs: '[{}]'
        ad.datadoghq.com/datadog-cluster-agent.instances: '[{"prometheus_url": "http://%%host%%:5000/metrics","namespace": "datadog.cluster_agent","metrics": ["go_goroutines","go_memstats_*","process_*","api_requests","datadog_requests","external_metrics", "cluster_checks_*"]}]'
    spec:
  • Related