Skip to content
/ pak-rt Public

🏘️ Educational container runtime implementation using Linux namespaces and cgroups

Notifications You must be signed in to change notification settings

tonidy/pak-rt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

80 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

RT Container Runtime

🏘️ Educational container runtime implementation using Linux namespaces and cgroups

RT (Rukun Tetangga) adalah bash script container runtime yang dibuat untuk memahami bagaimana container bekerja di level sistem operasi. Script ini menggunakan analogi RT di dalam perumahan untuk menjelaskan konsep-konsep container technology dengan cara yang mudah dipahami.

🌟 Features

  • βœ… Linux Namespace Management - PID, Mount, UTS, IPC, User, Network isolation
  • βœ… Cgroup Resource Management - Memory dan CPU limiting dengan monitoring
  • βœ… Container-to-Container Networking - Direct communication tanpa host routing
  • βœ… Busybox Integration - Lightweight container base dengan static binary
  • βœ… Educational Output - Step-by-step explanations dengan analogi perumahan
  • βœ… Comprehensive Error Handling - Recovery mechanisms dan troubleshooting
  • βœ… Security Features - Input sanitization dan privilege management
  • βœ… Docker Compose Development - Easy setup untuk macOS developers

πŸš€ Quick Start

Prerequisites

  • macOS dengan Docker Desktop installed
  • Docker Compose (included dengan Docker Desktop)
  • Git untuk cloning repository

Development Setup

# Clone repository
git clone <repository-url>
cd pak-rt

# Setup development environment
make setup

# Start development container (Linux environment)
make dev

# Dalam development container, test basic functionality
./rt.sh create rumah-a --ram=512 --cpu=50
./rt.sh list
./rt.sh run rumah-a
./rt.sh delete rumah-a

Basic Usage Examples

# Create container dengan resource limits
./rt.sh create rumah-jakarta --ram=256 --cpu=25

# List semua containers dengan status
./rt.sh list

# Run container dengan interactive shell
./rt.sh run rumah-jakarta

# Create multiple containers untuk networking test
./rt.sh create rumah-bandung --ram=512 --cpu=50
./rt.sh create rumah-surabaya --ram=256 --cpu=30

# Test container-to communication
./rt.sh run rumah-bandung
# Dalam container: ping 10.0.0.3 (IP rumah-surabaya)

# Cleanup containers
./rt.sh delete rumah-jakarta
./rt.sh cleanup-all  # Delete semua containers

πŸ› οΈ Development Commands

Command Description Analogi RT
make setup Setup development environment Menyiapkan kantor RT
make dev Start interactive development container Masuk ke kantor RT
make test Run all tests dalam Linux environment Tes semua sistem kompleks
make test-unit Run unit tests only Tes komponen individual
make test-integration Run integration tests Tes integrasi antar sistem
make test-network Run network connectivity tests Tes sambungan telepon antar rumah
make test-stress Run stress tests Tes beban maksimal kompleks
make clean Cleanup containers dan volumes Bersih-bersih kantor RT

Demo Scenarios

Command Description Analogi RT
make demo Show available demo scenarios Lihat demo yang tersedia
make demo-basic Basic container lifecycle demo Demo dasar kelola rumah
make demo-namespace Namespace isolation demo Demo isolasi antar rumah
make demo-resources Resource management demo Demo pembagian listrik
make demo-network Container networking demo Demo telepon antar rumah
make demo-multi Multi application demo Demo kompleks lengkap
make demo-tour Complete educational tour Tur lengkap kompleks
make demo-all Run all demo scenarios Jalankan semua demo

Advanced Testing Commands

# Test specific components
make test-busybox      # Test busybox management
make test-namespace    # Test namespace isolation
make test-cgroup       # Test resource limiting
make test-network      # Test container networking

# Performance and reliability tests
make test-stress       # Concurrent operations test
make test-resources    # Resource validation test
make test-cleanup      # Cleanup verification test

πŸ“ Project Structure

pak-rt/
β”œβ”€β”€ rt.sh                           # 🏠 Main RT script (Rukun Tetangga)
β”œβ”€β”€ demo-scenarios.sh               # 🎬 Educational demo scenarios
β”œβ”€β”€ Makefile                        # πŸ”§ Development commands untuk macOS
β”œβ”€β”€ docker-compose.yml              # 🐳 Linux development environment
β”œβ”€β”€ Dockerfile.dev                  # πŸ“¦ Development container setup
β”œβ”€β”€ README.md                       # πŸ“– This documentation
β”œβ”€β”€ docs/                          # πŸ“š Additional documentation
β”‚   β”œβ”€β”€ README.md                  # Project overview
β”‚   β”œβ”€β”€ ANALOGY.md                 # 🏘️ Detailed housing analogy
β”‚   β”œβ”€β”€ TROUBLESHOOTING.md         # πŸ” Common issues dan solutions
β”‚   β”œβ”€β”€ SECURITY.md                # πŸ”’ Security considerations
β”‚   └── TESTING.md                 # πŸ§ͺ Testing methodology
└── tests/                         # πŸ§ͺ Comprehensive test suite
    β”œβ”€β”€ run-all-tests.sh           # Main test runner
    β”œβ”€β”€ unit-tests.sh              # Unit tests
    β”œβ”€β”€ integration-tests.sh       # Integration tests
    β”œβ”€β”€ busybox-tests.sh           # Busybox management tests
    β”œβ”€β”€ namespace-tests.sh         # Namespace isolation tests
    β”œβ”€β”€ cgroup-tests.sh            # Resource management tests
    β”œβ”€β”€ network-tests.sh           # Network connectivity tests
    β”œβ”€β”€ security-tests.sh          # Security feature tests
    β”œβ”€β”€ stress-tests.sh            # Performance stress tests
    β”œβ”€β”€ resource-validation-tests.sh # Resource limiting tests
    └── cleanup-verification-tests.sh # Cleanup verification tests

🏘️ Educational Analogy

RT menggunakan analogi perumahan untuk menjelaskan konsep container technology:

Konsep Dasar

  • 🏘️ Host System = Kompleks Perumahan yang dikelola RT
  • 🏠 Container = Rumah Individual dengan penghuni
  • πŸ‘¨ PID 1 (busybox) = Ayah sebagai kepala keluarga (nomor 1 di rumah)
  • πŸ‘© Shell Process = Ibu yang mengelola aktivitas rumah
  • πŸ‘¦πŸ‘§ Child Processes = Anak-anak dalam keluarga

Namespace Isolation

  • PID Namespace: Setiap rumah punya penomoran sendiri, Ayah selalu nomor 1
  • Network Namespace: Setiap rumah punya telepon internal, bisa nelpon rumah lain
  • Mount Namespace: Setiap rumah punya rak buku sendiri, tidak bisa lihat rak tetangga
  • UTS Namespace: Setiap rumah punya nama sendiri (hostname)
  • IPC Namespace: Setiap rumah punya papan tulis keluarga sendiri
  • User Namespace: Ayah di rumah A berbeda dengan Ayah di rumah B

Resource Management

  • πŸ’‘ Memory Limit = Kuota listrik bulanan untuk setiap rumah
  • ⚑ CPU Limit = Pembagian daya listrik yang adil
  • πŸ“Š Resource Monitoring = Tagihan listrik dan air real-time
  • 🚨 Resource Alerts = Peringatan jika mendekati batas kuota

Network Communication

  • πŸ“ž Container-to-Container = Telepon langsung antar rumah
  • 🌐 Host Network = Telepon umum kompleks untuk internet
  • πŸ”Œ veth pairs = Kabel telepon yang menghubungkan rumah
  • πŸ“ IP Addresses = Nomor telepon setiap rumah (10.0.0.x)

🎬 Demo Scenarios

RT Container Runtime menyediakan demo scenarios yang interaktif untuk pembelajaran:

Quick Demo

# Start development environment
make dev

# Run basic demo
make demo-basic

# Run complete educational tour
make demo-tour

# Run all demos
make demo-all

Available Demo Scenarios

  1. Basic Lifecycle (make demo-basic)

    • Container creation, running, dan deletion
    • Seperti RT yang menunjukkan siklus hidup rumah
  2. Namespace Isolation (make demo-namespace)

    • PID dan Mount namespace demonstration
    • Seperti RT yang menunjukkan isolasi antar rumah
  3. Resource Management (make demo-resources)

    • Memory dan CPU limiting
    • Seperti RT yang menunjukkan pembagian listrik
  4. Container Networking (make demo-network)

    • Container-to communication
    • Seperti RT yang menunjukkan sistem telepon
  5. Multi-Container (make demo-multi)

    • Multiple containers working together
    • Seperti RT yang mengelola kompleks lengkap
  6. Educational Tour (make demo-tour)

    • Complete guided tour of all features
    • Seperti RT yang memberikan tur lengkap kompleks

🎯 Use Cases

1. Learning Container Technology

# Understand namespace isolation
./rt.sh create belajar-namespace --ram=128 --cpu=25
./rt.sh run belajar-namespace
# Dalam container: ps aux  # Lihat PID isolation
# Dalam container: mount   # Lihat filesystem isolation

2. Network Learning

# Create multiple containers untuk network testing
./rt.sh create server --ram=256 --cpu=30
./rt.sh create client --ram=128 --cpu=20

# Test direct container communication
./rt.sh run server
# Dalam server: nc -l -p 8080  # Start simple server

# Dari container lain
./rt.sh run client
# Dalam client: nc 10.0.0.2 8080  # Connect ke server

3. Resource Management Learning

# Create container dengan memory limit
./rt.sh create memory-test --ram=64 --cpu=10

# Monitor resource usage
./rt.sh run memory-test
# Dalam container: stress --vm 1 --vm-bytes 100M  # Test memory limit

πŸ”§ Advanced Configuration

Environment Variables

# Enable verbose educational output
export VERBOSE_MODE=true
./rt.sh create verbose-demo --ram=256 --cpu=25

# Enable debug mode untuk detailed system information
export DEBUG_MODE=true
./rt.sh list

# Enable resource monitoring
export MONITORING_ENABLED=true
./rt.sh run monitoring-demo

Custom Resource Limits

# High-performance container
./rt.sh create high-perf --ram=1024 --cpu=80

# Minimal resource container
./rt.sh create minimal --ram=64 --cpu=5

# Balanced container
./rt.sh create balanced --ram=512 --cpu=50

πŸ§ͺ Testing and Validation

Running Tests

# Full test suite (requires Linux environment)
make test

# Quick validation
make test-unit

# Network functionality test
make test-network

# Performance validation
make test-stress

Manual Testing Scenarios

# Scenario 1: Basic container lifecycle
./rt.sh create test1 --ram=256 --cpu=25
./rt.sh list
./rt.sh run test1
./rt.sh delete test1

# Scenario 2: Multi networking
./rt.sh create web --ram=512 --cpu=50
./rt.sh create db --ram=256 --cpu=30
# Test ping between containers

# Scenario 3: Resource limiting
./rt.sh create limited --ram=128 --cpu=10
# Monitor resource usage dalam container

πŸ” Troubleshooting

Common Issues

  1. Permission Denied

    # Ensure running dalam Docker container dengan privileged mode
    make dev
  2. Container Creation Fails

    # Check system resources
    ./rt.sh debug system
    
    # Verify busybox availability
    ./rt.sh debug busybox
  3. Network Issues

    # Check network configuration
    ./rt.sh debug network
    
    # Cleanup orphaned network interfaces
    ./rt.sh cleanup-all

Debug Commands

# System information
./rt.sh debug system

# Container status
./rt.sh debug containers

# Network topology
./rt.sh debug network

# Resource usage
./rt.sh debug resources

# Recovery from corrupted state
./rt.sh recover-state

πŸ“š Documentation

🀝 Contributing

  1. Fork repository
  2. Create feature branch: git checkout -b feature/amazing-feature
  3. Make changes dalam development container: make dev
  4. Run tests: make test
  5. Commit changes: git commit -m 'Add amazing feature'
  6. Push to branch: git push origin feature/amazing-feature
  7. Submit pull request

Development Guidelines

  • Follow bash scripting best practices
  • Add educational analogies untuk new features
  • Include comprehensive error handling
  • Write tests untuk new functionality
  • Update documentation accordingly

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

  • Linux kernel developers untuk namespace dan cgroup features
  • Busybox project untuk lightweight container base
  • Docker community untuk container technology inspiration
  • Indonesian RT system untuk educational analogy inspiration

🏠 Seperti RT yang melayani warga kompleks, script ini melayani developer yang ingin memahami container technology dengan cara yang mudah dan menyenangkan!

About

🏘️ Educational container runtime implementation using Linux namespaces and cgroups

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published