apiVersion: apps/v1
kind: Deployment
metadata:
  name: ratelimit
  namespace: istio-system
  labels:
    app: ratelimit
    version: v1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ratelimit
  template:
    metadata:
      labels:
        app: ratelimit
        version: v1
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/scheme: "http"
        prometheus.io/path: "/metrics"
        prometheus.io/port: "9102"
        prometheus.istio.io/merge-metrics: "false"
    spec:
      containers:
        - name: ratelimit
          image: docker.io/envoyproxy/ratelimit:6aaad7c3
          imagePullPolicy: Always
          command: ["/bin/ratelimit"]
          ports:
            - containerPort: 8080
            - containerPort: 8081
            - containerPort: 6070
          readinessProbe:
            httpGet:
              path: /healthcheck
              port: 8080
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 3
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 1
              memory: 1Gi
          env:
            - name: USE_STATSD
              value: "true"
            - name: STATSD_HOST
              value: "localhost"
            - name: STATSD_PORT
              value: "9125"
            - name: LOG_FORMAT
              value: "json"
            - name: LOG_LEVEL
              value: "warn"
            - name: REDIS_SOCKET_TYPE
              value: "tcp"
            - name: REDIS_URL
              value: "ratelimit-redis:6379"
            - name: REDIS_TLS
              value: "false"
            - name: REDIS_POOL_SIZE
              value: "5"
            - name: LOCAL_CACHE_SIZE_IN_BYTES # 25 MB local cache
              value: "26214400"
            - name: RUNTIME_ROOT
              value: "/data"
            - name: RUNTIME_SUBDIRECTORY
              value: "runtime"
            - name: RUNTIME_WATCH_ROOT
              value: "true"
            - name: RUNTIME_IGNOREDOTFILES
              value: "true"
          volumeMounts:
            - name: ratelimit-config
              mountPath: /data/runtime/config
        - name: statsd-exporter
          image: docker.io/prom/statsd-exporter:v0.21.0
          imagePullPolicy: Always
          args: ["--statsd.mapping-config=/etc/statsd-exporter/config.yaml"]
          ports:
            - containerPort: 9125
            - containerPort: 9102
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 1
              memory: 1Gi
          volumeMounts:
            - name: statsd-exporter-config
              mountPath: /etc/statsd-exporter
      volumes:
        - name: ratelimit-config
          configMap:
            name: ratelimit-config
        - name: statsd-exporter-config
          configMap:
            name: statsd-exporter-config
