Claude-skill-registry Lightweight Kubernetes
Optimized Kubernetes distributions and configurations for resource-constrained edge and IoT deployments
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/lightweight-kubernetes" ~/.claude/skills/majiayu000-claude-skill-registry-lightweight-kubernetes && rm -rf "$T"
skills/data/lightweight-kubernetes/SKILL.mdLightweight Kubernetes
Current Level: Expert (Enterprise Scale) Domain: Edge Computing / IoT / DevOps Skill ID: 81
Overview
Lightweight Kubernetes provides container orchestration for resource-constrained edge and IoT devices. It uses minimal resource footprints while providing core Kubernetes functionality for edge computing scenarios.
Why This Matters / Strategic Necessity
Context
In 2025-2026, edge computing deployments require orchestration for containers but standard Kubernetes is too resource-intensive for constrained devices. Lightweight Kubernetes enables edge-native orchestration with minimal overhead.
Business Impact
- Resource Efficiency: 60-80% reduction in resource requirements
- Edge Enablement: Enables containerized edge applications
- Cost Reduction: Lower hardware requirements for edge devices
- Operational Consistency: Same orchestration across cloud and edge
Product Thinking
Solves critical problem where edge deployments cannot use standard Kubernetes due to resource constraints, leading to manual management and inconsistent operations across edge locations.
Core Concepts / Technical Deep Dive
1. Lightweight Kubernetes Distributions
K3s:
- Single binary deployment
- Minimal resource footprint
- Supports ARM and x86 architectures
- SQLite-based storage backend
MicroK8s:
- Optimized for edge workloads
- Minimal memory footprint (< 100MB)
- Fast startup time
- SQLite-based storage
K0s:
- Zero dependency footprint
- All-in-one binary
- Minimal resource requirements
- Edge-optimized networking
KubeEdge:
- Cloud-native edge management
- Optimized for edge workloads
- Lightweight agent
- Offline capabilities
2. Edge Architecture
┌─────────────────────────────────────────────────────────────────┐ │ Edge Infrastructure │ ├─────────────────────────────────────────────────────────────────┤ │ Edge Node 1 │ Edge Node 2 │ Edge Node 3 │ │ - K3s/K0s │ - K3s/K0s │ - K3s/K0s │ │ - Containers │ - Containers │ - Containers │ │ - Edge Apps │ - Edge Apps │ - Edge Apps │ ├───────────────────────┼───────────────────────┼───────────────────────┤ │ Edge Management │ Cloud API │ Local Registry │ │ - KubeEdge │ - Control Plane │ - Container Store │ └───────────────────────┴───────────────────────┴───────────────────────┘
3. Resource Optimization
Memory Optimization:
- Minimal control plane components
- Efficient garbage collection
- Shared resource pools
- Memory-mapped storage
CPU Optimization:
- Single-threaded control plane
- Efficient scheduling
- Minimal overhead operations
- Event-driven architecture
Storage Optimization:
- SQLite for small deployments
- Efficient object storage
- Minimal metadata overhead
- Log rotation
4. Edge-Specific Features
Offline Operation:
- Local caching
- Disconnected mode
- Sync on reconnection
- Queue operations
Resource Constraints:
- Memory limits enforcement
- CPU quota management
- Storage optimization
- Network bandwidth awareness
Hardware Acceleration:
- GPU support
- NPU integration
- TPU optimization
- Custom accelerators
Tooling & Tech Stack
Enterprise Tools
- K3s: Lightweight Kubernetes distribution
- K0s: All-in-one Kubernetes binary
- MicroK8s: Minimal Kubernetes for edge
- KubeEdge: Cloud-native edge platform
- Rancher K3s: Managed K3s distribution
- Portainer: Lightweight container management
Configuration Essentials
# Lightweight Kubernetes configuration k3s: # Distribution selection distribution: "k3s" # k3s, k0s, microk8s, kubedge # Resource limits resources: max_memory_mb: 512 max_cpu_percent: 50 max_pods: 10 reserved_memory_mb: 64 # Storage configuration storage: type: "sqlite" # sqlite, etcd, none data_dir: "/var/lib/rancher/k3s" snapshot_enabled: false # Networking networking: mode: "flannel" # flannel, calico, cilium mtu: 1400 dns_enabled: true # Edge-specific settings edge: offline_mode: true sync_interval_minutes: 30 cache_enabled: true queue_operations: true bandwidth_limit_mbps: 100 # Hardware acceleration acceleration: gpu_enabled: false npu_enabled: false custom_accelerators: [] # Logging logging: level: "info" # debug, info, warn, error log_rotation: true max_log_files: 5 max_log_size_mb: 10
Code Examples
Good vs Bad Examples
# ❌ Bad - Standard Kubernetes on edge device apiVersion: v1 kind: Node metadata: name: edge-node spec: # Requires 2GB+ RAM - not suitable for edge kubelet: memory: 2Gi cpu: 2 # ✅ Good - Lightweight Kubernetes configuration apiVersion: v1 kind: Node metadata: name: edge-node spec: # Optimized for edge (512MB RAM) kubelet: memory: 512Mi cpu: 500m maxPods: 10
# ❌ Bad - Full Kubernetes installation curl -sfL https://dl.k8s.io/release/stable.txt | xargs -I {} bash -c 'curl -SL https://dl.k8s.io/release/$0/bin/linux/amd64/kubeadm' # ✅ Good - Lightweight K3s installation curl -sfL https://github.com/k3s-io/k3s/releases/download/v1.28.0/k3s-linux-amd64 chmod +x k3s ./k3s server --docker --no-deploy --write-kubeconfig-mode=644
Implementation Example
""" Production-ready Lightweight Kubernetes Manager """ from typing import Dict, List, Optional, Any, Tuple from datetime import datetime, timedelta import subprocess import json import logging from dataclasses import dataclass, field from enum import Enum import yaml import requests logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) class K8sDistribution(Enum): """Lightweight Kubernetes distributions.""" K3S = "k3s" K0S = "k0s" MICROK8S = "microk8s" KUBEEDGE = "kubedge" class EdgeMode(Enum): """Edge operation modes.""" ONLINE = "online" OFFLINE = "offline" HYBRID = "hybrid" @dataclass class EdgeNode: """Edge node information.""" node_id: str ip_address: str distribution: K8sDistribution version: str resources: Dict[str, Any] status: str last_seen: datetime @dataclass class EdgePod: """Edge pod information.""" pod_id: str node_id: str name: str containers: List[str] resources: Dict[str, Any] status: str created_at: datetime class LightweightK8sManager: """ Enterprise-grade lightweight Kubernetes manager. """ def __init__( self, distribution: K8sDistribution = K8sDistribution.K3S, edge_mode: EdgeMode = EdgeMode.HYBRID, max_memory_mb: int = 512, max_pods: int = 10 ): """ Initialize lightweight K8s manager. Args: distribution: K8s distribution to use edge_mode: Edge operation mode max_memory_mb: Maximum memory in MB max_pods: Maximum number of pods """ self.distribution = distribution self.edge_mode = edge_mode self.max_memory_mb = max_memory_mb self.max_pods = max_pods # Edge nodes self.nodes: Dict[str, EdgeNode] = {} # Pods self.pods: Dict[str, EdgePod] = {} # Offline queue self.offline_queue: List[Dict[str, Any]] = [] logger.info(f"Lightweight K8s manager initialized: {distribution.value}") def install_distribution( self, node_id: str, ip_address: str ) -> bool: """ Install lightweight Kubernetes distribution. Args: node_id: Edge node ID ip_address: IP address of edge node Returns: True if successful """ try: if self.distribution == K8sDistribution.K3S: return self._install_k3s(node_id, ip_address) elif self.distribution == K8sDistribution.K0S: return self._install_k0s(node_id, ip_address) elif self.distribution == K8sDistribution.MICROK8S: return self._install_microk8s(node_id, ip_address) else: raise ValueError(f"Unknown distribution: {self.distribution}") except Exception as e: logger.error(f"Failed to install distribution: {e}") return False def _install_k3s(self, node_id: str, ip_address: str) -> bool: """ Install K3s distribution. Args: node_id: Edge node ID ip_address: IP address Returns: True if successful """ try: # Download K3s binary download_cmd = f"curl -sfL https://github.com/k3s-io/k3s/releases/download/v1.28.0/k3s-linux-arm64" subprocess.run(download_cmd, shell=True, check=True) # Install K3s install_cmd = f"chmod +x k3s" subprocess.run(install_cmd, shell=True, check=True) # Start K3s server start_cmd = ( f"./k3s server --docker " f"--no-deploy " f"--write-kubeconfig-mode=644 " f"--disable-network-policy " f"--disable-selinux " f"--disable-traefik" ) subprocess.run(start_cmd, shell=True, check=True) # Register node self.nodes[node_id] = EdgeNode( node_id=node_id, ip_address=ip_address, distribution=K8sDistribution.K3S, version="1.28.0", resources={ "memory_mb": self.max_memory_mb, "max_pods": self.max_pods }, status="active", last_seen=datetime.utcnow() ) logger.info(f"K3s installed on {node_id}") return True except Exception as e: logger.error(f"Failed to install K3s: {e}") return False def _install_k0s(self, node_id: str, ip_address: str) -> bool: """Install K0s distribution.""" try: # Download K0s binary download_cmd = f"curl -sfL https://github.com/k0sproject/k0s/releases/download/v1.29.0/k0s-linux-arm64" subprocess.run(download_cmd, shell=True, check=True) # Install and start K0s install_cmd = f"chmod +x k0s && ./k0s server --disable-traefik" subprocess.run(install_cmd, shell=True, check=True) # Register node self.nodes[node_id] = EdgeNode( node_id=node_id, ip_address=ip_address, distribution=K8sDistribution.K0S, version="1.29.0", resources={ "memory_mb": self.max_memory_mb, "max_pods": self.max_pods }, status="active", last_seen=datetime.utcnow() ) logger.info(f"K0s installed on {node_id}") return True except Exception as e: logger.error(f"Failed to install K0s: {e}") return False def _install_microk8s(self, node_id: str, ip_address: str) -> bool: """Install MicroK8s distribution.""" try: # Download MicroK8s binary download_cmd = f"curl -sfL https://github.com/kubermatic/microk8s/releases/download/v0.22.0/microk8s-linux-arm64" subprocess.run(download_cmd, shell=True, check=True) # Install and start MicroK8s install_cmd = f"chmod +x microk8s && ./microk8s" subprocess.run(install_cmd, shell=True, check=True) # Register node self.nodes[node_id] = EdgeNode( node_id=node_id, ip_address=ip_address, distribution=K8sDistribution.MICROK8S, version="0.22.0", resources={ "memory_mb": self.max_memory_mb, "max_pods": self.max_pods }, status="active", last_seen=datetime.utcnow() ) logger.info(f"MicroK8s installed on {node_id}") return True except Exception as e: logger.error(f"Failed to install MicroK8s: {e}") return False def deploy_pod( self, node_id: str, pod_name: str, image: str, resources: Optional[Dict[str, str]] = None, env_vars: Optional[Dict[str, str]] = None ) -> bool: """ Deploy a pod to edge node. Args: node_id: Edge node ID pod_name: Pod name image: Container image resources: Resource limits env_vars: Environment variables Returns: True if successful """ try: # Create pod manifest manifest = self._create_pod_manifest( pod_name=pod_name, image=image, resources=resources, env_vars=env_vars ) # Apply manifest apply_cmd = f"kubectl apply -f -" subprocess.run(apply_cmd, input=manifest, shell=True, check=True) # Register pod self.pods[f"{node_id}_{pod_name}"] = EdgePod( pod_id=f"{node_id}_{pod_name}", node_id=node_id, name=pod_name, containers=[image], resources=resources or {}, status="pending", created_at=datetime.utcnow() ) logger.info(f"Pod deployed: {pod_name} on {node_id}") return True except Exception as e: logger.error(f"Failed to deploy pod: {e}") return False def _create_pod_manifest( self, pod_name: str, image: str, resources: Optional[Dict[str, str]], env_vars: Optional[Dict[str, str]] ) -> str: """ Create pod manifest. Args: pod_name: Pod name image: Container image resources: Resource limits env_vars: Environment variables Returns: Pod manifest YAML """ manifest = f""" apiVersion: v1 kind: Pod metadata: name: {pod_name} spec: containers: - name: {pod_name} image: {image} resources: limits: memory: {resources.get('memory', '256Mi') if resources else '256Mi'} cpu: {resources.get('cpu', '500m') if resources else '500m'} """ # Add environment variables if env_vars: manifest += " env:\n" for key, value in env_vars.items(): manifest += f" - name: {key}\n" manifest += f" value: \"{value}\"\n" return manifest def sync_to_cloud(self, node_id: str) -> bool: """ Sync edge node to cloud. Args: node_id: Edge node ID Returns: True if successful """ try: if self.edge_mode == EdgeMode.OFFLINE: logger.info(f"Node {node_id} in offline mode, skipping sync") return True # Get node status node = self.nodes.get(node_id) if not node: raise ValueError(f"Node not found: {node_id}") # Sync to cloud management system sync_data = { "node_id": node_id, "distribution": node.distribution.value, "version": node.version, "resources": node.resources, "pods": [ { "pod_id": pod.pod_id, "name": pod.name, "status": pod.status, "created_at": pod.created_at.isoformat() } for pod in self.pods.values() if pod.node_id == node_id ], "timestamp": datetime.utcnow().isoformat() } # Send to cloud API response = requests.post( "https://api.edge.example.com/sync", json=sync_data, timeout=30 ) if response.status_code == 200: node.last_seen = datetime.utcnow() logger.info(f"Node {node_id} synced to cloud") return True else: logger.error(f"Failed to sync {node_id}: {response.status_code}") return False except Exception as e: logger.error(f"Failed to sync node: {e}") return False def get_node_status(self, node_id: str) -> Optional[EdgeNode]: """ Get node status. Args: node_id: Edge node ID Returns: EdgeNode object """ return self.nodes.get(node_id) def get_cluster_status(self) -> Dict[str, Any]: """ Get cluster status. Returns: Cluster status dictionary """ return { "total_nodes": len(self.nodes), "active_nodes": sum(1 for n in self.nodes.values() if n.status == "active"), "total_pods": len(self.pods), "running_pods": sum(1 for p in self.pods.values() if p.status == "running"), "distribution": self.distribution.value, "edge_mode": self.edge_mode.value, "max_memory_mb": self.max_memory_mb, "max_pods": self.max_pods } # Example usage if __name__ == "__main__": # Initialize manager manager = LightweightK8sManager( distribution=K8sDistribution.K3S, edge_mode=EdgeMode.HYBRID, max_memory_mb=512, max_pods=10 ) # Install distribution on edge node success = manager.install_distribution( node_id="edge_node_001", ip_address="192.168.1.100" ) if success: print("Distribution installed successfully") # Deploy a pod manager.deploy_pod( node_id="edge_node_001", pod_name="edge-app", image="nginx:alpine", resources={ "memory": "128Mi", "cpu": "250m" }, env_vars={ "ENV": "production", "REGION": "us-east-1" } ) # Sync to cloud manager.sync_to_cloud("edge_node_001") # Get cluster status status = manager.get_cluster_status() print(f"\nCluster Status:") print(f" Total Nodes: {status['total_nodes']}") print(f" Active Nodes: {status['active_nodes']}") print(f" Total Pods: {status['total_pods']}") print(f" Running Pods: {status['running_pods']}") print(f" Distribution: {status['distribution']}") print(f" Edge Mode: {status['edge_mode']}")
Standards, Compliance & Security
International Standards
- CNCF: Cloud Native Computing Foundation
- OCI: Open Container Initiative
- ISO/IEC 27001: Information security management
- NIST SP 800-193: Container security
Security Protocol
- Container Security: Scan images for vulnerabilities
- Network Isolation: Network policies between pods
- Resource Quotas: Prevent resource exhaustion
- Access Control: RBAC for cluster operations
- Audit Logging: Complete audit trail of operations
Explainability
- Resource Monitoring: Track resource usage per pod
- Health Checks: Pod and node health status
- Logs Aggregation: Centralized log collection
Quick Start
-
Download K3s:
curl -sfL https://github.com/k3s-io/k3s/releases/download/v1.28.0/k3s-linux-arm64 chmod +x k3s -
Start K3s server:
./k3s server --docker --no-deploy --write-kubeconfig-mode=644 -
Deploy pod:
kubectl run nginx --image=nginx:alpine --limits=cpu=250m,memory=128Mi -
Check status:
kubectl get nodes kubectl get pods
Production Checklist
- Distribution selected and tested
- Resource limits configured
- Networking configured
- Storage optimized
- Security policies implemented
- Monitoring and alerting set up
- Backup and recovery procedures
- Offline mode configured
- Cloud sync configured
Anti-patterns
-
Full Kubernetes on Edge: Using standard K8s on constrained devices
- Why it's bad: Too resource-intensive, won't run
- Solution: Use lightweight distributions
-
No Resource Limits: Unlimited resource usage
- Why it's bad: Node instability, crashes
- Solution: Set strict resource quotas
-
No Offline Support: Requires constant connectivity
- Why it's bad: Edge devices often disconnected
- Solution: Implement offline mode and queuing
-
Ignoring Hardware: Not using GPU/NPU when available
- Why it's bad: Wasted acceleration potential
- Solution: Enable hardware acceleration
Unit Economics & KPIs
Cost Calculation
Total Cost = Hardware + Operations + Cloud Management Hardware = (Node Cost × Node Count) / 3 years Operations = (Management Time × Labor Rate) Cloud Management = (API Calls × API Rate) + (Storage × Storage Rate)
Key Performance Indicators
- Node Resource Usage: < 80% of allocated resources
- Pod Success Rate: > 99% of deployments
- Cluster Uptime: > 99.5%
- Sync Success Rate: > 95% of sync operations
- Memory Footprint: < 100MB per node
Integration Points / Related Skills
- Edge Cloud Sync - For cloud-edge synchronization
- Edge AI Acceleration - For hardware acceleration
- Edge Observability - For monitoring
- Edge Security Compliance - For edge security