Skip to content

Commit

Permalink
Enable external metrics for the cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
pflaeging committed Mar 30, 2023
1 parent 9fd5a4b commit b0a13df
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 2 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ The dashboard is always listening on port 32443 with SSL and a private certifica

<https://myfamous-minicluster-hostname.cloud:32443>

## Getting Prometheus metric for an external monitoring

You must rollout the component `metrics-server` (enable this in `env.sh`).

After this you get the config by executing `./get-metrics-reader-config.sh`.

The config makes a:

- ServiceAccount
- ClusterRole
- Rolebinding
- Bearer Token to access the metrics via the API

## Getting login info for your cluster

You can copy the admin.conf in your local kube environment. As normal user:
Expand Down
4 changes: 2 additions & 2 deletions env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ WILDCARD_INGRESS=gubernat1.pflaeging.net
MYIP=192.168.254.130

# all components:
# cert-manager contour-ingress kubernetes-dashboard local-storage
COMPONENTS="contour-ingress kubernetes-dashboard local-storage"
# cert-manager contour-ingress kubernetes-dashboard local-storage metrics-server
COMPONENTS="contour-ingress kubernetes-dashboard local-storage metrics-server"
11 changes: 11 additions & 0 deletions get-metrics-reader-config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /bin/sh

# get ip address
HOSTNAME=`hostname`
# get token for pre-defined admin-user
TOKEN=$(kubectl get secret metrics-reader -n kube-system -o jsonpath='{.data.token}' | base64 -d)

echo To access metrics:
echo
echo TOKEN=$TOKEN
echo curl -vv -k https://$HOSTNAME:6443/metrics --header \"Authorization: Bearer \$TOKEN\"
9 changes: 9 additions & 0 deletions metrics-server/clusterrole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: metrics-reader
rules:
- nonResourceURLs:
- "/metrics"
verbs:
- get
12 changes: 12 additions & 0 deletions metrics-server/clusterrolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: metrics-reader-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: metrics-reader
subjects:
- kind: ServiceAccount
name: metrics-reader
namespace: kube-system
5 changes: 5 additions & 0 deletions metrics-server/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#! /bin/sh

. ../env.sh

kubectl apply -k .
18 changes: 18 additions & 0 deletions metrics-server/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

resources:
- https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
- sa.yaml
- clusterrole.yaml
- clusterrolebinding.yaml
- secret.yaml

patches:
- target:
kind: Deployment
name: metrics-server
patch: |-
- op: add
path: /spec/template/spec/containers/0/args/-
value: --kubelet-insecure-tls
5 changes: 5 additions & 0 deletions metrics-server/sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: metrics-reader
namespace: kube-system
8 changes: 8 additions & 0 deletions metrics-server/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
annotations:
kubernetes.io/service-account.name: metrics-reader
name: metrics-reader
namespace: kube-system
type: kubernetes.io/service-account-token

0 comments on commit b0a13df

Please sign in to comment.