Possibility of downscale particular statefulset or deployment

84 Views Asked by At

I want my kubedownscaler to downscale particular stateful set. Below is the config map i'm using.

apiVersion: v1
kind: ConfigMap
metadata:
name: kube-downscaler
data:
DEFAULT_DOWNTIME: "Sat-Sun 00:00-06:30 Asia/Kolkata,Mon-Fri 15:33-15:43 Asia/Kolkata"
INCLUDE_RESOURCES: "deployments,horizontalpodautoscalers,statefulsets"
EXCLUDE_NAMESPACES: "kube-system, kube-downscaler, cert-manager, default, monitoring, operator, dev"

Here is it possible to add 3or4 statefulset

Or can I use just use one namespace like this <INCLUDE_NAMESPACES: "test">

I tried this, but I was out of luck.

1

There are 1 best solutions below

0
On

I think you are referring to the Kube-Downscaler open source project here: https://codeberg.org/hjacobs/kube-downscaler

I see that you already have some resources targeted to be downscaled so we won't touch them. Instead we will create a second deployment of the Kube Downscaler and we will call it kube-downscaler-second

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    application: kube-downscaler-second
    version: v23.2.0
  name: kube-downscaler-second
spec:
  replicas: 1
  selector:
    matchLabels:
      application: kube-downscaler-second
  template:
    metadata:
      labels:
        application: kube-downscaler-second
        version: v23.2.0
    spec:
      serviceAccountName: kube-downscaler
      containers:
      - name: downscaler
        image: hjacobs/kube-downscaler:latest
        args:
          - --interval=60
        envFrom:
          - configMapRef:
              name: kube-downscaler-second
              optional: true
        resources:
          limits:
            memory: 100Mi
          requests:
            cpu: 5m
            memory: 100Mi
        securityContext:
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 1000

done that, remove the namespace we are going to target from the rule of the first kube-downscaler. Then, in order to target only the StatefulSets present in the "test-namespace", you need to give only that namespace as a target. You can do something like that using this regex inside the EXCLUDE_NAMESPACES environment variable of the ConfigMap.

^(?!test-namespace).*$

If you have additional statefulsets inside that namespace that you don't want to scale down you can insert them inside the EXCLUDE_DEPLOYMENTS environment variable (that despite its name, it works for every type of resource)

Your config map should look like something like this:

apiVersion: v1
kind: ConfigMap
metadata:
name: kube-downscaler-second
data:
DEFAULT_DOWNTIME: "Sat-Sun 00:00-06:30 Asia/Kolkata,Mon-Fri 15:33-15:43 Asia/Kolkata"
INCLUDE_RESOURCES: "statefulsets"
EXCLUDE_NAMESPACES: "^(?!test-namespace).*$"
EXCLUDE_DEPLOYMENTS: statefulset-hello,statefulset-world

This should work, let me know!