轩辕镜像 官方专业版
轩辕镜像
专业版
轩辕镜像 官方专业版
轩辕镜像
专业版
首页个人中心搜索镜像
交易
充值流量¥7起我的订单
文档
工具
提交工单页面收录
cronjob-scale-down-operator

cronschedules/cronjob-scale-down-operator

cronschedules

Kubernetes operator for scheduled scaling of Deployments and StatefulSets.

下载次数: 0状态:社区镜像维护者:cronschedules仓库类型:镜像最近更新:1 个月前
让 AI 帮你使用轩辕镜像? · 展开查看说明 · 点击收起说明

如果你使用 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

CronJob-Scale-Down-Operator

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)

Features

  • 🕒 Cron-based Scheduling: Uses standard cron expressions with second precision
  • 🌍 Timezone Support: Configure schedules in any timezone
  • 📈 Flexible Scaling: Scale down and up on different schedules
  • 🎯 Multiple Resource Types: Supports Deployments and StatefulSets for scaling
  • 🧹 Resource Cleanup: Automatically delete test resources based on annotations
  • 🏷️ Cleanup-Only Mode: Pure cleanup functionality without scaling any target resources
  • 📊 Status Tracking: Monitor last execution times and current replica counts
  • 🌐 Web UI Dashboard: Built-in web interface to monitor all cron jobs and their status
  • 📈 Prometheus Metrics: Comprehensive metrics for scaling operations, cleanup activities, and system health
  • ⚡ Efficient: Only reconciles when needed, with smart requeue timing
  • 🛡️ Safe Testing: Dry-run mode for cleanup operations
  • 🔧 Graceful Error Handling: Continues operation even when target resources are missing

Quick Start

Prerequisites

  • Kubernetes cluster (v1.16+)
  • kubectl configured
  • Cluster admin permissions

Installation

Option 1: Using Helm (Recommended)

📦 Helm charts have been migrated to a dedicated repository for better management.

  1. Add the charts repository:

    bash
    helm repo add cronschedules https://cronschedules.github.io/charts
    helm repo update
    
  2. Install the operator:

    bash
    helm install cronjob-scale-down-operator cronschedules/cronjob-scale-down-operator
    
  3. Install with custom values:

    bash
    helm 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
    
  4. Verify installation:

    bash
    kubectl 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

  1. Install the CRDs and operator:
    bash
    kubectl apply -f config/crd/bases/
    kubectl apply -f config/rbac/
    kubectl apply -f config/manager/
    

Quick Test

  1. Create a test deployment:

    bash
    kubectl apply -f examples/test-deployment.yaml
    
  2. Apply a scaling schedule:

    bash
    kubectl apply -f examples/quick-test.yaml
    
  3. Monitor the scaling:

    bash
    kubectl get cronjobscaledown -w
    kubectl get deployment nginx-test -w
    

📦 Charts Repository Migration

Important Notice: Helm charts have been migrated to a dedicated repository for better management and hosting.

Migration Details

  • Previous Location: Charts were located in /charts directory of this repository
  • New Location: https://github.com/cronschedules/charts repository
  • Helm Repository URL: https://cronschedules.github.io/charts

Benefits of Migration

✅ 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

For Existing Users

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

Chart Documentation

For comprehensive chart documentation, configuration options, values, and advanced usage:

  • 📖 https://github.com/cronschedules/charts
  • 📋 https://github.com/cronschedules/charts/tree/main/cronjob-scale-down-operator
  • ⚙️ https://github.com/cronschedules/charts/blob/main/cronjob-scale-down-operator/values.yaml

Examples

The examples/ directory contains various use cases:

ExampleDescriptionSchedule
quick-test.yamlImmediate testingEvery minute
basic-daily-schedule.yamlProduction workload10 PM → 6 AM daily
weekend-shutdown.yamlWeekend cost savingsFriday 6 PM → Monday 8 AM
development-testing.yamlDev environmentEvery 30/45 seconds
multi-timezone.yamlGlobal deploymentsMultiple timezones
statefulset-example.yamlDatabase scalingStatefulSet support
resource-cleanup-example.yamlResource cleanupCom*ed scaling + cleanup**
cleanup-only-example.yamlCleanup onlyEvery 6 hours
orphan-cleanup-example.yamlOrphan resource cleanupEvery 3 AM daily

Cleanup-Only Mode

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.

When to Use Cleanup-Only Mode

  • CI/CD Pipelines: Automatically clean up test resources after builds
  • Development Environments: Remove temporary test objects on a schedule
  • Resource Management: Clean up expired ConfigMaps, Secrets, or test deployments
  • Cost Optimization: Remove unused resources to save cluster costs

Cleanup-Only Configuration

yaml
apiVersion: 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"

Com***ed Scaling + Cleanup

You can also com***e scaling and cleanup in a single resource:

yaml
apiVersion: 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"

Configuration

CronJobScaleDown Spec

yaml
apiVersion: 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.

Resource Cleanup Configuration

The operator now supports automatic cleanup of test resources based on annotations:

yaml
apiVersion: 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:

  • Duration: 24h, 7d, 30m (relative to resource creation time)
  • Absolute time: 2024-12-31T23:59:59Z (RFC3339 format)
  • Date: 2024-12-31 (cleanup at midnight on that date)
  • Immediate: E***y value "" (cleanup on next schedule run)

Example Resource with Cleanup Annotation

yaml
apiVersion: 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:

  • Enable cleanupOrphanResources: true in the cleanup configuration
  • Set orphanResourceMaxAge to define how old resources must be before cleanup
  • Only resources matching the label selector (if specified) will be ***ed
  • Resources without the cleanup annotation that are older than the max age will be deleted

Example scenario:

yaml
cleanupConfig:
  annotationKey: "cleanup-after"
  resourceTypes: ["ConfigMap", "Role", "RoleBinding"]
  cleanupOrphanResources: true
  orphanResourceMaxAge: "168h"  # 7 days
  labelSelector:
    app.kubernetes.io/managed-by: "test"

This configuration will:

  1. Clean up resources WITH the cleanup-after annotation according to their specified cleanup time
  2. Clean up resources WITHOUT the annotation that are labeled with app.kubernetes.io/managed-by: test and are older than 7 days

Supported Resource Types:

  • Standard resources: Deployment, StatefulSet, Service, ConfigMap, Secret
  • Workload resources: Pod, Job (useful for cleaning up failed/evicted resources)
  • RBAC resources: Role, RoleBinding, ClusterRole, ClusterRoleBinding

**Safety *ations:

  • Orphan cleanup is opt-in (disabled by default)
  • Always test with dryRun: true first
  • Use label selectors to limit scope
  • Set appropriate max age to avoid deleting important resources

Schedule Format

The 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

ScheduleDescription
"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)

Supported Timezones

Use standard IANA timezone names:

  • UTC
  • America/New_York
  • Europe/London
  • Europe/Berlin
  • Asia/Tokyo
  • Australia/Sydney

Monitoring

Check CronJobScaleDown Status

bash
kubectl get cronjobscaledown -o wide
kubectl describe cronjobscaledown my-scaler

View Operator Logs

bash
kubectl logs -n cronjob-scale-down-operator-system deployment/cronjob-scale-down-operator-controller-manager

Monitor Target Resources

bash
kubectl get deployment my-deployment -w
kubectl get statefulset my-statefulset -w

Prometheus Metrics

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:

  • Scaling Operations: cronjob_scale_down_operations_total, cronjob_scale_up_operations_total
  • Cleanup Operations: cronjob_cleaned_resources_total, cronjob_cleanup_operations_total
  • Resource Status: cronjob_target_resource_replicas_current, cronjob_scaled_down_resources_current
  • System Health: cronjob_reconciliation_errors_total, cronjob_reconciliation_duration_seconds
  • Schedules: cronjob_schedule_next_execution_timestamp, cronjob_schedule_last_execution_timestamp

For detailed metrics documentation, PromQL queries, and Grafana dashboard examples, see METRICS.md.

Web UI Dashboard

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

Accessing the Web UI

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:

  1. Port forwarding (for development/testing):

    bash
    kubectl port-forward -n cronjob-scale-down-operator-system deployment/cronjob-scale-down-operator-controller-manager 8082:8082
    

    Then visit http://localhost:8082

  2. Configure ingress (for production):

    yaml
    apiVersion: 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
    

Web UI Features

  • 📊 Real-time Dashboard: Overview of all CronJobScaleDown resources
  • 📈 Status Monitoring: Current state of target deployments and statefulsets
  • 🕒 Schedule Information: View scale-up/down schedules and timezones
  • 📋 Replica Status: Visual indicators for ready vs desired replicas
  • 📅 Action History: Timestamps of last scale operations
  • 🔄 Auto-refresh: Updates every 30 seconds automatically
  • 📱 Responsive Design: Works on desktop, tablet, and mobile

Customizing Web UI Port

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.

Development

Building from Source

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

Running Tests

bash
# Unit tests
make test

# End-to-end tests
make test-e2e

Troubleshooting

Common Issues

  1. Scaling not happening:

    • Check timezone configuration
    • Verify cron schedule syntax
    • Check operator logs for errors
  2. Permission errors:

    • Ensure RBAC is properly configured
    • Verify service account permissions
  3. Target resource not found:

    • Check namespace and resource name
    • Verify resource exists and is accessible

Debug Commands

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

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

Support

  • 📧 Issues: https://github.com/z4ck404/cronjob-scale-down-operator/issues
  • 📖 Documentation: docs/
  • 💬 Discussions: https://github.com/z4ck404/cronjob-scale-down-operator/discussions

镜像拉取方式

您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。

轩辕镜像加速拉取命令点我查看更多 cronjob-scale-down-operator 镜像标签

docker pull docker.xuanyuan.run/cronschedules/cronjob-scale-down-operator:<标签>

使用方法:

  • 登录认证方式
  • 免认证方式

DockerHub 原生拉取命令

docker pull cronschedules/cronjob-scale-down-operator:<标签>

轩辕镜像配置手册

按平台快速找到配置文档

一键安装

一键安装 Docker

Linux Docker 一键安装

AI

用 AI 使用轩辕镜像

agents.md · AI 对话 · 提示词

Docker

登录仓库拉取

登录认证 · 私有仓库

专属域名拉取

免登录 · 高速拉取

Linux

Docker 镜像配置

Windows / Mac

Docker Desktop 配置

MacOS OrbStack

OrbStack 容器

Apple Container

macOS 原生容器

Docker Compose

Compose 项目配置

NAS

群晖

Synology 配置

飞牛

fnOS 镜像配置

绿联

绿联 NAS

威联通

QNAP 配置

极空间

极空间 NAS

Unraid

Unraid NAS

企业仓库

其他仓库

ghcr · Quay · nvcr

Harbor 镜像源

Proxy Repository 对接

Portainer 镜像源

Registries 配置

Nexus 镜像源

Docker Proxy 缓存

开发工具

Dev Containers

VS Code 开发容器

Podman

Podman 配置指南

Singularity / Apptainer

HPC 科学计算容器

Kubernetes

K8s Containerd

Kubernetes · Containerd

K3s

轻量级集群

面板 / 网络

爱快路由

iKuai 镜像加速

宝塔面板

一键配置镜像源

需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单

镜像拉取常见问题

功能

版本功能对比

功能对比 · 版本选择

支持的镜像仓库

Docker Hub · GCR · GHCR

新手拉取配置

登录 · 专属域名 · 配置

docker search 限制

专属域名 · Hub 搜索

不支持 push

仅支持 pull · 不支持

拉取速度原因

带宽 · 缓存 · 冷热镜像

错误码

402 与流量用尽

402 · 流量包 · 充值

401 认证失败

401 · docker login

manifest unknown

标签错误 · 镜像不存在

410 Gone 排查

410 · Docker 升级

429 限流

免费版 · 专业版 · 企业版 · 请求频率

其他报错

DNS 超时

DNS 解析 · 网络超时

TLS 证书失败

no matching manifest(架构)

账号

失败是否计费

manifest · blob · 计费

申请开发票(企业 / 个人)

企业 · 个人 · 工单

修改登录密码

网站 · 仓库 · 重置

注销账户

工单 · 数据 · 注销

原理

mirrors 不生效

daemon.json · 重启

去掉域名前缀

docker tag · 重命名

指定架构拉取

ARM64 · AMD64 · 多架构

latest 与「最新」

digest · 版本号 · 标签

查看全部问题→

用户好评

来自真实用户的反馈,见证轩辕镜像的优质服务

用户头像

oldzhang

运维工程师

Linux服务器

5

"Docker访问体验非常流畅,大镜像也能快速完成下载。"

轩辕镜像
镜像详情
...
cronschedules/cronjob-scale-down-operator
定价查看流量套餐与价格
博客Docker 镜像公告与技术博客
专业版 · 高速稳定拉取镜像
高速镜像下载·在线技术支持·99.95% SLA 保障·付费会员免广告
50GB 仅 ¥7/年
专业版 · 高速稳定拉取镜像
50GB 仅 ¥7/年
高速镜像下载·在线技术支持·99.95% SLA 保障·付费会员免广告
用户协议·隐私政策·增值电信业务经营许可证:浙B2-20261007·©2024-2026 源码跳动©2024-2026 杭州源码跳动科技有限公司·商务合作:点击复制邮箱

更多 cronjob-scale-down-operator 镜像推荐

victoriametrics/operator logo

victoriametrics/operator

victoriametrics
用于在Kubernetes环境中自动化部署、管理和运维Victoria Metrics时序数据库的Operator控制器
1亿+ 次下载
11 天前更新
mariadb/maxscale logo

mariadb/maxscale

mariadb
MariaDB MaxScale 是世界上最先进的数据库代理,它能够实现数据库负载均衡、读写分离、高可用性支持与故障自动切换,同时提供数据分片管理、安全访问控制及性能监控等功能,有效提升数据库系统的运行效率、稳定性与可扩展性,简化复杂数据库环境的管理与维护。
40 次收藏500万+ 次下载
20 天前更新

查看更多 cronjob-scale-down-operator 相关镜像