Skip to content

Probando redlock como semáforo para cronjobs configurados en software

License

Notifications You must be signed in to change notification settings

diekotto/redlock-k8s-laboratory

Repository files navigation

REDLOCK-K8S-LABORATORY

Orchestrating distributed locks, reliably and efficiently.

license last-commit repo-top-language repo-language-count

Built with the tools and technologies:

npm Redis JavaScript GNU%20Bash Yarn Docker


🔗 Table of Contents


📍 Overview

redlock-k8s-laboratory showcases a scalable microservices architecture using Kubernetes, Redis, and Node.js. It demonstrates distributed locking and task scheduling, enabling efficient processing of concurrent jobs. The project provides a foundation for building robust, fault-tolerant systems that can handle high-volume workloads. Ideal for developers and DevOps professionals seeking best practices for containerized application design.


👾 Features

Feature Summary
⚙️ Architecture
  • Microservices architecture with web-server, cron-service, and Redis components
  • Containerization using Docker for consistent runtime environments
  • Orchestration and deployment using Kubernetes for scalability and reliability
🔩 Code Quality
  • Modular and organized codebase structure
  • Use of popular and well-maintained libraries and frameworks (Express, ioredis, cron)
  • Consistent coding style and naming conventions
📄 Documentation
  • Comprehensive README.md file providing project overview and setup instructions
  • Well-commented code explaining key functionalities and logic
  • Clear and concise Dockerfile and package.json files for each component
🔌 Integrations
  • Integration with Redis for distributed locking and data persistence
  • Communication between web-server and cron-service components
  • Seamless local development and testing using Minikube's Docker daemon
🧩 Modularity
  • Separation of concerns between web-server, cron-service, and Redis components
  • Reusable and maintainable code modules (main.js, Dockerfile, package.json)
  • Loose coupling between components through well-defined interfaces and communication channels
🧪 Testing
  • Automated build and deployment processes using Docker Compose and Kubernetes
  • Real-time monitoring and logging of web-server and Redis components
  • Streamlined development workflow with Minikube integration for local testing
⚡️ Performance
  • Efficient handling of HTTP requests and message processing in the web-server
  • Optimized task execution and retry logic in the cron-service
  • Utilization of Redis for fast in-memory data storage and retrieval
🛡️ Security
  • Containerization provides isolation and security between components
  • Secure communication between components using environment variables for configuration
  • Potential for implementing authentication and authorization mechanisms

📁 Project Structure

└── redlock-k8s-laboratory/
    ├── LICENSE
    ├── README.md
    ├── commands
    │   ├── build-into-registry.sh
    │   ├── log-redis.sh
    │   └── log-web.sh
    ├── cron-service
    │   ├── .gitignore
    │   ├── Dockerfile
    │   ├── main.js
    │   ├── package.json
    │   └── yarn.lock
    ├── deployment-cron-service.k8s.yaml
    ├── deployment-redis.k8s.yaml
    ├── deployment-web-server.k8s.yaml
    ├── docker-compose.yml
    ├── package.json
    └── web-server
        ├── .gitignore
        ├── Dockerfile
        ├── main.js
        ├── package.json
        └── yarn.lock

📂 Project Index

REDLOCK-K8S-LABORATORY/
__root__
deployment-redis.k8s.yaml - Configures a Redis deployment and service in a Kubernetes cluster
- The deployment spins up a single Redis container, exposing port 6379
- The accompanying service enables network access to the Redis instance, allowing other components to store and retrieve data
- Redis acts as an in-memory data store, providing fast caching and persistence capabilities to the application.
deployment-web-server.k8s.yaml - Defines a Kubernetes deployment and service for the web server component
- The deployment manages a single replica of the web server container, specifying the container image and port
- The service exposes the web server externally, routing traffic to the appropriate pod
- Together, they enable reliable deployment and access to the web server within the Kubernetes cluster architecture.
docker-compose.yml - Orchestrates the deployment of a multi-service architecture using Docker Compose
- Defines three services: a web server, a cron service, and Redis
- The web server and cron service are built from custom images, while Redis uses the official image
- Environment variables are set for each service, and the cron service depends on the web server and Redis.
deployment-cron-service.k8s.yaml - Configures a Kubernetes deployment for the cron service in the Redlock Laboratory project
- Sets up 5 replicas of the cron service container, specifying the container image and environment variables for connecting to the web server and Redis services
- Ensures high availability and scalability of the cron service within the project's microservices architecture.
package.json - Configures the project's build, deployment, and logging processes
- Defines scripts for starting the application, building Docker images, and managing containers using Docker Compose
- Includes commands for deploying and removing Kubernetes resources
- Provides convenient scripts for accessing logs of the web server and Redis components, streamlining development and troubleshooting tasks.
web-server
Dockerfile - Dockerfile sets up a Node.js environment for the web server component of the project
- It installs dependencies, copies the necessary files, and specifies the command to run the main server script
- The Dockerfile enables building a containerized version of the web server, facilitating deployment and ensuring a consistent runtime environment across different systems.
package.json - Manages dependencies and metadata for the web server component of the project
- Specifies the required third-party libraries, including Express for handling HTTP requests, body-parser for parsing request bodies, and Luxon for date and time manipulation
- Defines the entry point of the web server and sets the license under which the package is distributed.
main.js - Serves as the main entry point for the web server, handling HTTP requests and managing application state
- Exposes endpoints for receiving and processing messages, tracking data in memory based on message content
- Facilitates communication between system components and provides a centralized location for monitoring and controlling the application's behavior.
commands
build-into-registry.sh - Builds Docker images within the Minikube environment, enabling seamless local development and testing
- By leveraging Minikube's Docker daemon, the script eliminates the need to push images to a remote registry, streamlining the development workflow
- This integration allows for efficient iteration and debugging of containerized applications before deploying to production environments.
log-redis.sh - Enables real-time monitoring of Redis keys in a Kubernetes cluster
- Retrieves the name of the Redis pod using kubectl, then continuously displays the keys stored in the Redis database using the redis-cli command
- Facilitates observing changes to Redis data without manually connecting to the pod, aiding in debugging and understanding the application's runtime state.
log-web.sh - Enables viewing real-time logs for the web component in a Kubernetes cluster
- Retrieves the pod name associated with the web service using kubectl and the grep command
- Utilizes the kubectl logs command with the -f flag to stream the logs of the identified web pod, facilitating continuous monitoring and troubleshooting of the web component within the project's architecture.
cron-service
Dockerfile - Dockerfile sets up the environment for running the cron-service, a component of the project's architecture
- It installs dependencies, copies the necessary files, and specifies the command to start the service
- The cron-service likely performs scheduled tasks or background jobs, contributing to the overall functionality and automation within the project.
package.json - package.json defines dependencies and metadata for the cron-service, a component of the project's architecture
- It specifies the required libraries, such as ioredis for Redis interaction, cron for scheduling tasks, and luxon for date/time handling
- The file also includes development dependencies and identifies the entry point of the cron-service module.
main.js - Serves as the cron service for the project architecture, executing scheduled tasks at regular intervals
- Utilizes Redis for distributed locking and list management
- Communicates with the web server to send task-related messages
- Ensures tasks are processed efficiently and reliably by implementing retry logic and random sleep intervals between task executions.

🚀 Getting Started

☑️ Prerequisites

Before getting started with redlock-k8s-laboratory, ensure your runtime environment meets the following requirements:

  • Programming Language: Error detecting primary_language: {'yaml': 3, 'yml': 1, 'json': 3, 'lock': 2, 'js': 2, 'sh': 3}
  • Package Manager: Npm, Yarn
  • Container Runtime: Docker

⚙️ Installation

Install redlock-k8s-laboratory using one of the following methods:

Build from source:

  1. Clone the redlock-k8s-laboratory repository:
❯ git clone https://github.com/diekotto/redlock-k8s-laboratory
  1. Navigate to the project directory:
cd redlock-k8s-laboratory
  1. Install the project dependencies:

Using npm  

echo 'INSERT-INSTALL-COMMAND-HERE'

Using yarn  

echo 'INSERT-INSTALL-COMMAND-HERE'

Using docker  

❯ docker build -t diekotto/redlock-k8s-laboratory .

🤖 Usage

Run redlock-k8s-laboratory using the following command: Using npm  

echo 'INSERT-RUN-COMMAND-HERE'

Using yarn  

echo 'INSERT-RUN-COMMAND-HERE'

Using docker  

❯ docker run -it {image_name}

🧪 Testing

Run the test suite using the following command: Using npm  

echo 'INSERT-TEST-COMMAND-HERE'

Using yarn  

echo 'INSERT-TEST-COMMAND-HERE'

📌 Project Roadmap

  • Task 1: Implement feature one.
  • Task 2: Implement feature two.
  • Task 3: Implement feature three.

🔰 Contributing

Contributing Guidelines
  1. Fork the Repository: Start by forking the project repository to your github account.
  2. Clone Locally: Clone the forked repository to your local machine using a git client.
    git clone https://github.com/diekotto/redlock-k8s-laboratory
  3. Create a New Branch: Always work on a new branch, giving it a descriptive name.
    git checkout -b new-feature-x
  4. Make Your Changes: Develop and test your changes locally.
  5. Commit Your Changes: Commit with a clear message describing your updates.
    git commit -m 'Implemented new feature x.'
  6. Push to github: Push the changes to your forked repository.
    git push origin new-feature-x
  7. Submit a Pull Request: Create a PR against the original project repository. Clearly describe the changes and their motivations.
  8. Review: Once your PR is reviewed and approved, it will be merged into the main branch. Congratulations on your contribution!
Contributor Graph


🎗 License

This project is protected under the SELECT-A-LICENSE License. For more details, refer to the LICENSE file.


🙌 Acknowledgments

  • List any resources, contributors, inspiration, etc. here.

About

Probando redlock como semáforo para cronjobs configurados en software

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published