Sanket Arali
04/30/2025, 5:00 AMHi 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?
Raúl Díaz García
04/30/2025, 6:28 AMSleepInfo
resource with the following configuration:
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:
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 hoursSanket Arali
04/30/2025, 6:31 AMSanket Arali
04/30/2025, 6:31 AMRaúl Díaz García
04/30/2025, 6:32 AMSanket Arali
04/30/2025, 7:11 AMSleepInfo
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 helpRaúl Díaz García
04/30/2025, 7:26 AMSleepInfo
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)
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
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)
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
Sanket Arali
04/30/2025, 7:30 AMsleepAt: 22:00
One specifically for Friday with sleepAt: 20:00
Since both apply on Friday, whichtime takes precedence — 8 PM or 10 PM? so which one is considered ?sleepAt
Sanket Arali
04/30/2025, 7:32 AMSanket Arali
04/30/2025, 7:32 AMRaúl Díaz García
04/30/2025, 7:48 AMSleepInfo
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.
AllRaúl Díaz García
04/30/2025, 7:50 AMClemens Jütte
04/30/2025, 8:11 AMSanket Arali
04/30/2025, 8:47 AMLights On
04/30/2025, 10:48 PMSleepInfo
resource with a specific schedule configuration.
## YAML Configuration Example
Here's how you can configure it:
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 runningSanket Arali
05/02/2025, 5:11 AMValues.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 structureSanket Arali
05/02/2025, 5:15 AM# 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
#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
#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
Sanket Arali
05/02/2025, 5:22 AMLights On
05/07/2025, 12:54 AMValues.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`:
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:
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:
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
fileLights On
05/07/2025, 12:58 AMkube-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
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
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)
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