-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: describe the config file format in the CLI docs #2473
Open
ringerc
wants to merge
1
commit into
kubernetes:main
Choose a base branch
from
ringerc:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# Command line arguments | ||
|
||
kube-state-metrics can be configured through command line arguments. | ||
kube-state-metrics can be configured through command line arguments and/or a configuration file. | ||
|
||
Those arguments can be passed during startup when running locally: | ||
|
||
|
@@ -19,6 +19,8 @@ spec: | |
- '--apiserver=<APISERVER>' | ||
``` | ||
|
||
or via the `--config` option pointing to a [config file](#config-file-format). | ||
|
||
## Available options | ||
|
||
<!-- markdownlint-disable blanks-around-fences --> | ||
|
@@ -88,5 +90,83 @@ Flags: | |
|
||
Use "kube-state-metrics [command] --help" for more information about a command. | ||
``` | ||
|
||
## Config file format | ||
|
||
The above CLI options may also be set via a YAML-format config-file whose path is supplied as the `--config` argument on the CLI. | ||
|
||
The option names are defined in [`type Options` in `pkg/options/options.go`](https://github.com/kubernetes/kube-state-metrics/blob/main/pkg/options/options.go#L42). | ||
|
||
A sample configuration might look like: | ||
|
||
```yaml | ||
auto-gomemlimit: true | ||
auto-gomemlimit-ratio: 0.9 | ||
# Equivalent of --metric-labels-allowlist CLI option. type LabelsAllowList map[string][]string | ||
labels_allow_list: | ||
"*": | ||
# will map to {resourcekind}_labels label label_k8s_kapp_k14s_io_app: | ||
- kapp.k14s.io/app | ||
- mycompany/some-label | ||
- mycompany/anotherlabel | ||
# check kube_node_info before adding info here: | ||
nodes: | ||
- kubernetes.io/os | ||
- kubernetes.io/arch | ||
- node.kubernetes.io/instance-type | ||
- eks.amazonaws.com/nodegroup | ||
- eks.amazonaws.com/nodegroup-image | ||
``` | ||
|
||
### Using a config file with Kubernetes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't specific to KSM, but general knowledge to mount any configmap. Can we drop this? |
||
|
||
On a Kubernetes deployment you will need to: | ||
|
||
* add a volume mapping the ConfigMap containing the configuration into the app resource (`Deployment`, `DaemonSet`, etc) for `kube-state-metrics` | ||
* add a volumeMount exposing the configmap on a path in the workload | ||
* append an appropriate `--config` argument to the CLI options | ||
|
||
If you're using `kube-prometheus`, a `ConfigMap` resource like: | ||
|
||
```yaml | ||
kind: ConfigMap | ||
apiVersion: v1 | ||
metadata: | ||
name: kube-state-metrics-config | ||
namespace: monitoring | ||
data: | ||
kube-state-metrics-config.yaml: |- | ||
auto-gomemlimit: true | ||
# ... options here ... | ||
``` | ||
|
||
could be deployed, then a strategic merge patch applied to configure kube-state-metrics to use it: | ||
|
||
```yaml | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: kube-state-metrics | ||
namespace: monitoring | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: kube-state-metrics | ||
args: | ||
- --host=127.0.0.1 | ||
- --port=8081 | ||
- --telemetry-host=127.0.0.1 | ||
- --telemetry-port=8082 | ||
- --config=/etc/kube-state-metrics/kube-state-metrics-config.yaml | ||
volumeMounts: | ||
- name: config-volume | ||
mountPath: /etc/kube-state-metrics | ||
volumes: | ||
- name: config-volume | ||
configMap: | ||
name: kube-state-metrics-config | ||
``` | ||
|
||
<!-- markdownlint-enable link-image-reference-definitions --> | ||
<!-- markdownlint-enable blanks-around-fences --> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.