Created
November 15, 2018 12:14
-
-
Save m-wrona/1ceb84c12817b47c0ed76fb4b7810b74 to your computer and use it in GitHub Desktop.
Nginx deployment for Kubernetes with Prometheus monitoring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: ConfigMap | |
metadata: | |
name: nginx | |
namespace: default | |
data: | |
nginx.conf: | | |
worker_processes auto; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
# Hide nginx version information. | |
server_tokens off; | |
gzip on; | |
# Compression level (1-9). | |
# 5 is a perfect compromise between size and CPU usage, offering about | |
# 75% reduction for most ASCII files (almost identical to level 9). | |
gzip_comp_level 5; | |
# Don't compress anything that's already small and unlikely to shrink much | |
# if at all (the default is 20 bytes, which is bad as that usually leads to | |
# larger files after gzipping). | |
# Default: 20 | |
gzip_min_length 256; | |
# Tell proxies to cache both the gzipped and regular version of a resource | |
# whenever the client's Accept-Encoding capabilities header varies; | |
# Avoids the issue where a non-gzip capable client (which is extremely rare | |
# today) would display gibberish if their proxy gave them the gzipped version. | |
# Default: off | |
gzip_vary on; | |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
root /usr/share/nginx/html/; | |
location / { | |
access_log off; | |
try_files $uri $uri/ =404; | |
} | |
} | |
server { | |
server_name metrics; | |
listen 8088; | |
listen [::]:8088; | |
location /probes/health { | |
access_log off; | |
return 200 "healthy"; | |
} | |
location /nginx_status { | |
access_log off; | |
stub_status; | |
} | |
} | |
} | |
--- | |
apiVersion: extensions/v1beta1 | |
kind: Deployment | |
metadata: | |
name: nginx | |
namespace: default | |
labels: | |
app: nginx | |
spec: | |
replicas: 3 | |
template: | |
metadata: | |
labels: | |
app: nginx | |
annotations: | |
prometheus.io/scrape: "true" | |
prometheus.io/path: "/metrics" | |
prometheus.io/port: "9113" | |
spec: | |
volumes: | |
- name: config | |
configMap: | |
name: nginx | |
imagePullSecrets: | |
- name: platform-docker-registry | |
containers: | |
- name: nginx | |
image: nginx:1.15.2 | |
imagePullPolicy: IfNotPresent | |
ports: | |
- containerPort: 80 | |
volumeMounts: | |
- name: config | |
mountPath: /etc/nginx | |
readinessProbe: | |
httpGet: | |
path: /probes/health | |
port: 8088 | |
initialDelaySeconds: 5 | |
timeoutSeconds: 5 | |
periodSeconds: 5 | |
failureThreshold: 3 | |
successThreshold: 1 | |
livenessProbe: | |
httpGet: | |
path: /probes/health | |
port: 8088 | |
initialDelaySeconds: 5 | |
timeoutSeconds: 5 | |
periodSeconds: 15 | |
failureThreshold: 3 | |
successThreshold: 1 | |
- name: metrics | |
image: nginx/nginx-prometheus-exporter:0.1.0 | |
imagePullPolicy: IfNotPresent | |
ports: | |
- containerPort: 9113 | |
args: [ | |
"-nginx.scrape-uri", "http://localhost:8088/nginx_status" | |
] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment