Skip to content

Commit

Permalink
Add all configs to root README.md file
Browse files Browse the repository at this point in the history
  • Loading branch information
renuka-fernando committed Jun 28, 2020
1 parent ce549f3 commit f380a08
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 15 deletions.
149 changes: 141 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 <unknown>/100m, <unknown>/50% 1 10 0 8s
products Deployment/products-backend <unknown>/100m, <unknown>/50% 1 10 1 15s
products Deployment/products-backend <unknown>/100m, 1%/50% 1 10 1 92s
products Deployment/products-backend <unknown>/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 `<unknown>`.
Expand Down
2 changes: 1 addition & 1 deletion metrics-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions prometheus-adapter-configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

- Create namespace `custom-metrics`.
```sh
$ apictl create namespace custom-metrics
$ 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
$ 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
Expand All @@ -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
Expand Down Expand Up @@ -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":[]}
Expand Down
4 changes: 2 additions & 2 deletions prometheus-server-configs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit f380a08

Please sign in to comment.