Skip to content

Commit 6b36b88

Browse files
committed
added docs for high availability
1 parent 61be81f commit 6b36b88

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ are deleted they are no longer visible on the `/metrics` endpoint.
5353
* [Horizontal sharding](#horizontal-sharding)
5454
* [Automated sharding](#automated-sharding)
5555
* [Daemonset sharding for pod metrics](#daemonset-sharding-for-pod-metrics)
56+
* [High Availability](#high-availability)
5657
* [Setup](#setup)
5758
* [Building the Docker container](#building-the-docker-container)
5859
* [Usage](#usage)
@@ -304,6 +305,50 @@ spec:
304305

305306
Other metrics can be sharded via [Horizontal sharding](#horizontal-sharding).
306307

308+
### High Availability
309+
310+
Kube-state-metrics is a stateless service that reads from the Kubernetes API server. Be aware that multiple replicas increase the load on the Kubernetes API. Therefore, in most cases a single replica is also an option since most users scrape with a 30s interval. If you have the need for a higher scrape frequency or you have other constraints that require multiple replica, you can increase the availablity of kube-state-metrics in the following way:
311+
312+
For high availability, run multiple kube-state-metrics replicas to prevent a single point of failure. A common setup uses at least 2 replicas, pod anti-affinity rules to ensure they run on different nodes, and a PodDisruptionBudget (PDB) with `minAvailable: 1` to protect against voluntary disruptions.
313+
314+
```yaml
315+
apiVersion: apps/v1
316+
kind: Deployment
317+
metadata:
318+
name: kube-state-metrics
319+
spec:
320+
replicas: 2
321+
template:
322+
spec:
323+
affinity:
324+
podAntiAffinity:
325+
preferredDuringSchedulingIgnoredDuringExecution:
326+
- weight: 100
327+
podAffinityTerm:
328+
labelSelector:
329+
matchLabels:
330+
app: kube-state-metrics
331+
topologyKey: kubernetes.io/hostname
332+
containers:
333+
- name: kube-state-metrics
334+
image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.10.0
335+
ports:
336+
- containerPort: 8080
337+
name: http-metrics
338+
---
339+
apiVersion: policy/v1
340+
kind: PodDisruptionBudget
341+
metadata:
342+
name: kube-state-metrics-pdb
343+
spec:
344+
minAvailable: 1
345+
selector:
346+
matchLabels:
347+
app: kube-state-metrics
348+
```
349+
350+
If metrics get scraped at the service level via a ServiceMonitor (Prometheus-Operator) or similar, metrics won't need to be deduplicated in a HA setup.
351+
307352
### Setup
308353
309354
Install this project to your `$GOPATH` using `go get`:

README.md.tpl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ are deleted they are no longer visible on the `/metrics` endpoint.
5353
* [Horizontal sharding](#horizontal-sharding)
5454
* [Automated sharding](#automated-sharding)
5555
* [Daemonset sharding for pod metrics](#daemonset-sharding-for-pod-metrics)
56+
* [High Availability](#high-availability)
5657
* [Setup](#setup)
5758
* [Building the Docker container](#building-the-docker-container)
5859
* [Usage](#usage)
@@ -305,6 +306,50 @@ spec:
305306

306307
Other metrics can be sharded via [Horizontal sharding](#horizontal-sharding).
307308

309+
### High Availability
310+
311+
Kube-state-metrics is a stateless service that reads from the Kubernetes API server. Be aware that multiple replicas increase the load on the Kubernetes API. Therefore, in most cases a single replica is also an option since most users scrape with a 30s interval. If you have the need for a higher scrape frequency or you have other constraints that require multiple replica, you can increase the availablity of kube-state-metrics in the following way:
312+
313+
For high availability, run multiple kube-state-metrics replicas to prevent a single point of failure. A common setup uses at least 2 replicas, pod anti-affinity rules to ensure they run on different nodes, and a PodDisruptionBudget (PDB) with `minAvailable: 1` to protect against voluntary disruptions.
314+
315+
```yaml
316+
apiVersion: apps/v1
317+
kind: Deployment
318+
metadata:
319+
name: kube-state-metrics
320+
spec:
321+
replicas: 2
322+
template:
323+
spec:
324+
affinity:
325+
podAntiAffinity:
326+
preferredDuringSchedulingIgnoredDuringExecution:
327+
- weight: 100
328+
podAffinityTerm:
329+
labelSelector:
330+
matchLabels:
331+
app: kube-state-metrics
332+
topologyKey: kubernetes.io/hostname
333+
containers:
334+
- name: kube-state-metrics
335+
image: registry.k8s.io/kube-state-metrics/kube-state-metrics:v2.10.0
336+
ports:
337+
- containerPort: 8080
338+
name: http-metrics
339+
---
340+
apiVersion: policy/v1
341+
kind: PodDisruptionBudget
342+
metadata:
343+
name: kube-state-metrics-pdb
344+
spec:
345+
minAvailable: 1
346+
selector:
347+
matchLabels:
348+
app: kube-state-metrics
349+
```
350+
351+
If metrics get scraped at the service level via a ServiceMonitor (Prometheus-Operator) or similar, metrics won't need to be deduplicated in a HA setup.
352+
308353
### Setup
309354

310355
Install this project to your `$GOPATH` using `go get`:

0 commit comments

Comments
 (0)