apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: prometheus-server
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: ingress-nginx
rules:
  - apiGroups: [""]
    resources:
      - services
      - endpoints
      - pods
    verbs: ["get", "list", "watch"]

---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus-server
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: ingress-nginx

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: prometheus-server
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: ingress-nginx

roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: prometheus-server
subjects:
  - kind: ServiceAccount
    name: prometheus-server
    namespace: ingress-nginx

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-server
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: ingress-nginx

spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: prometheus
      app.kubernetes.io/part-of: ingress-nginx
  template:
    metadata:
      labels:
        app.kubernetes.io/name: prometheus
        app.kubernetes.io/part-of: ingress-nginx
    spec:
      serviceAccountName: prometheus-server
      containers:
        - name: prometheus
          image: prom/prometheus:v2.3.2
          args:
            - "--config.file=/etc/prometheus/prometheus.yml"
            - "--storage.tsdb.path=/prometheus/"
          ports:
            - containerPort: 9090
          volumeMounts:
            - name: prometheus-config-volume
              mountPath: /etc/prometheus/
            - name: prometheus-storage-volume
              mountPath: /prometheus/
      volumes:
        - name: prometheus-config-volume
          configMap:
            name: prometheus-configuration
        - name: prometheus-storage-volume
          emptyDir: {}

---
apiVersion: v1
kind: Service
metadata:
  name: prometheus-server
  namespace: ingress-nginx
  labels:
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: ingress-nginx

spec:
  selector:
    app.kubernetes.io/name: prometheus
    app.kubernetes.io/part-of: ingress-nginx
  type: NodePort
  ports:
    - port: 9090
      targetPort: 9090

---

