-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to scrape etcd metrics using a service (#8203)
Signed-off-by: Mathieu Parent <math.parent@gmail.com>
- Loading branch information
Showing
8 changed files
with
99 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# etcd | ||
|
||
## Metrics | ||
|
||
To expose metrics on a separate HTTP port, define it in the inventory with: | ||
|
||
```yaml | ||
etcd_metrics_port: 2381 | ||
``` | ||
To create a service `etcd-metrics` and associated endpoints in the `kube-system` namespace, | ||
define it's labels in the inventory with: | ||
|
||
```yaml | ||
etcd_metrics_service_labels: | ||
k8s-app: etcd | ||
app.kubernetes.io/managed-by: Kubespray | ||
app: kube-prometheus-stack-kube-etcd | ||
release: prometheus-stack | ||
``` | ||
|
||
The last two labels in the above example allows to scrape the metrics from the | ||
[kube-prometheus-stack](https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack) | ||
chart with the following Helm `values.yaml` : | ||
|
||
```yaml | ||
kubeEtcd: | ||
service: | ||
enabled: false | ||
``` |
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
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
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
- name: Kubernetes Apps | Lay down etcd_metrics templates | ||
template: | ||
src: "{{ item.file }}.j2" | ||
dest: "{{ kube_config_dir }}/{{ item.file }}" | ||
with_items: | ||
- { file: etcd_metrics-endpoints.yml, type: endpoints, name: etcd-metrics } | ||
- { file: etcd_metrics-service.yml, type: service, name: etcd-metrics } | ||
register: manifests | ||
when: inventory_hostname == groups['kube_control_plane'][0] | ||
|
||
- name: Kubernetes Apps | Start etcd_metrics | ||
kube: | ||
name: "{{ item.item.name }}" | ||
namespace: kube-system | ||
kubectl: "{{ bin_dir }}/kubectl" | ||
resource: "{{ item.item.type }}" | ||
filename: "{{ kube_config_dir }}/{{ item.item.file }}" | ||
state: "latest" | ||
with_items: "{{ manifests.results }}" | ||
when: inventory_hostname == groups['kube_control_plane'][0] |
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
17 changes: 17 additions & 0 deletions
17
roles/kubernetes-apps/ansible/templates/etcd_metrics-endpoints.yml.j2
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
apiVersion: v1 | ||
kind: Endpoints | ||
metadata: | ||
name: etcd-metrics | ||
namespace: kube-system | ||
labels: | ||
k8s-app: etcd | ||
app.kubernetes.io/managed-by: Kubespray | ||
subsets: | ||
{% for etcd_metrics_address in etcd_metrics_addresses.split(',') %} | ||
- addresses: | ||
- ip: {{ etcd_metrics_address | urlsplit('hostname') }} | ||
ports: | ||
- name: http-metrics | ||
port: {{ etcd_metrics_address | urlsplit('port') }} | ||
protocol: TCP | ||
{% endfor %} |
13 changes: 13 additions & 0 deletions
13
roles/kubernetes-apps/ansible/templates/etcd_metrics-service.yml.j2
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: etcd-metrics | ||
namespace: kube-system | ||
labels: | ||
{{ etcd_metrics_service_labels | to_yaml(indent=2, width=1337) | indent(width=4) }} | ||
spec: | ||
ports: | ||
- name: http-metrics | ||
protocol: TCP | ||
port: {{ etcd_metrics_port }} | ||
# targetPort: |
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