πŸ’€ KubeNidra
πŸ’» KubeNidra CLI

Overview

The KubeNidra CLI is a command-line tool for managing workload hibernation in Kubernetes clusters. It provides a simple interface to enable, disable, and control KubeNidra behavior for various workload types including Deployments, StatefulSets, DaemonSets, and ReplicaSets.

Features

The CLI offers comprehensive workload management capabilities:

  • Enable/Disable: Turn KubeNidra on or off for workloads
  • Manual Control: Snooze and wake workloads on demand
  • Schedule Management: Set and update wake schedules
  • Override Control: Clear manual override, set temporary or permanent manual overrides
  • State Pinning: Pin workloads in their current state
  • Status Monitoring: View detailed status and operation history for one or all workloads
  • Workload Listing: List all KubeNidra-enabled workloads

Supported Workload Types

The CLI supports all major Kubernetes workload types:

  • DaemonSets: Node-level workloads
  • Deployments: Most common workload type
  • ReplicaSets: Direct replica set management
  • StatefulSets: Stateful applications with persistent storage

Basic Usage

# Basic command structure
kubenidra <command> <workload-type> [workload-name] [-n <namespace>]

# Examples
kubenidra enable deployment my-app -n default
kubenidra snooze statefulset database -n test
kubenidra status deployment my-app -n test

Global Flags

FlagShortDescription
--kubeconfig-kPath to kubeconfig file
--namespace-nKubernetes namespace

Commands Overview

Core Management

  • enable: Enable KubeNidra for a workload
  • disable: Disable KubeNidra for a workload
  • snooze: Manually snooze a workload
  • wake: Wake up a snoozed workload

Advanced Control

  • override: Set manual override to disable automatic behavior
  • clear-override: Clear manual override and restore automatic behavior
  • pin: Pin workload in current state
  • unpin: Remove pin and restore normal behavior

Configuration

  • schedule: Update wake schedule for a workload

Monitoring

  • status: Show detailed status for a workload
  • list-status: Show details status for all workloads
  • list-enabled: List all KubeNidra-enabled workloads

Quick Start

1. Enable KubeNidra for a Deployment

# Enable with default settings
kubenidra enable deployment my-app -n test

# Enable with custom wake schedule
kubenidra enable deployment my-app -n test --schedule "09:00-17:00,mon-fri"

2. Check Status

# Check specific workload
kubenidra status deployment my-app -n test

# List all enabled deployments
kubenidra list-enabled deployment

3. Manual Control

# Manually snooze
kubenidra snooze deployment my-app -n test

# Manually wake
kubenidra wake deployment my-app -n test

4. Advanced Operations

# Set temporary override (2 hours)
kubenidra override deployment my-app -n test --duration 2h

# Pin in current state
kubenidra pin deployment my-app -n test

# Update schedule
kubenidra schedule deployment my-app -n test --schedule "08:00-18:00,mon-sun"

Workload Annotations

The CLI manages workload behavior through Kubernetes annotations:

metadata:
  annotations:
    # Enable KubeNidra
    kubenidra/enabled: "true"

    # Wake schedule 09:00-17:00,mon-wed,fri;08:00-18:00,thu;22:00-03:00,fri-mon
    kubenidra/wake-schedule: "09:00-17:00,mon-fri"

    # Manual requests
    kubenidra/snooze-now: "true"
    kubenidra/wake-now: "true"

    # State preservation
    kubenidra/last-replicas: "3"
    kubenidra/snoozed-at: "2024-01-15T10:30:00Z"
    kubenidra/woken-at: "2024-01-15T10:00:00Z"

    # Manual overrides
    kubenidra/manual-override: "true"
    kubenidra/manual-override-until: "2024-01-15T12:00:00Z"

    # Pin state
    kubenidra/pin-state: "active" # or "snoozed"

    # Operation tracking
    kubenidra/operation-in-progress: "snooze"
    kubenidra/backoff-until: "2024-01-15T11:00:00Z"

    kubenidra/last-operation-at: "2024-01-15T10:00:00Z"
    kubenidra/last-operation-type: "snooze"
    kubenidra/operation-history: "" # JSON encoded string storing operation history
    kubenidra/operation-count: "" # JSON encoded hourly operation counters to determine backoff

Schedule Format

Wake schedules use a flexible format:

# Basic format: time-range,days
"09:00-17:00,mon-fri"

# Multiple ranges
"09:00-17:00,mon-wed,fri;08:00-18:00,thu"

# 24-hour format with wrap around for time and days
"22:00-03:00,fri-mon"

# All week
"08:00-18:00,mon-sun"

Error Handling

The CLI provides clear error messages and validation:

# Invalid schedule
$ kubenidra enable deployment my-app -n test --schedule "invalid"
Error: invalid schedule for deployment: invalid, invalid schedule segment format: invalid, missing comma

# Workload not found
$ kubenidra status deployment nonexistent -n test
Error: failed to get deployment: deployments.apps "nonexistent" not found

# KubeNidra not enabled
$ kubenidra snooze deployment my-app -n test
KubeNidra is not enabled for deployment default/my-app

Best Practices

1. Use Namespace Specification

Always specify the namespace for clarity:

# Good
kubenidra enable deployment my-app -n development

2. Test with Conservative Settings

Start with manual mode and gradually enable automation:

# Enable with schedule
kubenidra enable deployment my-app -n test --schedule "09:00-17:00,mon-fri"

# Test manual control
kubenidra snooze deployment my-app -n test
kubenidra wake deployment my-app -n test

3. Use Overrides for Maintenance

Set overrides during maintenance windows:

# Temporary override for maintenance
kubenidra override deployment my-app -n test --duration 4h

# Clear when done
kubenidra clear-override deployment my-app -n test

Integration with Agent

The CLI works in conjunction with the KubeNidra Agent:

  1. CLI: Sets annotations and configuration
  2. Agent: Monitors workloads and executes operations
  3. Coordination: Both tools respect the same annotation system

Troubleshooting

Common Issues

  1. Permission Denied
# Check RBAC permissions
kubectl auth can-i update deployments --namespace development
  1. Workload Not Found
# Verify workload exists
kubectl get deployment my-app -n development
  1. Invalid Schedule
# Use correct format
kubenidra enable deployment my-app -n test --schedule "09:00-17:00,mon-fri"