Skip to content

Commit 6a99244

Browse files
authored
added examples for cli flags usage
1 parent 104c83f commit 6a99244

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

docs/developer/cli-arguments.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,95 @@ Use "kube-state-metrics [command] --help" for more information about a command.
9292
```
9393
<!-- markdownlint-enable link-image-reference-definitions -->
9494
<!-- markdownlint-enable blanks-around-fences -->
95+
96+
## Examples
97+
98+
```bash
99+
# Bool flag
100+
kube-state-metrics --enable-gzip-encoding
101+
```
102+
103+
```bash
104+
# Int flag
105+
kube-state-metrics --port=9090
106+
```
107+
108+
```bash
109+
# String flag
110+
kube-state-metrics --apiserver="https://my-apiserver:6443"
111+
```
112+
113+
```bash
114+
# Duration flags
115+
kube-state-metrics --server-idle-timeout=2m --server-write-timeout=30s
116+
```
117+
118+
```bash
119+
# List flags (formatted as a single string)
120+
kube-state-metrics \
121+
--metric-allowlist="kube_pod_info,kube_node_*" \
122+
--metric-denylist="kube_pod_labels_total,kube_service_info" \
123+
--metric-annotations-allowlist="namespaces=[kubernetes.io/team],pods=[owner]" \
124+
--metric-labels-allowlist="namespaces=[kubernetes.io/team],pods=[owner]" \
125+
--namespaces-denylist="default,kube-system"
126+
```
127+
## Config-file support
128+
You can provide a YAML config file using the `--config` flag instead of (or in addition to) command-line flags. Any flags passed on the command line will override values in the config file.
129+
130+
Example `config.yaml`:
131+
```yaml
132+
port: 9090
133+
serverIdleTimeout: "2m"
134+
metricAllowlist:
135+
- kube_pod_info
136+
- kube_node_*
137+
```
138+
139+
Run with config file:
140+
```bash
141+
kube-state-metrics --config=config.yaml --port=8085
142+
```
143+
144+
## Mutual-exclusion of allowlists and denylists
145+
For metrics, annotations, and labels, allowlists and denylists cannot be used together. If both are specified, the allowlist takes precedence and the denylist is ignored.
146+
147+
## Kubernetes Deployment example
148+
You can embed any of the flags in a Deployment manifest under `args:`:
149+
```yaml
150+
spec:
151+
template:
152+
spec:
153+
containers:
154+
- name: kube-state-metrics
155+
args:
156+
- "--metric-allowlist=kube_pod_info,kube_node_*"
157+
- "--server-idle-timeout=2m"
158+
```
159+
160+
## Experimental flags
161+
The following flags are experimental and subject to change:
162+
- `--auto-gomemlimit`, `--auto-gomemlimit-ratio`
163+
- `--auth-filter`
164+
- `--shard`, `--total-shards`
165+
- `--track-unscheduled-pods`
166+
167+
## Custom Resource State metrics
168+
You can enable custom resource state metrics using:
169+
```bash
170+
kube-state-metrics --custom-resource-state-config-file=crs-config.yaml
171+
```
172+
Example `crs-config.yaml`:
173+
```yaml
174+
resources:
175+
pods:
176+
state:
177+
- Pending
178+
- Running
179+
```
180+
181+
## Auth-filter example
182+
Protect the metrics endpoint with Kubernetes RBAC by enabling the auth filter and providing a kubeconfig:
183+
```bash
184+
kube-state-metrics --auth-filter --kubeconfig=/etc/kubernetes/kubeconfig
185+
```
186+
Ensure the service account used has a Role or ClusterRole granting `get` on `metrics.k8s.io` in the desired namespace.

0 commit comments

Comments
 (0)