prometheus-operator: The CustomResourceDefinition "prometheuses.monitoring.coreos.com" is invalid: metadata.annotations: Too long: must have at most 262144 bytes

What happened?

Did you expect to see something different?

How to reproduce it (as minimally and precisely as possible):

Environment

  • Prometheus Operator version:

    Insert image tag or Git SHA here

  • Kubernetes version information:

    kubectl version Client Version: version.Info{Major:“1”, Minor:“21”, GitVersion:“v1.21.0”, GitCommit:“cb303e613a121a29364f75cc67d3d580833a7479”, GitTreeState:“clean”, BuildDate:“2021-04-08T16:31:21Z”, GoVersion:“go1.16.1”, Compiler:“gc”, Platform:“linux/amd64”} Server Version: version.Info{Major:“1”, Minor:“18+”, GitVersion:“v1.18.20-eks-8c579e”, GitCommit:“8c579edfc914f013ff48b2a2b2c1308fdcacc53f”, GitTreeState:“clean”, BuildDate:“2021-07-31T01:34:13Z”, GoVersion:“go1.13.15”, Compiler:“gc”, Platform:“linux/amd64”}

  • Kubernetes cluster kind:

Using EKS Cluster

  • Manifests:
Used this guide to install 
https://grafana.com/docs/grafana-cloud/quickstart/prometheus_operator/
Bundle yml : kubectl apply -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/bundle.yaml
  • Prometheus Operator Logs:
insert Prometheus Operator logs relevant to the issue here

Anything else we need to know?:

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

This is also important when you use a Delivery tool like argoCD for example.

For ArgoCD since 2.5 version there is a solution https://blog.ediri.io/kube-prometheus-stack-and-argocd-25-server-side-apply-to-the-rescue

Can you try with kubectl create. The issue is due to large annotation size which will be issue for kubectl apply since it stores last applied config.

@paulfantom Is using kubectl create instead of kubectl apply right now the best approach? We’re generating our monitoring stack based on kube-prometheus and applying those manifests in every pipeline run, this is now somehow blocked, because we would need to handle that edge-case differently and that just feels bad.

It works with create.

$ kubectl create -f https://raw.githubusercontent.com/prometheus-operator/prometheus-operator/master/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created

It fails with apply even if the CRD didn’t previously exist.

kubectl apply will store kubernetes.io/last-applied-configuration annotation even if we are creating a new resource 😃

This is also important when you use a Delivery tool like argoCD for example.

@guusvw that’s kubernetes restriction (as mentioned in https://github.com/prometheus-operator/prometheus-operator/issues/4355#issuecomment-955899678) and using kubectl create and/or kubectl replace to apply CRDs is considered a valid workaround by kubernetes-sigs. FYI tools like argoCD have an internal logic to handle such cases by removing and creating object if needed. However if you use only kubectl you need to put that logic into your tooling. Something like kubectl replace -f crds/ || kubectl create -f crds/ should do the trick.

As for kube-prometheus, we can simplify things for you by moving CRDs to a separate directory in manifests/ if that would help. Just file an issue in the project first 😃

https://github.com/prometheus-operator/prometheus-operator/pull/4937 is a quick hack. It would be good if you could test it.