Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework 8 #8

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kubernetes-monitoring/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM nginx:1.14.2
RUN rm /etc/nginx/conf.d/default.conf
ADD nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]
32 changes: 32 additions & 0 deletions kubernetes-monitoring/nginx/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: homework
labels:
app: nginx
spec:
replicas: 1
selector:
matchLabels:
app: nginx
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nvyakimov/my-nginx:v1.0.0
ports:
- containerPort: 80
- name: nginx-exporter
image: 'nginx/nginx-prometheus-exporter:1.1.0'
args:
- '-nginx.scrape-uri=http://homework.otus/nginx-metrics'
ports:
- containerPort: 9113
22 changes: 22 additions & 0 deletions kubernetes-monitoring/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 80;
server_name localhost;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
}

location /nginx-metrics {
stub_status on;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
20 changes: 20 additions & 0 deletions kubernetes-monitoring/nginx/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: homework
labels:
app: nginx
spec:
type: ClusterIP
selector:
app: nginx
ports:
- name: nginx-port
protocol: TCP
port: 80
targetPort: 80
- name: nginx-exporter-port
protocol: TCP
port: 9113
targetPort: 9113
16 changes: 16 additions & 0 deletions kubernetes-monitoring/prometheus-stack/serviceMonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: nginx-exporter-sm
namespace: prometheus
labels:
release: prometheus-stack
spec:
namespaceSelector:
any: true
selector:
matchLabels:
app: nginx
endpoints:
- port: nginx-exporter-port
scheme: http
Binary file not shown.
32 changes: 32 additions & 0 deletions kubernetes-monitoring/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
1) запустить миникуб minikube start --registry-mirror=https://c.163.com
2) запустить деплоймент с кастомным образом nginx и экспортером: kubectl apply -f .\nginx\deployment.yaml
3) включить сервис для него: kubectl apply -f .\nginx\service.yaml
4) создать неймспейс для prometheus-operator: kubectl create ns prometheus
5) установить prometheus-operator. Для этого выполнить команды:
- helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
- helm repo update
- helm -n prometheus install prometheus-stack prometheus-community/kube-prometheus-stack

6) добавить настройку для скейпинга метрик nginx:
вариант №1:
получить values из чарта: helm show values prometheus-community/kube-prometheus-stack > .\prometheus-stack\values.yaml

в values добавить
additionalServiceMonitors:
- name: "nginx-exporter"
namespaceSelector:
any: true
selector:
matchLabels:
app: nginx
endpoints:
- port: "nginx-exporter-port"
- targetPort: "nginx-exporter-port"
scheme: http
и выполнить helm -n prometheus upgrade -f .\prometheus-stack\values.yaml prometheus-stack prometheus-community/kube-prometheus-stack

вариант №2: применить настройку из файла serviceMonitor.yaml
выполнить kubectl apply -f .\prometheus-stack\serviceMonitor.yaml

7) пробросить порт для графаны: kubectl -n prometheus port-forward svc/prometheus-stack-grafana 8080:80
ипортировать дашборд 12708 , уюбедиться, что на нем есть информация о работе nginx
Loading