diff --git a/inventory/sample/group_vars/k8s-cluster/k8s-net-kube-router.yml b/inventory/sample/group_vars/k8s-cluster/k8s-net-kube-router.yml index e36b9c1dc..c50132854 100644 --- a/inventory/sample/group_vars/k8s-cluster/k8s-net-kube-router.yml +++ b/inventory/sample/group_vars/k8s-cluster/k8s-net-kube-router.yml @@ -47,3 +47,12 @@ # Array of common annotations for every node # kube_router_annotations_all: [] + +# Enables scraping kube-router metrics with Prometheus +# kube_router_enable_metrics: false + +# Path to serve Prometheus metrics on +# kube_router_metrics_path: /metrics + +# Prometheus metrics port to use +# kube_router_metrics_port: 9255 diff --git a/roles/network_plugin/kube-router/defaults/main.yml b/roles/network_plugin/kube-router/defaults/main.yml index 7ede7e3bc..885e3474e 100644 --- a/roles/network_plugin/kube-router/defaults/main.yml +++ b/roles/network_plugin/kube-router/defaults/main.yml @@ -49,3 +49,12 @@ kube_router_annotations_node: [] # Array of common annotations for every node kube_router_annotations_all: [] + +# Enables scraping kube-router metrics with Prometheus +kube_router_enable_metrics: false + +# Path to serve Prometheus metrics on +kube_router_metrics_path: /metrics + +# Prometheus metrics port to use +kube_router_metrics_port: 9255 \ No newline at end of file diff --git a/roles/network_plugin/kube-router/templates/kube-router.yml.j2 b/roles/network_plugin/kube-router/templates/kube-router.yml.j2 index 687af0fb9..50b8431e7 100644 --- a/roles/network_plugin/kube-router/templates/kube-router.yml.j2 +++ b/roles/network_plugin/kube-router/templates/kube-router.yml.j2 @@ -65,6 +65,12 @@ spec: labels: k8s-app: kube-router tier: node + annotations: +{% if kube_router_enable_metrics %} + prometheus.io/path: {{ kube_router_metrics_path }} + prometheus.io/port: "{{ kube_router_metrics_port }}" + prometheus.io/scrape: "true" +{% endif %} spec: priorityClassName: system-cluster-critical serviceAccountName: kube-router @@ -95,6 +101,10 @@ spec: {% if kube_router_peer_router_ports %} - --peer-router-ports={{ kube_router_peer_router_ports }} {% endif %} +{% if kube_router_enable_metrics %} + - --metrics-path={{ kube_router_metrics_path }} + - --metrics-port={{ kube_router_metrics_port }} +{% endif %} {% for arg in kube_router_extra_args %} - "{{ arg }}" {% endfor %} @@ -129,6 +139,13 @@ spec: - name: kubeconfig mountPath: /var/lib/kube-router readOnly: true +{% if kube_router_enable_metrics %} + ports: + - containerPort: {{ kube_router_metrics_port }} + hostPort: {{ kube_router_metrics_port }} + name: metrics + protocol: TCP +{% endif %} initContainers: - name: install-cni image: {{ busybox_image_repo }}:{{ busybox_image_tag }}