Skip to main content

Log Generator Setup Guide

This guide provides instructions to set up a Python-based log generator using Docker and Kubernetes. The log generator randomly outputs log messages with different severity levels, which is helpful for testing log collection, monitoring setups, and more.

Table of Contents


Requirements

  • Docker installed locally
  • Kubernetes cluster setup (e.g., minikube, EKS, etc.)
  • kubectl command-line tool configured to communicate with the Kubernetes cluster

Step 1: Docker Setup

Make sure Docker is installed on your machine. Verify the installation by running:

Step 2: Python Log Generator Script

Create a Python file named log_generator.py with the following content. This script generates log messages at random intervals with varying log levels.

Step 3: Dockerfile

Create a Dockerfile to containerize the Python log generator application.

Step 4: Build and Push Docker Image

Build and push the Docker image to a registry, such as Docker Hub or GitHub Container Registry.
Replace USERNAME with your Docker Hub or registry username.

Step 5: Kubernetes Deployment

Create a Kubernetes deployment file, log-generator-deployment.yaml, to deploy the application to the Kubernetes cluster.
Apply the deployment file:

Step 6: Kubernetes Service

Create a service file, log-generator-service.yaml, to expose the application within or outside the cluster.
Apply the service file:

Verifying Deployment

  1. Confirm the pods are running:
  2. Confirm the service is exposed:
Access logs by viewing the pod logs:
Replace <pod-name> with the actual pod name listed from the kubectl get pods command.