apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: chronocollector
  name: chronocollector-deployment
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  labels:
    app: chronocollector
  name: chronocollector-deployment
rules:
- apiGroups:
  - apps
  resources:
  - deployments
  - statefulsets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - namespaces
  - nodes
  - pods
  - services
  - endpoints
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - nodes/metrics
  verbs:
  - get
- apiGroups:
  - discovery.k8s.io
  resources:
  - endpointslices
  verbs:
  - get
  - list
  - watch
- nonResourceURLs:
  - /metrics
  verbs:
  - get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  labels:
    app: chronocollector
  name: chronocollector-deployment
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: chronocollector-deployment
subjects:
- kind: ServiceAccount
  name: chronocollector-deployment
  namespace: default
---
apiVersion: v1
data:
  config.yml: |-
    logging:
      level: ${LOGGING_LEVEL:info}

    metrics:
      scope:
        prefix: "chronocollector"
      prometheus:
        handlerPath: /metrics
      sanitization: prometheus
      samplingRate: 1.0
      extended: none

    listenAddress: "${LISTEN_ADDRESS:0.0.0.0:3030}"

    labels:
      defaults:
        tenant_k8s_cluster: ${KUBERNETES_CLUSTER_NAME:""}

    backend:
      type: ${BACKEND_TYPE:gateway}
      gateway:
        address: ${GATEWAY_ADDRESS:""}
        insecure: ${GATEWAY_INSECURE:false}
        cert: ${GATEWAY_CERT:""}
        certSkipVerify: ${GATEWAY_CERT_SKIP_VERIFY:false}
      prometheusRemoteWrite:
        writeURL: ${PROMETHEUS_REMOTE_WRITE_ADDRESS:""}
        httpClientTimeout: ${PROMETHEUS_REMOTE_WRITE_HTTP_CLIENT_TIMEOUT:30s}
        userAgent: ${PROMETHEUS_REMOTE_WRITE_USER_AGENT:chronosphere.io/chronocollector}

    discovery:
      kubernetes:
        enabled: true
        kubeletMonitoring:
          enabled: ${KUBERNETES_KUBELET_MONITORING_ENABLED:false}
          port: 10250
          bearerTokenFile: "/var/run/secrets/kubernetes.io/serviceaccount/token"

    kubernetes:
      client:
        outOfCluster: ${KUBERNETES_CLIENT_OUT_OF_CLUSTER:false}
      processor:
        annotationsPrefix: ${KUBERNETES_PROCESSOR_ANNOTATIONS_PREFIX:"prometheus.io/"}

    jobs:
      - name: node-exporter
        options:
          relabels:
            - action: replace
              regex: (.*)
              replacement: $1
              sourceLabels:
                - __meta_kubernetes_pod_node_name
              targetLabel: instance
      - name: mysql-exporter
        options:
          relabels:
            - action: replace
              regex: (.*)
              replacement: $1
              sourceLabels:
                - __meta_kubernetes_pod_container_name
              targetLabel: database

    scrape:
      enableStalenessMarker: false
      defaults:
        scrapeInterval: 10s
        scrapeTimeout: 10s
        relabels:
          - action: replace
            regex: (.*)
            replacement: $1
            sourceLabels:
              - __meta_kubernetes_namespace
            targetLabel: tenant_k8s_namespace

    push:
      statsd:
        enabled: false
        listenAddress: 0.0.0.0:3031
kind: ConfigMap
metadata:
  labels:
    app: chronocollector
  name: chronocollector-config
  namespace: default
---
apiVersion: v1
data:
  address: <add-base64-encoded-token-here>
  api-token: <add-base64-encoded-token-here>
kind: Secret
metadata:
  labels:
    app: chronocollector
  name: chronosphere-secret
  namespace: default
type: Opaque
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: chronocollector
  name: chronocollector-deployment
  namespace: default
spec:
  replicas: 1
  selector:
    matchLabels:
      app: chronocollector
  strategy:
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      annotations:
        prometheus.io/port: "3030"
        prometheus.io/scrape: "true"
      labels:
        app: chronocollector
    spec:
      containers:
      - env:
        - name: LISTEN_ADDRESS
          value: 0.0.0.0:3030
        - name: GATEWAY_ADDRESS
          value: foo.chronosphere.io:443
        - name: LOGGING_LEVEL
          value: info
        - name: API_TOKEN
          valueFrom:
            secretKeyRef:
              key: api-token
              name: chronosphere-secret
        - name: KUBERNETES_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        - name: KUBERNETES_CLUSTER_NAME
          value: default
        - name: KUBERNETES_KUBELET_MONITORING_ENABLED
          value: "false"
        image: gcr.io/chronosphereio/chronocollector:v0.102.0
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 3
          httpGet:
            path: /health
            port: http
          initialDelaySeconds: 5
          periodSeconds: 30
          successThreshold: 1
          timeoutSeconds: 5
        name: chronocollector-deployment
        ports:
        - containerPort: 3030
          name: http
        - containerPort: 3031
          name: statsd
          protocol: UDP
        - containerPort: 3031
          name: statsd-tcp
        - containerPort: 3032
          name: dogstatsd
          protocol: UDP
        - containerPort: 3033
          name: carbon
          protocol: UDP
        readinessProbe:
          failureThreshold: 5
          httpGet:
            path: /ready
            port: http
          initialDelaySeconds: 5
          periodSeconds: 5
          successThreshold: 1
          timeoutSeconds: 3
        resources:
          limits:
            cpu: 1000m
            memory: 512Mi
          requests:
            cpu: 1000m
            memory: 512Mi
        volumeMounts:
        - mountPath: /etc/chronocollector
          name: chronocollector-config
      serviceAccountName: chronocollector-deployment
      terminationGracePeriodSeconds: 5
      tolerations:
      - operator: Exists
      volumes:
      - configMap:
          name: chronocollector-config
        name: chronocollector-config
