我想将传入流量重定向到myserver.mydomain.com/prometheus到我的prometheus pod。这是我尝试实现的YAML文件:
这是部署清单:
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus-deployment
namespace: monitoring
spec:
replicas: 1
selector:
matchLabels:
app: prometheus-server
template:
metadata:
labels:
app: prometheus-server
spec:
containers:
- name: prometheus
image: prom/prometheus:latest
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus/"
- "--web.external-url=http://myserver.mydomain.com/prometheus"
ports:
- containerPort: 9090
volumeMounts:
- name: prometheus-config-volume
mountPath: /etc/prometheus/
- name: prometheus-storage-volume
mountPath: /prometheus/
volumes:
- name: prometheus-config-volume
configMap:
defaultMode: 420
name: prometheus-server-conf
- name: prometheus-storage-volume
persistentVolumeClaim:
claimName: prometheus-local-zfs-pvc
服务清单...
apiVersion: v1
kind: Service
metadata:
name: prometheus-service
namespace: monitoring
annotations:
prometheus.io/scrape: 'true'
prometheus.io/port: '9090'
spec:
selector:
app: prometheus-server
ports:
- name: http
protocol: TCP
port: 80
targetPort: 9090
...以及入口清单...
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: prometheus-ingress
namespace: monitoring
annotations:
kubernetes.io/ingress.class: traefik
spec:
rules:
- host: myserver.mydomain.com
http:
paths:
- path: /prometheus
backend:
serviceName: prometheus-service
servicePort: 80
但是,这将返回404。我在做什么错了?
编辑:我已经添加了@coderanger建议的选项。我在应用新部署时注意到的一件事是,在删除旧Pod之前启动新Pod时似乎存在锁定问题,日志中的错误为err="opening storage failed: lock DB directory: resource temporarily unavailable....
答案 0 :(得分:2)
由于要将其移至子路径,因此需要在Prometheus命令行选项上传递--web.external-url
。