Skip to content

Repository files navigation

System Testing Guide

This guide explains how to set up, test, and visualize the system that integrates with Kubernetes, processes resources, and visualizes relationships between them as a graph.

Overview

The system connects to a Kubernetes cluster to:

  1. Fetch resources, such as Pods, Deployments, Services, and ConfigMaps.
  2. Construct relationships between resources (e.g., Deployments managing Pods, Services targeting Pods).
  3. Generate a graph representation as a versioned JSON output.
  4. Visualize the relationships using a graph tool.

Testing this system involves:

  • Setting up a Kubernetes cluster.
  • Running the system.
  • Adding and modifying Kubernetes resources within the cluster.
  • Visualizing and validating the graph.

Prerequisites

1. Environment Setup

  • Python: 3.8+ installed.
  • Install required Python dependencies with:
  pip install -r requirements.txt

2. Kubernetes Setup

3. Start Minikube

Run the following command to start the Minikube Kubernetes cluster:

minikube start

Verify that the cluster is running:

kubectl get nodes

Testing Steps

Step 1: Run the System

  1. Navigate to your project’s directory.
  2. Run the main system script:
   python main.py

What happens:

  1. The system sets up the Kubernetes API client and initializes its database.
  2. It fetches all existing Kubernetes resources and their relationships.
  3. The system generates a versioned graph file in the graph_output directory and monitors the cluster for any dynamic changes.

Step 2: Add Resources to the Cluster

Manually add Kubernetes resources by creating and applying YAML files.

Example 1: Add a Deployment

  1. Create a deployment to run an Nginx container.
  2. Save the YAML to a file (e.g., nginx-deployment.yaml) and apply it:
   kubectl apply -f nginx-deployment.yaml

Example 2: Add a ConfigMap

  1. Write a configuration file as a ConfigMap.
  2. Apply it:
   kubectl apply -f example-configmap.yaml

Example 3: Add a Service

  1. Create a service to expose a Deployment (or Pods).
  2. Apply it to the cluster:
   kubectl apply -f nginx-service.yaml

Expected Outcome: The system’s watcher will detect the newly added resources, update the database, and generate an updated graph in the graph_output directory.

Step 3: Visualize the Graph

  1. Open the latest graph file in the graph_output directory (e.g., graph_OUTPUT_<timestamp>.json).
  2. Use a graph visualization script or external tools to render the graph.

Using a Graphing Tool

Run the relationship_visualizer.py script:

python relationship_visualizer.py

What happens:

  • The emitted graph file is read and visualized.
  • Nodes represent Kubernetes resources (e.g., Pods, Deployments) with color coding by resource type.
  • Edges represent the relationships (e.g., a Deployment controlling Pods).

Step 4: Test Dynamic Updates

  1. Modify or scale an existing resource to test dynamic behavior:
    • Scale a Deployment:
     kubectl scale deployment nginx-deployment --replicas=5
  • Modify or Add a ConfigMap: Create and apply:
     kubectl apply -f another-configmap.yaml
  1. Check the graph_output directory for the updated graph output. The relationships and newly added resources should now appear.

Expected Results

Initial Run

  • A graph is generated containing all current Kubernetes resources and their relationships.

Adding Resources

  • New resources (e.g., deployments, services, ConfigMaps) are detected and added as nodes in the graph.
  • Relationships between resources (e.g., Service → Pod) are updated.

Dynamic Updates

  • Changes to resources (e.g., scaling replicas or creating additional resources) are reflected in a new version of the graph output.

Visualization

  • Graph renders with:
    • Nodes color-coded based on resource type (Pods, Deployments, Services, etc.).
    • Edges representing the relationships.

About

A lightweight k8s agent that records resource meta and relationships.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages