
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
!Logo
A Kubernetes operator that automatically scales down Deployments and StatefulSets during specific time windows (e.g., at night or on weekends) to save resources and costs.
https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/cronschedules](https://artifacthub.io/packages/search?repo=cronschedules)
Option 1: Using Helm (Recommended)
📦 Helm charts have been migrated to a dedicated repository for better management.
Add the charts repository:
bashhelm repo add cronschedules https://cronschedules.github.io/charts helm repo update
Install the operator:
bashhelm install cronjob-scale-down-operator cronschedules/cronjob-scale-down-operator
Install with custom values:
bashhelm install cronjob-scale-down-operator cronschedules/cronjob-scale-down-operator \ --set image.tag=0.3.0 \ --set webUI.enabled=true \ --set resources.requests.memory=128Mi
Verify installation:
bashkubectl get pods -l app.kubernetes.io/name=cronjob-scale-down-operator
📖 Chart Documentation: For detailed Helm chart documentation, values, and configuration options, visit the https://github.com/cronschedules/charts/tree/main/cronjob-scale-down-operator.
Option 2: Using Container Image
The operator is available as a pre-built container image from multiple registries:
bash# From Docker Hub: docker pull cronschedules/cronjob-scale-down-operator:0.3.0 # From GitHub Container Registry: docker pull ghcr.io/cronschedules/cronjob-scale-down-operator:0.3.0
Use these images in your custom deployments or with the provided Helm chart.
Option 3: Using kubectl
bashkubectl apply -f config/crd/bases/ kubectl apply -f config/rbac/ kubectl apply -f config/manager/
Quick Test
Create a test deployment:
bashkubectl apply -f examples/test-deployment.yaml
Apply a scaling schedule:
bashkubectl apply -f examples/quick-test.yaml
Monitor the scaling:
bashkubectl get cronjobscaledown -w kubectl get deployment nginx-test -w
Important Notice: Helm charts have been migrated to a dedicated repository for better management and hosting.
/charts directory of this repositoryhttps://cronschedules.github.io/charts✅ Centralized Management: All charts in one dedicated repository
✅ Proper Hosting: GitHub Pages hosting for Helm repository
✅ Improved CI/CD: Better error handling and comprehensive testing
✅ Security: Automated security scanning with Checkov
✅ Standards: Following Helm chart repository best practices
✅ Automation: Fully automated releases and index updates
If you were using the old chart location, please update your installation:
bash# Old way (deprecated) # helm install cronjob-scale-down-operator ./charts/cronjob-scale-down-operator # New way (recommended) helm repo add cronschedules https://cronschedules.github.io/charts helm repo update helm install cronjob-scale-down-operator cronschedules/cronjob-scale-down-operator
For comprehensive chart documentation, configuration options, values, and advanced usage:
The examples/ directory contains various use cases:
| Example | Description | Schedule |
|---|---|---|
| quick-test.yaml | Immediate testing | Every minute |
| basic-daily-schedule.yaml | Production workload | 10 PM → 6 AM daily |
| weekend-shutdown.yaml | Weekend cost savings | Friday 6 PM → Monday 8 AM |
| development-testing.yaml | Dev environment | Every 30/45 seconds |
| multi-timezone.yaml | Global deployments | Multiple timezones |
| statefulset-example.yaml | Database scaling | StatefulSet support |
| resource-cleanup-example.yaml | Resource cleanup | Com*ed scaling + cleanup** |
| cleanup-only-example.yaml | Cleanup only | Every 6 hours |
| orphan-cleanup-example.yaml | Orphan resource cleanup | Every 3 AM daily |
The operator supports a cleanup-only mode where it manages resource cleanup without scaling any target resources. This is perfect for environments where you need automated cleanup of test resources, temporary objects, or expired configurations.
yamlapiVersion: cronschedules.elbazi.co/v1 kind: CronJobScaleDown metadata: name: cleanup-only-job namespace: default spec: # No targetRef needed for cleanup-only mode cleanupSchedule: "0 0 */6 * * *" # Every 6 hours cleanupConfig: annotationKey: "test.example.com/cleanup-after" resourceTypes: - "ConfigMap" - "Secret" - "Service" - "Deployment" namespaces: - "test" - "staging" labelSelector: environment: "test" dryRun: false timeZone: "UTC"
You can also com***e scaling and cleanup in a single resource:
yamlapiVersion: cronschedules.elbazi.co/v1 kind: CronJobScaleDown metadata: name: combined-scaler-cleanup namespace: default spec: # Scaling configuration targetRef: name: my-app namespace: default kind: Deployment apiVersion: apps/v1 scaleDownSchedule: "0 0 22 * * *" # Scale down at 10 PM scaleUpSchedule: "0 0 6 * * *" # Scale up at 6 AM # Cleanup configuration cleanupSchedule: "0 0 2 * * *" # Clean up at 2 AM cleanupConfig: annotationKey: "cleanup-after" resourceTypes: ["ConfigMap", "Secret"] dryRun: false timeZone: "UTC"
yamlapiVersion: cronschedules.elbazi.co/v1 kind: CronJobScaleDown metadata: name: my-scaler namespace: default spec: # Target resource to scale targetRef: name: my-deployment namespace: default kind: Deployment # or StatefulSet apiVersion: apps/v1 # When to scale down (cron format with seconds) scaleDownSchedule: "0 0 22 * * *" # 10 PM daily # When to scale up (optional) scaleUpSchedule: "0 0 6 * * *" # 6 AM daily # Timezone for schedule interpretation timeZone: "UTC" # or "America/New_York", "Europe/London", etc.
The operator now supports automatic cleanup of test resources based on annotations:
yamlapiVersion: cronschedules.elbazi.co/v1 kind: CronJobScaleDown metadata: name: test-cleanup namespace: default spec: # Optional: You can still use scaling features alongside cleanup targetRef: name: my-deployment namespace: default kind: Deployment apiVersion: apps/v1 scaleDownSchedule: "0 0 22 * * *" scaleUpSchedule: "0 0 6 * * *" # Cleanup configuration cleanupSchedule: "0 0 2 * * *" # Run cleanup at 2 AM daily cleanupConfig: # Annotation key that marks resources for cleanup annotationKey: "cleanup-after" # Resource types to cleanup (now includes RBAC and failed resources) resourceTypes: - "Deployment" - "Service" - "ConfigMap" - "Secret" - "StatefulSet" - "Pod" # Useful for cleaning up evicted or failed pods - "Job" # Useful for cleaning up failed jobs - "Role" - "RoleBinding" # Note: ClusterRole and ClusterRoleBinding are also supported (cluster-scoped) # Optional: Limit cleanup to specific namespaces namespaces: - "test" - "lab" # Optional: Additional label selector labelSelector: environment: "test" # NEW: Enable orphan resource cleanup (resources without cleanup annotation) cleanupOrphanResources: true # NEW: Maximum age for orphan resources before cleanup orphanResourceMaxAge: "168h" # 7 days # Optional: Enable dry-run mode (default: false) dryRun: false timeZone: "UTC"
Cleanup Time Formats
Resources can be marked for cleanup using various time formats in the annotation value:
24h, 7d, 30m (relative to resource creation time)2024-12-31T23:59:59Z (RFC3339 format)2024-12-31 (cleanup at midnight on that date)"" (cleanup on next schedule run)Example Resource with Cleanup Annotation
yamlapiVersion: apps/v1 kind: Deployment metadata: name: test-deployment namespace: test labels: environment: "test" annotations: cleanup-after: "24h" # Delete 24 hours after creation spec: # ... deployment spec
Orphan Resource Cleanup
The operator now supports cleaning up "orphan" resources - resources that don't have the cleanup annotation but are old and potentially forgotten. This is useful for environments where resources are created during testing but not properly annotated for cleanup.
How it works:
cleanupOrphanResources: true in the cleanup configurationorphanResourceMaxAge to define how old resources must be before cleanupExample scenario:
yamlcleanupConfig: annotationKey: "cleanup-after" resourceTypes: ["ConfigMap", "Role", "RoleBinding"] cleanupOrphanResources: true orphanResourceMaxAge: "168h" # 7 days labelSelector: app.kubernetes.io/managed-by: "test"
This configuration will:
cleanup-after annotation according to their specified cleanup timeapp.kubernetes.io/managed-by: test and are older than 7 daysSupported Resource Types:
Deployment, StatefulSet, Service, ConfigMap, SecretPod, Job (useful for cleaning up failed/evicted resources)Role, RoleBinding, ClusterRole, ClusterRoleBinding**Safety *ations:
dryRun: true firstThe operator supports 6-field cron expressions with second precision:
┌─────────────second (0 - 59) │ ┌───────────── minute (0 - 59) │ │ ┌───────────── hour (0 - 23) │ │ │ ┌───────────── day of month (1 - 31) │ │ │ │ ┌───────────── month (1 - 12) │ │ │ │ │ ┌───────────── day of week (0 - 6) (0 = Sunday) │ │ │ │ │ │ * * * * * *
Common Schedule Examples
| Schedule | Description |
|---|---|
"0 0 22 * * *" | Every day at 10:00 PM |
"0 0 6 * * 1-5" | Weekdays at 6:00 AM |
"0 0 18 * * 5" | Every Friday at 6:00 PM |
"0 0 0 * * 0" | Every Sunday at midnight |
"*/30 * * * * *" | Every 30 seconds (testing) |
Use standard IANA timezone names:
UTCAmerica/New_YorkEurope/LondonEurope/BerlinAsia/TokyoAustralia/Sydneybashkubectl get cronjobscaledown -o wide kubectl describe cronjobscaledown my-scaler
bashkubectl logs -n cronjob-scale-down-operator-system deployment/cronjob-scale-down-operator-controller-manager
bashkubectl get deployment my-deployment -w kubectl get statefulset my-statefulset -w
The operator exposes comprehensive Prometheus metrics for monitoring scaling operations, cleanup activities, and system health:
bash# Access metrics endpoint kubectl port-forward -n cronjob-scale-down-operator-system deployment/cronjob-scale-down-operator-controller-manager 8443:8443 curl -k https://localhost:8443/metrics
Key Metrics Categories:
cronjob_scale_down_operations_total, cronjob_scale_up_operations_totalcronjob_cleaned_resources_total, cronjob_cleanup_operations_totalcronjob_target_resource_replicas_current, cronjob_scaled_down_resources_currentcronjob_reconciliation_errors_total, cronjob_reconciliation_duration_secondscronjob_schedule_next_execution_timestamp, cronjob_schedule_last_execution_timestampFor detailed metrics documentation, PromQL queries, and Grafana dashboard examples, see METRICS.md.
The operator includes a built-in web dashboard that provides real-time monitoring of all CronJobScaleDown resources and their target deployments/statefulsets.
!Web UI Dashboard
By default, the web UI is available at http://localhost:8082 when running the operator locally. In a Kubernetes cluster, you can access it by:
Port forwarding (for development/testing):
bashkubectl port-forward -n cronjob-scale-down-operator-system deployment/cronjob-scale-down-operator-controller-manager 8082:8082
Then visit http://localhost:8082
Configure ingress (for production):
yamlapiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: cronjob-scale-down-operator-ui spec: rules: - host: cronjob-ui.example.com http: paths: - path: / pathType: Prefix backend: service: name: cronjob-scale-down-operator-ui port: number: 8082
You can customize the web UI port using the --webui-addr flag:
bash./manager --webui-addr=:8080
For more details about the web UI, see the Web UI Documentation.
bash# Clone the repository git clone https://github.com/z4ck404/cronjob-scale-down-operator.git cd cronjob-scale-down-operator # Build and run locally make run # Build Docker image make docker-build IMG=my-registry/cronjob-scale-down-operator:latest # Deploy to cluster make deploy IMG=my-registry/cronjob-scale-down-operator:latest
bash# Unit tests make test # End-to-end tests make test-e2e
Scaling not happening:
Permission errors:
Target resource not found:
bash# Check CRD installation kubectl get crd cronjobscaledowns.cronschedules.elbazi.co # Verify operator deployment kubectl get deployment -n cronjob-scale-down-operator-system # Check events kubectl get events --sort-by=.metadata.creationTimestamp
Licensed under the Apache License, Version 2.0. See LICENSE for details.
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务