Bring Your Own Prometheus

    To use your own Prometheus stack setup, perform the following steps:

    1. Uninstall the customized Prometheus stack of KubeSphere

    2. Install your own Prometheus stack

    3. Install KubeSphere customized stuff to your Prometheus stack

    4. Change KubeSphere’s monitoring endpoint

    1. Execute the following commands to uninstall the stack:

    2. Delete the PVC that Prometheus used.

      1. kubectl -n kubesphere-monitoring-system delete pvc `kubectl -n kubesphere-monitoring-system get pvc | grep -v VOLUME | awk '{print $1}' | tr '\n' ' '`

    Note

    KubeSphere 3.0.0 was certified to work well with the following Prometheus stack components:

    • Prometheus Operator v0.38.3+
    • Prometheus v2.20.1+
    • Alertmanager v0.21.0+
    • kube-state-metrics v1.9.6
    • node-exporter v0.18.1

    Make sure your Prometheus stack components’ version meets these version requirements especially node-exporter and kube-state-metrics.

    Make sure you install node-exporter and kube-state-metrics if only Prometheus Operator and Prometheus were installed. node-exporter and kube-state-metrics are required for KubeSphere to work properly.

    If you’ve already had the entire Prometheus stack up and running, you can skip this step.

    1. Get kube-prometheus version v0.6.0 whose node-exporter’s version v0.18.1 matches the one KubeSphere v3.0.0 is using.

      1. Setup the monitoring namespace, and install Prometheus Operator and corresponding roles:

        1. kubectl apply -f manifests/setup/
      2. Wait until Prometheus Operator is up and running.

        1. kubectl -n monitoring get pod --watch
      3. Remove unnecessary components such as Prometheus Adapter.

        1. rm -rf manifests/prometheus-adapter-*.yaml
      4. Change kube-state-metrics to the same version v1.9.6 as KubeSphere v3.0.0 is using.

      5. Install Prometheus, Alertmanager, Grafana, kube-state-metrics, and node-exporter. You can only install kube-state-metrics or node-exporter by only applying the yaml file kube-state-metrics-*.yaml or node-exporter-*.yaml.

        1. kubectl apply -f manifests/

      Note

      KubeSphere 3.0.0 uses Prometheus Operator to manage Prometheus/Alertmanager config and lifecycle, ServiceMonitor (to manage scrape config), and PrometheusRule (to manage Prometheus recording/alert rules).

      There are a few items listed in KubeSphere kustomization, among which and prometheus-rulesEtcd.yaml are required for KubeSphere v3.0.0 to work properly and others are optional. You can remove alertmanager-secret.yaml if you don’t want your existing Alertmanager’s config to be overwritten. You can remove xxx-serviceMonitor.yaml if you don’t want your own ServiceMonitors to be overwritten (KubeSphere customized ServiceMonitors discard many irrelevant metrics to make sure Prometheus only stores the most useful metrics).

      If your Prometheus stack setup isn’t managed by Prometheus Operator, you can skip this step. But you have to make sure that:

      • You must copy the recording/alerting rules in and PrometheusRule for etcd to your Prometheus config for KubeSphere v3.0.0 to work properly.

      • Configure your Prometheus to scrape metrics from the same targets as the ServiceMonitors listed in .

        1. cd ~ && mkdir kubesphere && cd kubesphere && git clone https://github.com/kubesphere/kube-prometheus.git && cd kube-prometheus/kustomize
      1. Change the namespace to your own in which the Prometheus stack is deployed. For example, it is monitoring if you install Prometheus in the monitoring namespace following Step 2.

        1. sed -i 's/my-namespace/<your own namespace>/g' kustomization.yaml
      2. Apply KubeSphere customized stuff including Prometheus rules, Alertmanager config, and various ServiceMonitors.

        1. kubectl apply -k .
      3. Setup Services for kube-scheduler and kube-controller-manager metrics exposure.

        1. kubectl apply -f ./prometheus-serviceKubeControllerManager.yaml
      4. Find the Prometheus CR which is usually Kubernetes in your own namespace.

      5. Set the Prometheus rule evaluation interval to 1m to be consistent with the KubeSphere v3.0.0 customized ServiceMonitor. The Rule evaluation interval should be greater or equal to the scrape interval.

        1. kubectl -n <your own namespace> patch prometheus k8s --patch '{
        2. "spec": {
        3. }
        4. }' --type=merge

      Now that your own Prometheus stack is up and running, you can change KubeSphere’s monitoring endpoint to use your own Prometheus.

      1. Edit kubesphere-config by running the following command:

        1. kubectl edit cm -n kubesphere-system kubesphere-config
      2. Navigate to the monitoring endpoint section as below:

        1. monitoring:
        2. endpoint: http://prometheus-operated.kubesphere-monitoring-system.svc:9090
      3. Change monitoring endpoint to your own Prometheus:

        1. monitoring:
        2. endpoint: http://prometheus-operated.monitoring.svc:9090
      4. Run the following command to restart the KubeSphere APIServer.

        1. kubectl -n kubesphere-system rollout restart deployment/ks-apiserver

      Warning

      If you enable/disable KubeSphere pluggable components following this guide , the will be reset to the original one. In this case, you have to change it to the new one and then restart the KubeSphere APIServer again.