You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Daemonset sharding for pod metrics](#daemonset-sharding-pod-metrics)
48
49
-[Setup](#setup)
49
50
-[Building the Docker container](#building-the-docker-container)
50
51
-[Usage](#usage)
@@ -235,6 +236,36 @@ This way of deploying shards is useful when you want to manage KSM shards throug
235
236
236
237
The downside of using an auto-sharded setup comes from the rollout strategy supported by `StatefulSet`s. When managed by a `StatefulSet`, pods are replaced one at a time with each pod first getting terminated and then recreated. Besides such rollouts being slower, they will also lead to short downtime for each shard. If a Prometheus scrape happens during a rollout, it can miss some of the metrics exported by kube-state-metrics.
237
238
239
+
### Daemonset sharding for pod metrics
240
+
241
+
For pod metrics, they can be sharded per node with the following flag:
242
+
*`--node`
243
+
244
+
Each kube-state-metrics pod uses FieldSelector (spec.nodeName) to watch/list pod metrics only on the same node.
Copy file name to clipboardExpand all lines: docs/cli-arguments.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,6 +46,7 @@ Usage of ./kube-state-metrics:
46
46
--metric-opt-in-list string Comma-separated list of metrics which are opt-in and not enabled by default. This is in addition to the metric allow- and denylists
47
47
--namespaces string Comma-separated list of namespaces to be enabled. Defaults to ""
48
48
--namespaces-denylist string Comma-separated list of namespaces not to be enabled. If namespaces and namespaces-denylist are both set, only namespaces that are excluded in namespaces-denylist will be used.
49
+
--node string Name of the node that contains the kube-state-metrics pod. Most likely it should be passed via the downward API. This is used for daemonset sharding. Only available for resources (pod metrics) that support spec.nodeName fieldSelector. This is experimental.
49
50
--one_output If true, only write logs to their native severity level (vs also writing to each lower severity level; no effect when -logtostderr=true)
50
51
--pod string Name of the pod that contains the kube-state-metrics container. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
51
52
--pod-namespace string Name of the namespace of the pod specified by --pod. When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice.
Copy file name to clipboardExpand all lines: pkg/options/options.go
+17Lines changed: 17 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,7 @@ type Options struct {
39
39
ResourcesResourceSet
40
40
NamespacesNamespaceList
41
41
NamespacesDenylistNamespaceList
42
+
NodeNodeType
42
43
Shardint32
43
44
TotalShardsint
44
45
Podstring
@@ -111,6 +112,8 @@ func (o *Options) AddFlags() {
111
112
o.flags.Int32Var(&o.Shard, "shard", int32(0), "The instances shard nominal (zero indexed) within the total number of shards. (default 0)")
112
113
o.flags.IntVar(&o.TotalShards, "total-shards", 1, "The total number of shards. Sharding is disabled when total shards is set to 1.")
113
114
115
+
o.flags.StringVar((*string)(&o.Node), "node", "", "Name of the node that contains the kube-state-metrics pod. Most likely it should be passed via the downward API. This is used for daemonset sharding. Only available for resources (pod metrics) that support spec.nodeName fieldSelector. This is experimental.")
116
+
114
117
autoshardingNotice:="When set, it is expected that --pod and --pod-namespace are both set. Most likely this should be passed via the downward API. This is used for auto-detecting sharding. If set, this has preference over statically configured sharding. This is experimental, it may be removed without notice."
115
118
116
119
o.flags.StringVar(&o.Pod, "pod", "", "Name of the pod that contains the kube-state-metrics container. "+autoshardingNotice)
@@ -132,3 +135,17 @@ func (o *Options) Parse() error {
132
135
func (o*Options) Usage() {
133
136
o.flags.Usage()
134
137
}
138
+
139
+
// Validate validates arguments
140
+
func (o*Options) Validate() error {
141
+
shardableResource:="pods"
142
+
ifo.Node=="" {
143
+
returnnil
144
+
}
145
+
for_, x:=rangeo.Resources.AsSlice() {
146
+
ifx!=shardableResource {
147
+
returnfmt.Errorf("Resource %s can't be sharded by field selector spec.nodeName", x)
0 commit comments