There's another useful metric that you can use to create annotations when you deploy, if you have kube-state-metrics configured on your cluster: kube_replicaset_created.
This metric exists for every ReplicaSet that has been created recently, with a label identifying which RS it refers to, and a value referencing the timestamp when the RS was created. If you're using a Deployment to manage your app's pod lifecycle, every time you release a new image or change the config, it will result in a new ReplicaSet being created. We can use this to write a Prometheus query which will create an annotation every time a RS is created:
The kube_replicaset_created metric value is a timestamp measured in seconds, so we can use the max aggregation function to get the timestamp of the most-recently created RS.
Since we only want our Grafana annotation to appear every time a new RS is created, we need the query value to be 0 unless a replicaset has just been created. Using the changes function, combined with the subquery [1m:], gives us this.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There's another useful metric that you can use to create annotations when you deploy, if you have
kube-state-metrics
configured on your cluster:kube_replicaset_created
.This metric exists for every ReplicaSet that has been created recently, with a label identifying which RS it refers to, and a value referencing the timestamp when the RS was created. If you're using a Deployment to manage your app's pod lifecycle, every time you release a new image or change the config, it will result in a new ReplicaSet being created. We can use this to write a Prometheus query which will create an annotation every time a RS is created:
To break down what this query is doing:
kube_replicaset_created
metric value is a timestamp measured in seconds, so we can use themax
aggregation function to get the timestamp of the most-recently created RS.changes
function, combined with the subquery[1m:]
, gives us this.