From f380a08586cba2300418fda2e54f3aab80caf97f Mon Sep 17 00:00:00 2001 From: Renuka Fernando Date: Sun, 28 Jun 2020 17:34:38 +0530 Subject: [PATCH] Add all configs to root README.md file --- README.md | 149 +++++++++++++++++++++++++-- metrics-server/README.md | 2 +- prometheus-adapter-configs/README.md | 8 +- prometheus-server-configs/README.md | 4 +- 4 files changed, 148 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 700d2d6..14f3a91 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,137 @@ ## Steps to follow the tutorial -- [Install Metrics Server](metrics-server) -- [Install Prometheus Monitoring System](prometheus-server-configs) -- [Install Prometheus Adapter](prometheus-adapter-configs) -- [Deploy Sample Products Backend Service](sample-apps/prometheus-metrics-app-java/k8s-configs) +1. [Install Metrics Server](metrics-server) + + If you are running Minikube, run the following command to enable metrics-server. + ```sh + $ minikube addons enable metrics-server + ``` + OR else + **NOTE:** This installation only required in local setup, if you using GKE, EKS cluster you do not need to install + following. + ```sh + $ kubectl apply -f metrics-server/metrics-server-components-0.3.6.yaml + + Output: + clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created + clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created + rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created + apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created + serviceaccount/metrics-server created + deployment.apps/metrics-server created + service/metrics-server created + clusterrole.rbac.authorization.k8s.io/system:metrics-server created + clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created + ``` + +1. [Install Prometheus Monitoring System](prometheus-server-configs) + + - Install Prometheus Operator (version 0.39 for this sample) in Kubernetes cluster. + + ```sh + $ kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/v0.39.0/bundle.yaml + + Output: + 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 + customresourcedefinition.apiextensions.k8s.io/thanosrulers.monitoring.coreos.com created + clusterrolebinding.rbac.authorization.k8s.io/prometheus-operator created + clusterrole.rbac.authorization.k8s.io/prometheus-operator created + deployment.apps/prometheus-operator created + serviceaccount/prometheus-operator created + service/prometheus-operator created + ``` + + - Create a Prometheus instance in Kubernetes cluster. The directory `prometheus/` contains related configurations. + ```sh + $ kubectl apply -f prometheus-server-configs/ + + Output: + prometheus.monitoring.coreos.com/prometheus created + serviceaccount/prometheus created + clusterrole.rbac.authorization.k8s.io/prometheus created + clusterrolebinding.rbac.authorization.k8s.io/prometheus created + servicemonitor.monitoring.coreos.com/products-backend created + service/prometheus created + ``` +1. [Install Prometheus Adapter](prometheus-adapter-configs) + + - Create namespace `custom-metrics`. + ```sh + $ kubectl create namespace custom-metrics + + Output: + namespace/custom-metrics created + ``` + - Create service certificate. Follow [Serving Certificates, Authentication, and Authorization](https://github.com/kubernetes-sigs/apiserver-builder-alpha/blob/v1.18.0/docs/concepts/auth.md) + to create serving certificate. For this sample we can use certs in the directory `prometheus-adapter/certs`. Create secret `cm-adapter-serving-certs` as follows. + ```sh + $ kubectl create secret generic cm-adapter-serving-certs \ + --from-file=serving-ca.crt=prometheus-adapter-configs/certs/serving-ca.crt \ + --from-file=serving-ca.key=cprometheus-adapter-configs/erts/serving-ca.key \ + -n custom-metrics + + Output: + secret/cm-adapter-serving-certs created + ``` + + - Install Prometheus Adapter (version 0.7.0 for this sample) in Kubernetes cluster. + ```sh + $ kubectl apply -f prometheus-adapter-configs/ + + Output: + clusterrolebinding.rbac.authorization.k8s.io/custom-metrics:system:auth-delegator created + rolebinding.rbac.authorization.k8s.io/custom-metrics-auth-reader created + deployment.apps/custom-metrics-apiserver created + clusterrolebinding.rbac.authorization.k8s.io/custom-metrics-resource-reader created + serviceaccount/custom-metrics-apiserver created + service/custom-metrics-apiserver created + apiservice.apiregistration.k8s.io/v1beta1.custom.metrics.k8s.io created + clusterrole.rbac.authorization.k8s.io/custom-metrics-server-resources created + configmap/adapter-config created + clusterrole.rbac.authorization.k8s.io/custom-metrics-resource-reader created + clusterrolebinding.rbac.authorization.k8s.io/hpa-controller-custom-metrics created + ``` + In the directory `prometheus-adapter` we have specified configurations for Prometheus Adapter. + [custom-metrics-config-map.yaml](prometheus-adapter-configs/custom-metrics-config-map.yaml) contains rules defined for this + sample. + ```yaml + # rule for products backend service + - seriesQuery: '{__name__=~"^.*_http_requests_total"}' + resources: + overrides: + namespace: {resource: "namespace"} + pod: {resource: "pod"} + name: + matches: "^(.*)_http_requests_total" + as: "${1}_http_requests_total_per_second" + metricsQuery: 'sum(rate(<<.Series>>{<<.LabelMatchers>>,http_url!=""}[1m])) by (<<.GroupBy>>)' + + - Test the Prometheus Adapter deployment executing follows. + ```sh + $ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 + + Output: + {"kind":"APIResourceList","apiVersion":"v1","groupVersion":"custom.metrics.k8s.io/v1beta1","resources":[]} + ``` + +1. [Deploy Sample Products Backend Service](sample-apps/prometheus-metrics-app-java/k8s-configs) + + ```sh + $ kubectl apply -f sample-apps/prometheus-metrics-app-java/k8s-configs/ + + Output: + deployment.apps/products-backend created + horizontalpodautoscaler.autoscaling/products created + service/products-backend created + ``` ## Test Sample + - Lets make `IP` as the node IP and `PERIOD` as waiting period in seconds to send requests periodically. ```sh @@ -26,12 +151,20 @@ periodically. ``` Wait for 2-3 minutes and open a new terminal and execute following to get HPA details. ```sh - $ apictl get hpa -w; + $ kubectl get hpa -w; Output: - NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE - products Deployment/products 200m/200m, 18%/50% 1 5 1 6m52s - products-privatejet Deployment/products-privatejet 166m/100m, 5%/50% 1 6 2 8m29s + NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE + products Deployment/products-backend /100m, /50% 1 10 0 8s + products Deployment/products-backend /100m, /50% 1 10 1 15s + products Deployment/products-backend /100m, 1%/50% 1 10 1 92s + products Deployment/products-backend /100m, 1%/50% 1 10 1 2m33s + products Deployment/products-backend 173m/100m, 1%/50% 1 10 1 2m49s + products Deployment/products-backend 200m/100m, 1%/50% 1 10 2 3m4s + products Deployment/products-backend 99m/100m, 1%/50% 1 10 2 3m19s + products Deployment/products-backend 99m/100m, 2%/50% 1 10 2 3m34s + products Deployment/products-backend 106m/100m, 2%/50% 1 10 2 3m50s + products Deployment/products-backend 116m/100m, 2%/50% 1 10 2 4m5s ``` **NOTE:** Wait for fem minutes if the metrics values is ``. diff --git a/metrics-server/README.md b/metrics-server/README.md index 26d3e7e..df0970c 100644 --- a/metrics-server/README.md +++ b/metrics-server/README.md @@ -14,7 +14,7 @@ $ minikube addons enable metrics-server **NOTE:** This installation only required in local setup, if you using GKE, EKS cluster you do not need to install following. ```sh - $ apictl apply -f metrics-server-components-0.3.6.yaml + $ kubectl apply -f metrics-server-components-0.3.6.yaml Output: clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created diff --git a/prometheus-adapter-configs/README.md b/prometheus-adapter-configs/README.md index 68acd5e..7120390 100644 --- a/prometheus-adapter-configs/README.md +++ b/prometheus-adapter-configs/README.md @@ -2,7 +2,7 @@ - Create namespace `custom-metrics`. ```sh - $ apictl create namespace custom-metrics + $ kubectl create namespace custom-metrics Output: namespace/custom-metrics created @@ -10,7 +10,7 @@ - Create service certificate. Follow [Serving Certificates, Authentication, and Authorization](https://github.com/kubernetes-sigs/apiserver-builder-alpha/blob/v1.18.0/docs/concepts/auth.md) to create serving certificate. For this sample we can use certs in the directory `prometheus-adapter/certs`. Create secret `cm-adapter-serving-certs` as follows. ```sh - $ apictl create secret generic cm-adapter-serving-certs \ + $ kubectl create secret generic cm-adapter-serving-certs \ --from-file=serving-ca.crt=certs/serving-ca.crt \ --from-file=serving-ca.key=certs/serving-ca.key \ -n custom-metrics @@ -21,7 +21,7 @@ to create serving certificate. For this sample we can use certs in the directory - Install Prometheus Adapter (version 0.7.0 for this sample) in Kubernetes cluster. ```sh - $ apictl apply -f . + $ kubectl apply -f . Output: clusterrolebinding.rbac.authorization.k8s.io/custom-metrics:system:auth-delegator created @@ -53,7 +53,7 @@ to create serving certificate. For this sample we can use certs in the directory - Test the Prometheus Adapter deployment executing follows. ```sh - $ apictl get --raw /apis/custom.metrics.k8s.io/v1beta1 + $ kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1 Output: {"kind":"APIResourceList","apiVersion":"v1","groupVersion":"custom.metrics.k8s.io/v1beta1","resources":[]} diff --git a/prometheus-server-configs/README.md b/prometheus-server-configs/README.md index 14adb51..639b113 100644 --- a/prometheus-server-configs/README.md +++ b/prometheus-server-configs/README.md @@ -3,7 +3,7 @@ - Install Prometheus Operator (version 0.39 for this sample) in Kubernetes cluster. ```sh - $ apictl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/v0.39.0/bundle.yaml + $ kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/v0.39.0/bundle.yaml Output: customresourcedefinition.apiextensions.k8s.io/alertmanagers.monitoring.coreos.com created @@ -21,7 +21,7 @@ - Create a Prometheus instance in Kubernetes cluster. The directory `prometheus/` contains related configurations. ```sh - $ apictl apply -f . + $ kubectl apply -f . Output: prometheus.monitoring.coreos.com/prometheus created