Skip to main content

Local Kubernetes Environment Manager - Simplified local K8s development with Kind

Project description

LoKO - Local Kubernetes Oasis - simplified Kubernetes development environments

PyPI version Python Versions License: MIT

LoKO Logo

A Python CLI utility to manage local Kubernetes environments with Kind, providing simplified configuration management, version upgrades, DNS, wildcard certificates, local container registry, and extensive customization options.

Features

  • ๐Ÿš€ Easy Setup: Initialize local Kubernetes clusters with a single command
  • ๐Ÿ”„ Smart Version Management: Upgrade component versions using Renovate-style comments
  • ๐Ÿ’พ Automatic Backups: Config files are automatically backed up before upgrades
  • ๐ŸŽจ Custom Templates: Use your own Jinja2 templates for configuration generation
  • โš™๏ธ Extensive CLI Overrides: Override any configuration value via command-line flags
  • ๐Ÿ“ฆ Built-in Local Registry: Local container registry with TLS support
  • ๐Ÿ”’ Automatic HTTPS: Built-in certificate management with mkcert
  • ๐ŸŒ Local DNS: Automatic DNS configuration for local development
  • ๐Ÿ“ˆ Metrics & Monitoring: Built-in metrics-server for resource monitoring and HPA support
  • ๐Ÿ“Š Comprehensive Status: Detailed view of cluster resources with loko status
  • ๐ŸŽฏ Advanced Node Scheduling: Flexible node labeling and workload placement
  • ๐Ÿ”ง Service Presets: Pre-configured settings for common services (MySQL, PostgreSQL, Valkey, etc.)
  • ๐Ÿ› ๏ธ Helm-based Deployment: Deploy services from public repositories (groundhog2k, etc.)
  • ๐Ÿ—‚๏ธ Centralized Helm Repos: Define repositories once, reference everywhere
  • ๐Ÿ”‘ Automatic Secrets Management: Automatically generate, fetch and save service credentials

Prerequisites

  • Python 3.9 or higher
  • Docker
  • Kind
  • mkcert (for HTTPS certificates)
  • Helm
  • Helmfile (optional, for service deployment)
  • (optional) nss (for macOS) or libnss3-tools (for Linux) - needed for Firefox to trust mkcert certificates

Installation

From PyPI (recommended)

Using pip:

pip install loko-k8s

Using uv:

uv tool install loko-k8s

From Source

git clone https://github.com/bojanraic/loko.git
cd loko
pip install -e .

Using uv (for development)

git clone https://github.com/bojanraic/loko.git
cd loko
uv sync
uv run loko --help

Quick Start

  1. Check prerequisites:

    loko check-prerequisites
    
  2. Generate a default configuration:

    loko generate-config
    
  3. Initialize your environment:

    loko init
    
  4. Create the full environment:

    loko create
    

Demo

Watch Loko in action - see the complete workflow from installation to cluster validation:

asciicast

Demo highlights:

  • Installing loko
  • Generating a default configuration with auto-detected IP
  • Creating a local Kubernetes cluster with Kind
  • Deploying services (Traefik, container registry, PostgreSQL) with Helm
  • Validating the cluster setup
  • Checking environment status
  • Upgrading component versions
  • Viewing service secrets & connecting to PostgreSQL and test application
  • Stopping and starting environment
  • Installing shell completions

Commands

Environment Lifecycle

  • loko init - Initialize environment (generate configs, setup certs, network)
  • loko create - Create full environment with complete workflow
  • loko start - Start all cluster containers
  • loko stop - Stop all cluster containers
  • loko destroy - Destroy the environment
  • loko recreate - Destroy and recreate the environment
  • loko clean - Destroy environment and remove all artifacts

Status & Validation

  • loko status - Show comprehensive environment status
  • loko validate - Validate the environment
  • loko check-prerequisites - Check if required tools are installed

Configuration & Secrets

  • loko generate-config - Generate default loko.yaml
  • loko config upgrade - Upgrade component versions using Renovate comments
  • loko secrets - Fetch and display service credentials
  • loko config presets - View available service presets (coming soon)

Checking Cluster Status

Use the status command to get a comprehensive overview of your local Kubernetes environment:

loko status

This will display:

  • Cluster Status: Overall health of the Kubernetes cluster
  • Container Status: Status of all related containers (nodes, DNS, etc.)
  • Node Status: List of all nodes with their roles and status
  • DNS Status: Status of the local DNS service

Version Management & Upgrades

Loko uses Renovate-style comments in your configuration file to track and upgrade component versions. This approach allows you to:

  • Keep component versions up-to-date
  • Track version sources directly in your config
  • Automatically query Docker Hub and Helm repositories for latest versions

How It Works

Add Renovate comments above the version fields in your loko.yaml:

kubernetes:
  image: kindest/node
  # renovate: datasource=docker depName=kindest/node
  tag: v1.34.0

internal-components:
  # renovate: datasource=helm depName=traefik repositoryUrl=https://traefik.github.io/charts
  - traefik: "37.3.0"

services:
  system:
    - name: mysql
      config:
        chart: groundhog2k/mysql
        # renovate: datasource=helm depName=mysql repositoryUrl=https://groundhog2k.github.io/helm-charts
        version: 3.0.7

Supported Datasources

  • Docker Hub (datasource=docker): Fetches latest tags from Docker Hub
  • Helm Repositories (datasource=helm): Fetches latest chart versions from Helm repos

Running Upgrades

loko config upgrade

This will:

  1. ๐Ÿ” Scan your config for Renovate comments
  2. ๐ŸŒ Query each datasource for the latest version
  3. ๐Ÿ’พ Create a backup (loko-prev.yaml)
  4. โœ… Update versions in place
  5. ๐Ÿ“‹ Show a summary of changes

Example output:

Upgrading component versions...

๐Ÿ” Checking kindest/node (docker)...
๐Ÿ” Checking traefik (helm)...
๐Ÿ” Checking mysql (helm)...

Updates found:
  kindest/node: v1.32.0 โ†’ v1.34.0
  traefik: 31.2.0 โ†’ 37.3.0
  mysql: 3.0.5 โ†’ 3.0.7

๐Ÿ’พ Backup created: loko-prev.yaml
โœ… Updated 3 version(s) in loko.yaml

Restoring from Backup

If an upgrade causes issues, easily revert:

mv loko-prev.yaml loko.yaml

Managing Service Credentials

Service credentials (database passwords, etc.) are automatically generated during deployment. To view them:

loko secrets

This fetches credentials from the cluster and displays them. Credentials are also saved to:

<base-dir>/<env-name>/service-secrets.txt

Example services with auto-generated credentials:

  • MySQL (root password)
  • PostgreSQL (postgres password)
  • MongoDB (root password)
  • RabbitMQ (admin password)
  • Valkey (default password)

Directory Structure

When you run loko init or loko create, a .local directory is created (configurable via base-dir).

.
โ”œโ”€โ”€ loko.yaml                       # Main configuration file
โ”œโ”€โ”€ .local/                            # Default directory for cluster data and configs
โ”‚   โ””โ”€โ”€ <env-name>/                    # Environment-specific directory (e.g. dev-me)
โ”‚       โ”œโ”€โ”€ certs/                     # TLS certificates and keys
โ”‚       โ”‚   โ”œโ”€โ”€ rootCA.pem             # Root CA certificate
โ”‚       โ”‚   โ”œโ”€โ”€ <domain>.pem           # Domain certificate
โ”‚       โ”‚   โ”œโ”€โ”€ <domain>-key.pem       # Domain private key
โ”‚       โ”‚   โ””โ”€โ”€ <domain>-combined.pem  # Combined cert and key
โ”‚       โ”œโ”€โ”€ config/                    # Generated configuration files
โ”‚       โ”‚   โ”œโ”€โ”€ cluster.yaml           # KinD cluster configuration
โ”‚       โ”‚   โ”œโ”€โ”€ containerd.yaml        # Container runtime config
โ”‚       โ”‚   โ”œโ”€โ”€ dnsmasq.conf           # Local DNS configuration
โ”‚       โ”‚   โ””โ”€โ”€ helmfile.yaml          # Helm releases definition
โ”‚       โ”œโ”€โ”€ logs/                      # Kubernetes node logs
โ”‚       โ”œโ”€โ”€ storage/                   # Persistent volume data
โ”‚       โ”œโ”€โ”€ kubeconfig                 # Cluster access configuration
โ”‚       โ””โ”€โ”€ service-secrets.txt        # Generated service credentials

Note: The .local directory is git-ignored by default.

Service Management

The environment manages development services (databases, message queues, etc.) through Helm deployments.

Service Types and DNS Structure

  1. System Services (service.local.domain):

    • Core infrastructure services (databases, message queues, etc.)
    • Direct DNS resolution (e.g., mysql.dev.me, postgres.dev.me)
    • No wildcard resolution for security
  2. Applications (${LOCAL_APPS_DOMAIN}):

    • Custom applications and services
    • Either under .apps subdomain (service.apps.local.domain) or direct domain (service.local.domain)
    • Configurable via use-apps-subdomain setting
  3. Core Infrastructure:

    • Registry service (e.g., cr.dev.me)

Accessing Services

Once the environment is running, services are accessible through:

  1. Direct Port Access:

    # Example for PostgreSQL
    psql -h localhost -p 5432 -U postgres
    
  2. Domain Names:

    # Example for system service
    psql -h postgres.dev.me -U postgres
    
  3. Service Credentials:

    • Passwords are automatically generated and stored in <local-dir>/<env-name>/service-secrets.txt
    • Or fetch them with: loko secrets

Using the Local Container Registry

The environment includes a local container registry accessible at <registry-name>.<local-domain>.

  1. Push Images:

    docker tag myapp:latest cr.dev.me/myapp:latest
    docker push cr.dev.me/myapp:latest
    
  2. Use in Kubernetes:

    image: cr.dev.me/myapp:latest
    

Node Scheduling and Workload Placement

The environment supports advanced node scheduling configurations to separate infrastructure and application workloads.

Node Labels

Configure custom labels in loko.yaml:

nodes:
  labels:
    control-plane:
      tier: "infrastructure"
    worker:
      tier: "application"

Scheduling Flags

  • internal-components-on-control-plane: Forces infrastructure components (Traefik, registry) to run only on control-plane nodes.
  • run-services-on-workers-only: Forces application services (databases, etc.) to run only on worker nodes.

OCI Registry and Helm Chart Validation

Loko includes validation workflows for testing OCI registry functionality.

Run validation with:

loko validate

This runs a comprehensive check including:

  1. Cluster status and node readiness
  2. DNS service health
  3. System pods status
  4. Kubectl connectivity
  5. Registry & TLS Validation: Builds a test image, pushes to local registry, deploys a test app, and verifies connectivity.

Configuration

The environment is configured through loko.yaml. You can generate a default one with loko generate-config.

Schema Structure

environment:
  # General settings
  name: string                    # Name of the environment
  base-dir: string                # Base directory for storage
  expand-env-vars: boolean        # Whether to expand OS and k8s-env variables

  # Centralized repository definitions
  helm-repositories: array        # List of Helm repositories

  # Provider configuration
  provider:
    name: string                  # Provider name (currently only "kind" supported)
    runtime: string               # Container runtime (docker or podman)

  # Kubernetes configuration
  kubernetes:
    api-port: integer             # API server port
    image: string                 # Node image
    tag: string                   # Node image tag

  # Node configuration
  nodes:
    servers: integer              # Number of control-plane nodes
    workers: integer              # Number of worker nodes
    allow-scheduling-on-control-plane: boolean
    internal-components-on-control-plane: boolean

  # Network configuration
  local-ip: string                # Local IP for DNS resolution
  local-domain: string            # Domain name
  local-lb-ports: array           # Load balancer ports
  use-apps-subdomain: boolean     # Use apps subdomain
  apps-subdomain: string          # Subdomain for apps

  # Registry configuration
  registry:
    name: string
    storage:
      size: string

  # Internal components
  internal-components: array      # List of internal components with versions

  # Service configuration
  use-service-presets: boolean    # Whether to use service presets
  run-services-on-workers-only: boolean
  enable-metrics-server: boolean
  services:
    system: array                 # List of system services to deploy
    user: array                   # List of user-defined services

CLI Overrides

Loko provides extensive CLI options to override almost any configuration value during initialization:

loko init --name my-cluster --workers 3 --registry-storage 50Gi --no-schedule-on-control

See loko init --help for all available overrides.

Troubleshooting

  1. DNS Resolution Issues

    • Verify local DNS container is running: loko status
    • Check DNS configuration: cat /etc/resolver/<your-domain>
  2. Certificate Issues

    • Regenerate certificates: loko init (will re-run certificate setup)
    • Verify cert location: ls <local-dir>/<env-name>/certs/
  3. Service Access Issues

    • Validate environment: loko validate
    • Verify ingress: kubectl get ingress -A
    • Check credentials: loko secrets
  4. OCI Registry Issues

    • Test registry connectivity: docker pull cr.dev.me/test:latest
    • Run validation: loko validate
  5. Version Upgrade Issues

    • Restore from backup: mv loko-prev.yaml loko.yaml
    • Check Renovate comment syntax in config file

Development

Setup

git clone https://github.com/bojanraic/loko.git
cd loko
uv sync
uv run loko --help

Running Tests

uv run loko --help
uv run loko init --help

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loko_k8s-0.0.5.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loko_k8s-0.0.5-py3-none-any.whl (44.4 kB view details)

Uploaded Python 3

File details

Details for the file loko_k8s-0.0.5.tar.gz.

File metadata

  • Download URL: loko_k8s-0.0.5.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for loko_k8s-0.0.5.tar.gz
Algorithm Hash digest
SHA256 f739280e379c252e99a1525185b23f1e2cf9af256226e6d6a939c2b3f05b499e
MD5 40b96eaeb45e5f79e1f6f475d930db2a
BLAKE2b-256 e47d62cf212269bc42e199d6c87ab775e2b35e73629ef598b74662d25380393e

See more details on using hashes here.

Provenance

The following attestation bundles were made for loko_k8s-0.0.5.tar.gz:

Publisher: publish.yml on bojanraic/loko

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file loko_k8s-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: loko_k8s-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 44.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for loko_k8s-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c5745398cb956bd6a08a24dc6b518f68b7aed256729ddf2730b0e098410200f6
MD5 fdc163ea030543a7414c42a77deb623c
BLAKE2b-256 bac27401666fb0c7da5c4fd0a06baa80de4cae434e83348d5c2b8ab8c955f517

See more details on using hashes here.

Provenance

The following attestation bundles were made for loko_k8s-0.0.5-py3-none-any.whl:

Publisher: publish.yml on bojanraic/loko

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page