CentOS 8
Sponsored Link

MicroK8s : Enable Prometheus2020/08/17

 
Enable Prometheus add-on to monitor metrics on MicroK8s Cluster.
[1] Enable built-in Prometheus add-on on primary Node.
[root@dlp ~]#
microk8s enable prometheus dashboard dns

Enabling Prometheus
namespace/monitoring created
customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/podmonitors.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheuses.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/prometheusrules.monitoring.coreos.com created
customresourcedefinition.apiextensions.k8s.io/servicemonitors.monitoring.coreos.com created
.....
.....
rolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
clusterrolebinding.rbac.authorization.k8s.io/kubernetes-dashboard created
deployment.apps/kubernetes-dashboard created
service/dashboard-metrics-scraper created
deployment.apps/dashboard-metrics-scraper created

If RBAC is not enabled access the dashboard using the default token retrieved with:

token=$(microk8s kubectl -n kube-system get secret | grep default-token | cut -d " " -f1)
microk8s kubectl -n kube-system describe secret $token

In an RBAC enabled setup (microk8s enable RBAC) you need to create a user with restricted
permissions as shown in:
https://github.com/kubernetes/dashboard/blob/master/docs/user/access-control/creating-sample-user.md

Addon dns is already enabled.

[root@dlp ~]#
microk8s kubectl get services -n monitoring

NAME                    TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                      AGE
alertmanager-main       ClusterIP   10.152.183.122   <none>        9093/TCP                     57s
alertmanager-operated   ClusterIP   None             <none>        9093/TCP,9094/TCP,9094/UDP   39s
grafana                 ClusterIP   10.152.183.161   <none>        3000/TCP                     57s
kube-state-metrics      ClusterIP   None             <none>        8443/TCP,9443/TCP            57s
node-exporter           ClusterIP   None             <none>        9100/TCP                     56s
prometheus-adapter      ClusterIP   10.152.183.34    <none>        443/TCP                      56s
prometheus-k8s          ClusterIP   10.152.183.217   <none>        9090/TCP                     56s
prometheus-operated     ClusterIP   None             <none>        9090/TCP                     29s
prometheus-operator     ClusterIP   None             <none>        8080/TCP                     61s

[root@dlp ~]#
microk8s kubectl get pods -n monitoring

NAME                                  READY   STATUS    RESTARTS   AGE
alertmanager-main-0                   2/2     Running   0          83s
grafana-fbb6785d5-c275s               1/1     Running   0          100s
kube-state-metrics-dcc94d9f8-pj87s    3/3     Running   0          99s
node-exporter-d48hw                   2/2     Running   0          99s
prometheus-adapter-5949969998-bgznt   1/1     Running   0          100s
prometheus-k8s-0                      3/3     Running   1          73s
prometheus-operator-5c7dcf954-f982j   1/1     Running   0          103s

# set port-forwarding to enable external access

# Prometheus UI

[root@dlp ~]#
microk8s kubectl port-forward -n monitoring service/prometheus-k8s --address 0.0.0.0 9090:9090

Forwarding from 0.0.0.0:9090 -> 9090
# Grafana UI

[root@dlp ~]#
microk8s kubectl port-forward -n monitoring service/grafana --address 0.0.0.0 3000:3000

Forwarding from 0.0.0.0:3000 -> 3000
# if Firewalld is running, allow ports

[root@dlp ~]#
firewall-cmd --add-port={9090/tcp,3000/tcp} --permanent

[root@dlp ~]#
firewall-cmd --reload

[2] Access to [https://(MicroK8s primary node's Hostname or IP address):(setting port)] with an web browser on a Client computer in local network. Then, that's OK if following Prometheus or Grafana UI is shown.
For default user/password on Grafana, it [admin/admin].
Matched Content