# rafaelmnatali/kafka-k8s architecture

> Architecture diagram of the GitHub repository rafaelmnatali/kafka-k8s, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rafaelmnatali/kafka-k8s
- Repository: https://github.com/rafaelmnatali/kafka-k8s

## Overview

The project is a tutorial resource that demonstrates how to run Apache Kafka (v3.5.x) on a Kubernetes (Minikube) environment using different security and configuration setups. It covers various deployment configurations including a basic local Confluent installation, Kafka with SSL, Kafka with SASL authentication, and Kafka with SASL along with ACLs.

##### Main components
- Kubernetes Cluster (Minikube): This is the hosting environment.
- Kafka Clusters: There are multiple variants shown by the directories – confluent-local, ssl, sasl, and acls. Each variant represents a different deployment configuration.
- Configuration Resources: YAML files (e.g., 00-namespace.yaml, 01-kafka.yaml, and 02-kafka-client.yaml) that are used to provision the necessary Kubernetes objects for each Kafka variant.
- Scripts: Additional automation such as the kafka-reassign.sh script, which interacts with Kafka’s internal management (like partition reassignments).

##### Relationships and interactions
- The Kubernetes cluster hosts all deployments. Within this cluster, different namespaces or sets of resources are configured using the provided YAML files.
- Each deployment variant (e.g., Kafka with SSL or SASL) can be visualized as a branch that includes both Kafka server configuration and its corresponding client configuration (often separated into files like 01-kafka.yaml and 02-kafka-client.yaml).
- Security-related configurations (SSL properties, SASL properties, ACL definitions) are applied to the respective Kafka variants. For example, the “sasl” and “acls” folders show how SASL authentication and ACLs are layered on top of a basic Kafka deployment.
- The “confluent-local” directory represents a standard, non-secured deployment scenario with possible additional local configurations.

##### Important architectural patterns
- Configuration as Code: Using YAML files to define the namespaces and Kafka resources is a core principle here.
- Environment-specific Deployment: The separation into distinct directories indicates an architecture that is modular, allowing you to swap between different security setups (SSL, SASL, ACLs). This modularity could be represented as isolated “deployment stacks” within the same overall Kubernetes environment.
- Script-driven management: The provided shell script in the “scripts” directory demonstrates operational management (e.g., reassigning partitions), indicating a separation between deployment configuration and administrative operations.

##### Relevant technologies and frameworks
- Kubernetes (via Minikube) as the container orchestration platform.
- Apache Kafka (with its KRaft consensus protocol) as the messaging backbone.
- Confluent components for rapid setup in the local mode.
- Security technologies like SSL certificates and SASL mechanisms used in securing Kafka clusters.
- YAML configuration files to define runtime components.

##### Elements
- Clear labels for every component (e.g., “Kubernetes Cluster”, “Confluent-Local Kafka Deployment”, “Kafka with SSL”, etc.).
- Rectangles for infrastructure components (Kubernetes Cluster, Kafka brokers).

##### Conclusion

This detailed approach will help a principal software engineer quickly grasp the architectural layout of the repository and understand how each component fits into the overall Kafka on Kubernetes environment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Kubernetes Cluster
    subgraph "Minikube-based Kubernetes Cluster"
        %% Confluent-Local Kafka Deployment
        subgraph "Confluent-Local Kafka Deployment"
            CL_NS["Namespace: 00-namespace.yaml"]:::config
            CL_KAFKA["Kafka Broker: 01-kafka-local.yaml"]:::kafka
            CL_NS -->|"creates"| CL_KAFKA
        end

        %% Kafka with SSL Deployment
        subgraph "Kafka with SSL Deployment"
            SSL_NS["Namespace: 00-namespace.yaml"]:::config
            SSL_KAFKA["Kafka Broker: 01-kafka.yaml"]:::kafka
            SSL_CLIENT["Kafka Client: 02-kafka-client.yaml"]:::client
            SSL_NS -->|"creates"| SSL_KAFKA
            SSL_NS -->|"creates"| SSL_CLIENT
        end

        %% Kafka with SASL Deployment
        subgraph "Kafka with SASL Deployment"
            SASL_NS["Namespace: 00-namespace.yaml"]:::config
            SASL_KAFKA["Kafka Broker: 01-kafka.yaml"]:::kafka
            SASL_CLIENT["Kafka Client: 02-kafka-client.yaml"]:::client
            SASL_SASL["SASL Client: sasl_client.properties"]:::security
            SASL_NS -->|"creates"| SASL_KAFKA
            SASL_NS -->|"creates"| SASL_CLIENT
            SASL_CLIENT -->|"configures"| SASL_SASL
        end

        %% Kafka with SASL and ACLs Deployment
        subgraph "Kafka with SASL and ACLs Deployment"
            ACLS_NS["Namespace: 00-namespace.yaml"]:::config
            ACLS_KAFKA["Kafka Broker: 01-kafka.yaml"]:::kafka
            ACLS_CLIENT["Kafka Client: 02-kafka-client.yaml"]:::client
            ACLS_ADMIN["Kafka Admin: 03-kafka-admin.yaml"]:::kafka
            ACLS_SASL_CLIENT["SASL Client: sasl_client.properties"]:::security
            ACLS_SASL_ADMIN["SASL Admin: sasl_admin.properties"]:::security
            ACLS_NS -->|"creates"| ACLS_KAFKA
            ACLS_NS -->|"creates"| ACLS_CLIENT
            ACLS_NS -->|"creates"| ACLS_ADMIN
            ACLS_CLIENT -->|"configures"| ACLS_SASL_CLIENT
            ACLS_ADMIN -->|"configures"| ACLS_SASL_ADMIN
        end
    end

    %% Operational Scripts
    OPS["Operational Scripts: kafka-reassign.sh"]:::script

    %% Script interactions with Kafka Broker in each deployment
    OPS -->|"manages"| CL_KAFKA
    OPS -->|"manages"| SSL_KAFKA
    OPS -->|"manages"| SASL_KAFKA
    OPS -->|"manages"| ACLS_KAFKA

    %% Click Events for Confluent-Local Deployment
    click CL_NS "https://github.com/rafaelmnatali/kafka-k8s/blob/main/confluent-local/00-namespace.yaml"
    click CL_KAFKA "https://github.com/rafaelmnatali/kafka-k8s/blob/main/confluent-local/01-kafka-local.yaml"

    %% Click Events for Kafka with SSL Deployment
    click SSL_NS "https://github.com/rafaelmnatali/kafka-k8s/blob/main/ssl/00-namespace.yaml"
    click SSL_KAFKA "https://github.com/rafaelmnatali/kafka-k8s/blob/main/ssl/01-kafka.yaml"
    click SSL_CLIENT "https://github.com/rafaelmnatali/kafka-k8s/blob/main/ssl/02-kafka-client.yaml"

    %% Click Events for Kafka with SASL Deployment
    click SASL_NS "https://github.com/rafaelmnatali/kafka-k8s/blob/main/sasl/00-namespace.yaml"
    click SASL_KAFKA "https://github.com/rafaelmnatali/kafka-k8s/blob/main/sasl/01-kafka.yaml"
    click SASL_CLIENT "https://github.com/rafaelmnatali/kafka-k8s/blob/main/sasl/02-kafka-client.yaml"
    click SASL_SASL "https://github.com/rafaelmnatali/kafka-k8s/blob/main/sasl/sasl_client.properties"

    %% Click Events for Kafka with SASL and ACLs Deployment
    click ACLS_NS "https://github.com/rafaelmnatali/kafka-k8s/blob/main/acls/00-namespace.yaml"
    click ACLS_KAFKA "https://github.com/rafaelmnatali/kafka-k8s/blob/main/acls/01-kafka.yaml"
    click ACLS_CLIENT "https://github.com/rafaelmnatali/kafka-k8s/blob/main/acls/02-kafka-client.yaml"
    click ACLS_ADMIN "https://github.com/rafaelmnatali/kafka-k8s/blob/main/acls/03-kafka-admin.yaml"
    click ACLS_SASL_CLIENT "https://github.com/rafaelmnatali/kafka-k8s/blob/main/acls/sasl_client.properties"
    click ACLS_SASL_ADMIN "https://github.com/rafaelmnatali/kafka-k8s/blob/main/acls/sasl_admin.properties"

    %% Click Event for Operational Script
    click OPS "https://github.com/rafaelmnatali/kafka-k8s/blob/main/scripts/kafka-reassign.sh"

    %% Styling classes with colors
    classDef config fill:#cfe2f3,stroke:#2e6da4,stroke-width:2px;
    classDef kafka fill:#f3e2c7,stroke:#d58512,stroke-width:2px;
    classDef client fill:#dff0d8,stroke:#3c763d,stroke-width:2px;
    classDef security fill:#fae3e3,stroke:#a94442,stroke-width:2px;
    classDef script fill:#f7f8e0,stroke:#8a6d3b,stroke-width:2px;
```
