> Hi all, I’m using Kubegreen and want to confi...
# general
s
Hi all, I’m using Kubegreen and want to configure pod sleep/wake schedules. From Mon–Fri, pods should sleep at 10 PM and wake up at 10 AM. On weekends, they should stay fully shut down and only wake up Monday at 10 AM. How can I achieve this with Kubegreen?
r
Hi , hope this helps . To configure Kube-Green for your pod sleep/wake schedule, use a single
SleepInfo
resource with the following configuration:
Copy code
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: weekday-schedule
spec:
  weekdays: "1-5"  # Monday-Friday
  sleepAt: "22:00"  # 10 PM
  wakeUpAt: "10:00"  # 10 AM
  timeZone: "Your/Timezone"  # e.g., "Europe/Paris"
Key behavior: • Pods will automatically sleep at 10 PM and wake at 10 AM Monday-Friday • On Friday at 10 PM, pods enter sleep mode but won't wake Saturday/Sunday (since weekends aren't in
weekdays: 1-5
) • Automatic wake-up occurs Monday at 10 AM when the schedule reactivates For 24/7 weekend shutdown:
Copy code
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: weekend-shutdown
spec:
  weekdays: "6,0"  # Saturday-Sunday
  sleepAt: "00:00"  # Midnight
  # No wakeUpAt = remains asleep until Monday's schedule
  timeZone: "Your/Timezone"
To verify configurations, check pod states using
kubectl get deployments
during scheduled hours
s
@Raúl Díaz García Thank you so much for the help 🙂
my problem is solved
r
Cool , have a nice day !
s
Hi @Raúl Díaz García I'm configuring a
SleepInfo
resource for my pods using Kubegreen, and I need help setting up the correct
sleepAt
and
wakeUpAt
times for weekdays and weekends. Requirement:Weekdays (Mon–Fri) • Sleep at 10:00 PM IST ( Indian Standard Time ) • Wake up at 9:00 AM IST ( Indian Standard Time )Weekend Mode • Stop on Friday at 8:00 PM IST ( Indian Standard Time ) • Wake up on Sunday at 11:00 AM IST ( Indian Standard Time ) How can I update this config to match the above weekday and weekend sleep/wake requirements? Could you pleas help
r
Mm I just check those loinks : https://kube-green.dev/docs/configuration/ https://github.com/kube-green/kube-green/issues/332 So to match your requirements for weekday and weekend sleep/wake schedules using Kube-Green's
SleepInfo
resource, you'll need to use two separate resources, as Kube-Green's standard configuration supports one sleep/wake cycle per resource and does not natively support multi-day "full stop" periods with a single rule 1. Weekday Schedule (Monday–Friday)
Copy code
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: weekday-schedule
spec:
  weekdays: "1-5"              # Monday (1) to Friday (5)
  sleepAt: "22:00"             # 10:00 PM IST
  wakeUpAt: "09:00"            # 9:00 AM IST
  timeZone: "Asia/Kolkata"     # IST timezone
  suspendCronJobs: true        # Optional: suspend CronJobs too P..D I´m not sure about your timezone, check this one ...
2. Weekend Full Stop (Friday Night to Sunday Morning
Copy code
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: weekend-shutdown
spec:
  weekdays: "5"                # Friday only
  sleepAt: "20:00"             # 8:00 PM IST (full stop begins)
  timeZone: "Asia/Kolkata"
  suspendCronJobs: true
3. Weekend Wake-Up (Sunday)
Copy code
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: weekend-wakeup
spec:
  weekdays: "0"                # Sunday only (0 = Sunday)
  wakeUpAt: "11:00"            # 11:00 AM IST
  timeZone: "Asia/Kolkata"
  suspendCronJobs: true
s
Hi @Raúl Díaz García Thank you for the help but i have one doubt that One for weekdays (Mon–Fri) with
sleepAt: 22:00
One specifically for Friday with
sleepAt: 20:00
Since both apply on Friday, which
sleepAt
time takes precedence — 8 PM or 10 PM? so which one is considered ?
Untitled
This is what chatgpt gave me
r
When multiple
SleepInfo
resources apply to the same day, Kube-Green uses the earliest
sleepAt
time and latest
wakeUpAt
time from all matching rules. Here's how it works for your specific Friday scenario: Friday Behavior Explained 1. Both rules apply since: ◦
weekday-schedule
matches Friday (
1-5
includes Friday = 5) ◦
friday-shutdown
explicitly targets Friday (
5
) 1. Sleep Time Precedence: ◦ Kube-Green will prioritize the earliest
sleepAt
time (8:00 PM from
friday-shutdown
) to ensure your Friday shutdown happens earlier than the regular weekday schedule. 1. Wake-Up Behavior: ◦ The
wakeUpAt: 09:00
from
weekday-schedule
won't apply on Friday because the
friday-shutdown
rule doesn't specify a
wakeUpAt
, leaving pods asleep until Sunday's rule triggers. The Friday-specific
sleepAt: 20:00
(8 PM) takes priority over the weekday rule's
sleepAt: 22:00
(10 PM) because earlier sleep times override later ones when multiple rules apply. No conflict occurs because Kube-Green is designed to handle overlapping schedules by selecting the most conservative (earliest sleep, latest wake) times. All
All this is just theory I couldn´t try just now ,I´ve a (bored) meeting in a few minutes, hope this could be usefull mate !
c
Hey @Sanket Arali! Love to see the interaction and that you’re getting help but there’s a #C037GR3TNH5 channel that won’t ping every user on this slack 🙂
s
Hi @Raúl Díaz García Once again Thank you for the help!!
l
Configuring Pod Sleep/Wake Schedules with KubeGreen To achieve your desired schedule (weekdays 10 PM sleep/10 AM wake, weekends fully off), you'll need to create a KubeGreen
SleepInfo
resource with a specific schedule configuration. ## YAML Configuration Example Here's how you can configure it:
Copy code
yaml
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: weekday-schedule
spec:
  weekdays:
    from: "Monday"
    to: "Friday"
    sleepAt: "22:00"
    wakeUpAt: "10:00"
  weekends:
    enabled: false
  timeZone: "America/New_York"  # Change to your timezone
Key Configuration Points: 1. Weekday Schedule: ◦
from: Monday
to
to: Friday
defines the weekday range ◦
sleepAt: "22:00"
makes pods sleep at 10 PM ◦
wakeUpAt: "10:00"
wakes them at 10 AM 1. Weekend Behavior: ◦
enabled: false
means pods will stay asleep all weekend ◦ They'll automatically wake up Monday at 10 AM as per the weekday schedule 1. Time Zone: ◦ Make sure to set the correct
timeZone
for your location Additional Notes: • The schedule uses 24-hour format • You may need to adjust the API version based on your KubeGreen version • Apply this configuration to the namespace where your workloads run • Verify your KubeGreen controller is properly installed and running
s
Hi @Raúl Díaz García / @Lights On Hi , I'm trying to set up kube-green using custom YAMLs and a CronJob to manage pod sleep/wake schedules. Everything works locally, but my Jenkins build is failing on Bitbucket with this error: Error: template: kube-green/templates/crds/sleepinfo.yaml823: executing ... nil pointer evaluating interface {}.weekdays Looks like
Values.sleepinfo.weekdays.wakeUpAt
is not defined. How can I fix this in the Helm chart or values.yaml to avoid the nil pointer error? so this is my folder structure
Copy code
# sleepinfo-clusterrole.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: sleepinfo-job-clusterrole
rules:
  - apiGroups: [""]
    resources: ["namespaces"]
    verbs: ["get", "list"]
  - apiGroups: ["apps"]
    resources: ["deployments", "statefulsets"]
    verbs: ["get", "list"]
  - apiGroups: ["batch"]
    resources: ["cronjobs"]
    verbs: ["get", "list"]
  - apiGroups: ["kube-green.com"]
    resources: ["sleepinfos"]
    verbs: ["create", "update", "get", "list", "patch", "watch"]


# sleepinfo-clusterrolebinding.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: sleepinfo-job-binding
subjects:
  - kind: ServiceAccount
    name: sleepinfo-job-sa
    namespace: shashank
roleRef:
  kind: ClusterRole
  name: sleepinfo-job-clusterrole
  apiGroup: rbac.authorization.k8s.io

#sleepinfo-cronjob.yaml

apiVersion: batch/v1
kind: CronJob
metadata:
  name: sleepinfo-creator
  namespace: shashank
spec:
  schedule: "1 7 * * *"  # 12:31 PM IST (converted to UTC)
  jobTemplate:
    spec:
      template:
        spec:
          serviceAccountName: sleepinfo-job-sa
          containers:
          - name: sleepinfo-job
            image: bitnami/kubectl:latest
            command: ["/bin/bash", "/scripts/sleepinfo.sh"]
            volumeMounts:
            - name: script-volume
              mountPath: /scripts
          restartPolicy: OnFailure
          volumes:
          - name: script-volume
            configMap:
              name: sleepinfo-script
              defaultMode: 0777
Copy code
#sleepinfo-rbac.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: sleepinfo-sa
  namespace: shashank
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: sleepinfo-cr
rules:
- apiGroups: [""]
  resources: ["pods", "namespaces", "deployments", "daemonsets", "statefulsets", "replicasets", "jobs", "cronjobs"]
  verbs: ["get", "list"]
- apiGroups: ["kube-green.com"]
  resources: ["sleepinfos"]
  verbs: ["get", "create", "patch", "update", "delete"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: sleepinfo-crb
subjects:
- kind: ServiceAccount
  name: sleepinfo-sa
  namespace: shashank
roleRef:
  kind: ClusterRole
  name: sleepinfo-cr
  apiGroup: rbac.authorization.k8s.io


# sleepinfo-sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
  name: sleepinfo-job-sa
  namespace: shashank

#sleepinfo-script-configmap.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  name: sleepinfo-script
  namespace: shashank
data:
  sleepinfo.sh: |
    #!/bin/bash

    # Loop through all namespaces
    for ns in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do
      # Skip kube-green namespace
      if [ "$ns" = "kube-green" ]; then
        echo "Skipping kube-green namespace..."
        continue
      fi

      # Count Deployments, StatefulSets, CronJobs
      deploy_count=$(kubectl get deploy -n "$ns" --no-headers 2>/dev/null | wc -l)
      sts_count=$(kubectl get sts -n "$ns" --no-headers 2>/dev/null | wc -l)
      cron_count=$(kubectl get cronjob -n "$ns" --no-headers 2>/dev/null | wc -l)

      total=$((deploy_count + sts_count + cron_count))

      if [ "$total" -gt 0 ]; then
        echo "Creating SleepInfo for namespace: $ns"

        # Apply SleepInfo manifest dynamically
        cat <<EOF | kubectl apply -f -
        apiVersion: kube-green.com/v1alpha1
        kind: SleepInfo
        metadata:
          name: sleep-$ns
          namespace: $ns
        spec:
          weekdays: "1-5"              # Monday to Friday
          sleepAt: "14:40"             # Sleep at 14:40 (2:40 PM)
          wakeUpAt: "14:50"            # Wake up at 14:50 (2:50 PM)
          timeZone: "Asia/Kolkata"     # Change timezone if needed
          suspendCronJobs: true
        EOF

      else
        echo "No active workloads in namespace: $ns — skipping."
      fi
    done
Copy code
#sleepinfo.sh

#!/bin/bash

# Loop through all namespaces
for ns in $(kubectl get ns -o jsonpath='{.items[*].metadata.name}'); do
  # Skip specific namespaces
  if [[ "$ns" == "default" || "$ns" == "argocd" || "$ns" == "kube-system" || "$ns" == "kube-green" ]]; then
    echo "Skipping $ns namespace..."
    continue
  fi

  # Count Deployments, StatefulSets, CronJobs
  deploy_count=$(kubectl get deploy -n "$ns" --no-headers 2>/dev/null | wc -l)
  sts_count=$(kubectl get sts -n "$ns" --no-headers 2>/dev/null | wc -l)
  cron_count=$(kubectl get cronjob -n "$ns" --no-headers 2>/dev/null | wc -l)

  total=$((deploy_count + sts_count + cron_count))

  if [ "$total" -gt 0 ]; then
    echo "Creating SleepInfo for namespace: $ns"

    # Apply SleepInfo manifest dynamically
    cat <<EOF | kubectl apply -f -
apiVersion: kube-green.com/v1alpha1
kind: SleepInfo
metadata:
  name: sleep-$ns
  namespace: $ns
spec:
  weekdays: "1-5"              # Monday to Friday
  sleepAt: "15:39"             # Sleep at 10:00 PM
  wakeUpAt: "15:49"            # Wake up at 10:00 AM
  timeZone: "Asia/Kolkata"     # Change if needed
  suspendCronJobs: true
EOF

  else
    echo "No active workloads in namespace: $ns — skipping."
  fi
done
so these are all my files please help me
l
# Troubleshooting the kube-green Helm Chart Error The error you're seeing indicates that your Helm chart is trying to access
Values.sleepinfo.weekdays.wakeUpAt
but this value isn't defined in your values.yaml file. ## Solution Options ### 1. Define Default Values in values.yaml Add default values in your `values.yaml`:
Copy code
yaml
sleepinfo:
  weekdays:
    wakeUpAt: "08:00"
    sleepAt: "20:00"
  weekends:
    wakeUpAt: "09:00"
    sleepAt: "18:00"
### 2. Add Nil Checks in Your Template Modify your
crds/sleepinfo.yaml
template to handle nil values:
Copy code
yaml
{{- if .Values.sleepinfo }}
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: {{ include "kube-green.fullname" . }}
spec:
  {{- if .Values.sleepinfo.weekdays }}
  weekdays:
    wakeUpAt: {{ .Values.sleepinfo.weekdays.wakeUpAt | default "08:00" }}
    sleepAt: {{ .Values.sleepinfo.weekdays.sleepAt | default "20:00" }}
  {{- end }}
  {{- if .Values.sleepinfo.weekends }}
  weekends:
    wakeUpAt: {{ .Values.sleepinfo.weekends.wakeUpAt | default "09:00" }}
    sleepAt: {{ .Values.sleepinfo.weekends.sleepAt | default "18:00" }}
  {{- end }}
{{- end }}
### 3. Folder Structure Recommendation Based on standard Helm chart structure, your folders should look like:
Copy code
kube-green/
├── Chart.yaml
├── values.yaml
├── charts/
├── templates/
│   ├── crds/
│   │   └── sleepinfo.yaml
│   ├── deployment.yaml
│   ├── _helpers.tpl
│   └── ...
└── ...
## Additional Checks 1. Verify your
Chart.yaml
has the correct
apiVersion
(v2 for Helm 3) 2. Ensure all required fields are documented in your
values.yaml
3. Consider adding schema validation with a
values.schema.json
file
Here's a more detailed breakdown of how to properly structure and configure your kube-green Helm chart to avoid the nil pointer error: ## Complete Solution ### 1. Folder Structure
Copy code
kube-green/
├── Chart.yaml              # Chart metadata
├── values.yaml             # Default configuration
├── values.schema.json      # (Optional) Validation schema
├── charts/                 # Subcharts
├── templates/
│   ├── crds/
│   │   └── sleepinfo.yaml  # Your SleepInfo CRD
│   ├── _helpers.tpl        # Template helpers
│   ├── NOTICE.txt
│   └── ...                 # Other templates
└── templates/tests/        # Test files
### 2. Recommended values.yaml
Copy code
yaml
# Default values for kube-green
sleepinfo:
  enabled: true
  weekdays:
    wakeUpAt: "08:00"    # Default wake time (weekdays)
    sleepAt: "20:00"     # Default sleep time (weekdays)
  weekends:
    wakeUpAt: "09:00"    # Default wake time (weekends)
    sleepAt: "18:00"     # Default sleep time (weekends)
  timeZone: "UTC"        # Default timezone
### 3. Robust templates/crds/sleepinfo.yaml
Copy code
yaml
{{- if .Values.sleepinfo.enabled -}}
apiVersion: <http://kube-green.com/v1alpha1|kube-green.com/v1alpha1>
kind: SleepInfo
metadata:
  name: {{ include "kube-green.fullname" . }}
  labels:
    {{- include "kube-green.labels" . | nindent 4 }}
spec:
  timeZone: {{ .Values.sleepinfo.timeZone | quote }}
  {{- with .Values.sleepinfo.weekdays }}
  weekdays:
    wakeUpAt: {{ .wakeUpAt | quote }}
    sleepAt: {{ .sleepAt | quote }}
  {{- end }}
  {{- with .Values.sleepinfo.weekends }}
  weekends:
    wakeUpAt: {{ .wakeUpAt | quote }}
    sleepAt: {{ .sleepAt | quote }}
  {{- end }}
{{- end }}
### 4. Key Improvements: 1. Conditional Rendering: The template only renders if
sleepinfo.enabled
is true 2. Nil Protection: Uses
with
blocks to safely handle potentially undefined values 3. Default Values: Provides sensible defaults in values.yaml 4. String Quoting: Ensures time values are properly quoted 5. Label Standardization: Includes common labels from _helpers.tpl ### 5. Validation (Optional values.schema.json)
Copy code
json
{
  "$schema": "<http://json-schema.org/draft-07/schema#|http://json-schema.org/draft-07/schema#>",
  "properties": {
    "sleepinfo": {
      "type": "object",
      "properties": {
        "enabled": { "type": "boolean" },
        "timeZone": { "type": "string" },
        "weekdays": {
          "type": "object",
          "properties": {
            "wakeUpAt": { "type": "string", "pattern": "^[0-9]{2}:[0-9]{2}$" },
            "sleepAt": { "type": "string", "pattern": "^[0-9]{2}:[0-9]{2}$" }
          }
        },
        "weekends": {
          "type": "object",
          "properties": {
            "wakeUpAt": { "type": "string", "pattern": "^[0-9]{2}:[0-9]{2}$" },
            "sleepAt": { "type": "string", "pattern": "^[0-9]{2}:[0-9]{2}$" }
          }
        }
      }
    }
  }
}
### 6. Testing the Solution 1. Dry Run:
helm install --dry-run my-release ./kube-green
2. Lint:
helm lint ./kube-green
3. Override Values:
helm install my-release ./kube-green -f my-values.yaml