Skip to content

Commit

Permalink
Install prometheus on local clusters (2/4)
Browse files Browse the repository at this point in the history
related to #124

I want to check metrics that will be implemented. That's why I'm adding the option to install prometheus on both clusters with `make deploy-prometheus`.

Such deployed prometheus scrapes metrics of k8gb operator and is accessible directly from the browser:

 - http://127.0.0.1:8080 - test-gslb1
 - http://127.0.0.1:8081 - test-gslb2
  • Loading branch information
kuritka committed Jun 18, 2021
1 parent e0dab18 commit 96d4b36
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
24 changes: 24 additions & 0 deletions Makefile
Expand Up @@ -185,6 +185,11 @@ destroy-full-local-setup: ## Destroy full local multicluster setup
k3d cluster delete $(CLUSTER_GSLB2)
docker network rm $(CLUSTER_GSLB_NETWORK)

.PHONY: deploy-prometheus
deploy-prometheus:
$(call deploy-prometheus,$(CLUSTER_GSLB1))
$(call deploy-prometheus,$(CLUSTER_GSLB2))

.PHONY: dns-tools
dns-tools: ## Run temporary dnstools pod for debugging DNS issues
@kubectl -n k8gb get svc k8gb-coredns
Expand Down Expand Up @@ -487,3 +492,22 @@ define list-running-pods
@echo "\n$(YELLOW)Local cluster $(CYAN)$1 $(NC)"
kubectl get pods -A --context=k3d-$1
endef

define deploy-prometheus
@echo "\n$(YELLOW)Local cluster $(CYAN)$1$(NC)"
kubectl config use-context k3d-$1

@echo "\n$(YELLOW)Set annotations on pods that will be scraped by prometheus$(NC)"
kubectl annotate pods -l name=k8gb -n k8gb --overwrite prometheus.io/scrape="true"
kubectl annotate pods -l name=k8gb -n k8gb --overwrite prometheus.io/path=/metrics
kubectl annotate pods -l name=k8gb -n k8gb --overwrite prometheus.io/port="8080"

@echo "\n$(YELLOW)install prometheus $(NC)"
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo add kube-state-metrics https://kubernetes.github.io/kube-state-metrics
helm repo update
helm -n k8gb upgrade -i prometheus prometheus-community/prometheus -f deploy/prometheus/values.yaml \
--version 14.2.0 \
--wait --timeout=2m0s
kubectl get pods -A
endef
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -70,6 +70,7 @@ This setup is adapted for local scenarios and works without external DNS provide

Consult with [local playground](/docs/local.md) documentation to learn all the details of experimenting with local setup.

Optionally, you can run `make-deploy-prometheus` and check the metrics on the test clusters (http://localhost:8080, http://localhost:8081).
## Motivation and Architecture

k8gb was born out of the need for an open source, cloud native GSLB solution at Absa Group in South Africa.
Expand Down
20 changes: 20 additions & 0 deletions deploy/prometheus/values.yaml
@@ -0,0 +1,20 @@
server:
enabled: true
service:
nodePort: 30090 # allowed port range between 30000 and 32768
servicePort: 9090
type: NodePort

alertmanager:
enabled: false
# service:
# nodePort: 30091 # allowed port range between 30000 and 32768
# servicePort: 9091
# type: NodePort

pushgateway:
enabled: false
# service:
# nodePort: 30092 # allowed port range between 30000 and 32768
# servicePort: 9092
# type: NodePort
5 changes: 4 additions & 1 deletion k3d/test-gslb1.yaml
Expand Up @@ -10,7 +10,10 @@ ports:
- agent[0]
- port: 443:443
nodeFilters:
- agent[0]
- agent[0]
- port: 8080:30090
nodeFilters:
- agent[0]
- port: 5053:53/udp
nodeFilters:
- agent[0]
Expand Down
5 changes: 4 additions & 1 deletion k3d/test-gslb2.yaml
Expand Up @@ -10,7 +10,10 @@ ports:
- agent[0]
- port: 444:443
nodeFilters:
- agent[0]
- agent[0]
- port: 8081:30090
nodeFilters:
- agent[0]
- port: 5054:53/udp
nodeFilters:
- agent[0]
Expand Down
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -102,7 +102,7 @@ func main() {
}
reconciler.DNSProvider = f.Provider()
log.Info().Msgf("provider: %s", reconciler.DNSProvider)
log.Info().Msg("starting metrics")
log.Info().Msgf("starting metrics on %s", reconciler.Config.MetricsAddress)
reconciler.Metrics = metrics.NewPrometheusMetrics(*reconciler.Config)
err = reconciler.Metrics.Register()
if err != nil {
Expand Down

0 comments on commit 96d4b36

Please sign in to comment.