---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kube-state-metrics
  namespace: monitoring
  labels:
    app: kube-state-metrics
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kube-state-metrics
  template:
    metadata:
      labels:
        app: kube-state-metrics
    spec:
      # Deployment has PodAntiAffinity configured to ensure that
      # the scheduler does not co-locate replicas on a single node.
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values:
                - kube-state-metrics
            topologyKey: "kubernetes.io/hostname"
      serviceAccountName: kube-state-metrics
      serviceAccount: kube-state-metrics
      securityContext:
        runAsUser: 65534
        runAsGroup: 65534
        fsGroup: 65534    
      containers:
        - name: kube-state-metrics
          image: quay.io/coreos/kube-state-metrics:v1.9.7
          imagePullPolicy: IfNotPresent          
          ports:
            - containerPort: 8080
              protocol: TCP
          resources:
            limits:
              memory: "400Mi"
              cpu: "100m"
            requests:
              memory: "30Mi"
              cpu: "10m"
          livenessProbe:
            httpGet:
              path: /healthz
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
          readinessProbe:
            httpGet:
              path: /
              port: 8080
              scheme: HTTP
            initialDelaySeconds: 5
            timeoutSeconds: 5
            periodSeconds: 10
            successThreshold: 1
            failureThreshold: 3
      restartPolicy: Always
      terminationGracePeriodSeconds: 30
