Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ledu0032 committed Apr 21, 2023
1 parent a47ef68 commit 8c6dd3a
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:alpine3.7
COPY . /app
WORKDIR /app
RUN pip install flask && pip3 install --no-cache-dir Flask flask_prometheus_metrics
RUN pip install flask && pip3 install prometheus-flask-exporter
EXPOSE 5000
CMD ["python", "./index.py"]
9 changes: 7 additions & 2 deletions chart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ spec:
metadata:
labels:
app: nginx
annotations:
prometheus.io/scrape: "true"
prometheus.io.scheme: "http"
prometheus.io/path: "/metrics"
prometheus.io/port: "5000"
spec:
containers:
- name: helloworldv2
image: ledu32/helloworldv2:latest
- name: helloworldv3
image: ledu32/helloworldv2
livenessProbe:
httpGet:
path: /
Expand Down
4 changes: 4 additions & 0 deletions chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress
annotations:
nginx.ingress.kubernetes.io/cors-allow-headers: Content-Type
nginx.ingress.kubernetes.io/cors-allow-methods: POST, GET, OPTIONS
nginx.ingress.kubernetes.io/cors-allow-origin: http://localhost:9090/
spec:
rules:
http:
Expand Down
6 changes: 3 additions & 3 deletions chart/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ kind: Service
metadata:
name: service
annotations:
se7entyse7en.prometheus/scrape: "true"
se7entyse7en.prometheus/path: "/metrics"
se7entyse7en.prometheus/port: "80"
prometheus.io/port: "5000"
prometheus.io/scrape: "true"
prometheus.io/path: "/metrics"
spec:
type: ClusterIP
selector:
Expand Down
81 changes: 81 additions & 0 deletions grafana/grafana.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: grafana-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: grafana
name: grafana
spec:
selector:
matchLabels:
app: grafana
template:
metadata:
labels:
app: grafana
spec:
securityContext:
fsGroup: 472
supplementalGroups:
- 0
containers:
- name: grafana
image: grafana/grafana:9.1.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 3000
name: http-grafana
protocol: TCP
readinessProbe:
failureThreshold: 3
httpGet:
path: /robots.txt
port: 3000
scheme: HTTP
initialDelaySeconds: 10
periodSeconds: 30
successThreshold: 1
timeoutSeconds: 2
livenessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 3000
timeoutSeconds: 1
resources:
requests:
cpu: 250m
memory: 750Mi
volumeMounts:
- mountPath: /var/lib/grafana
name: grafana-pv
volumes:
- name: grafana-pv
persistentVolumeClaim:
claimName: grafana-pvc
---
apiVersion: v1
kind: Service
metadata:
name: grafana
spec:
ports:
- port: 3000
protocol: TCP
targetPort: http-grafana
selector:
app: grafana
sessionAffinity: None
type: LoadBalancer
15 changes: 13 additions & 2 deletions index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
from flask import Flask
from prometheus_client import make_wsgi_app
from werkzeug.middleware.dispatcher import DispatcherMiddleware
from prometheus_flask_exporter import PrometheusMetrics


app = Flask(__name__)
metrics = PrometheusMetrics(app)

@app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int("5000"), debug=True)


# Plug metrics WSGI app to your main app with dispatcher
dispatcher = DispatcherMiddleware(app.wsgi_app, {"/metrics": make_wsgi_app()})

app.run(host='0.0.0.0', port=5000)
2 changes: 1 addition & 1 deletion monitoring_flask/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ services:
prometheus:
image: prom/prometheus:latest
ports:
- 9090:9090
- 9091:9090
volumes:
- "./prometheus.yml:/etc/monitoring_flask/prometheus.yml"

Expand Down
5 changes: 5 additions & 0 deletions prometheus/prometheus_account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
namespace: default
name: prometheus
17 changes: 17 additions & 0 deletions prometheus/prometheus_cluster_role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: discover
rules:
- apiGroups: [""]
resources:
- nodes
- services
- endpoints
- pods
verbs: ["get", "list", "watch"]
- apiGroups:
- extensions
resources:
- ingresses
verbs: ["get", "list", "watch"]
39 changes: 39 additions & 0 deletions prometheus/prometheus_config_map.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-server-conf
namespace: default
labels:
name: prometheus-server-conf
data:
prometheus.yml: |-
scrape_configs:
- job_name: 'kubernetes-service-endpoints'
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "scraping_pods"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["helloworldv2:8080"]
30 changes: 30 additions & 0 deletions prometheus/prometheus_deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
namespace: default
labels:
app: prometheus
spec:
replicas: 1
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
serviceAccountName: prometheus
containers:
- name: prometheus
image: prom/prometheus:latest
ports:
- containerPort: 9090
volumeMounts:
- name: config
mountPath: /etc/prometheus
volumes:
- name: config
configMap:
name: prometheus-server-conf
12 changes: 12 additions & 0 deletions prometheus/prometheus_role_binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: prometheus-discoverer
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: discoverer
subjects:
- kind: ServiceAccount
name: prometheus
namespace: default
10 changes: 10 additions & 0 deletions prometheus/prometheus_service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: prometheus
namespace: default
spec:
selector:
app: prometheus
ports:
- port: 9090

0 comments on commit 8c6dd3a

Please sign in to comment.