# cloudwithvarjosh/tls-in-kubernetes-masterclass architecture

> Architecture diagram of the GitHub repository cloudwithvarjosh/tls-in-kubernetes-masterclass, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cloudwithvarjosh/tls-in-kubernetes-masterclass
- Repository: https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass

## Overview

##### Project Type and Purpose
- This repository is **not** an application codebase but a **training/reference project** that explains **TLS/mTLS in Kubernetes**.
- Its goal is to **teach** how Kubernetes components (kubectl, API server, etcd, scheduler, kubelet) use **asymmetric and symmetric encryption**, **certificate authorities**, **kubeconfig**, and **RBAC** to secure in-cluster communication and external access.

##### Main Components
a. Certificate Authorities (CAs)
- **Cluster Root CA** (signs API server, scheduler, controller-manager certs)
- **etcd-CA** (signs etcd server and apiserver-etcd-client certs)
- **External/Public CA** (e.g., Let's Encrypt) for ingress (optional)
b. Clients
- **kubectl** (human user Seema)
- **kube-scheduler**, **kube-controller-manager**, **kube-proxy**
- **API server** when it acts as a client to etcd and kubelet
c. Servers
- **kube-apiserver** (serves API, validates client certs)
- **etcd** (persistent store, serves data to API server)
- **kubelet** (node agent, serves logs/exec endpoints)
d. User and External Access
- **Seema’s workstation** with kubeconfig, CSR flow, certificate issuance, RBAC

##### Relationships and Interactions
- **One-way TLS**: kubectl → API server (server authenticates via `apiserver.crt`)
- **mTLS**:
- Scheduler → API server
- Controller-manager → API server
- API server → etcd
- API server → kubelet
- **CSR Flow** for external user:
- User → CSR → API server → Approval → Signed certificate → kubeconfig

##### Architectural Patterns and Principles
- **PKI Model**: Root CA signs intermediate CAs and component certificates
- **Mutual TLS**: Both client and server present certs for authentication
- **Layered Security**:
- Control Plane (API server, scheduler, controller) uses cluster CA
- etcd uses dedicated etcd-CA
- Node services (kubelet) use TLS bootstrapping and NodeRestriction
- **Separation of Concerns**: Each component has its own key pair and kubeconfig

##### Technologies, Frameworks, Libraries
- **Kubernetes** core components: kube-apiserver, etcd, kubelet, scheduler, controller-manager, kube-proxy
- **TLS/OpenSSL** for certificates and CRLs
- **kubectl & kubeconfig** for user-to-cluster authentication
- **RBAC** API to bind certificates to users/namespaces
- **CertificateSigningRequest** Kubernetes API

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and CSR Flow
    subgraph "User Access"
        direction TB
        Seema["Seema’s Workstation"]:::user
        CSR["CertificateSigningRequest API"]:::api
        Kubeconfig["kubeconfig"]:::client
    end

    Seema -->|“submit CSR”| CSR
    CSR -->|“approval & signing”| RootCA
    RootCA -->|“issue client cert”| Kubeconfig

    %% Certificate Authorities
    subgraph "Certificate Authorities"
        direction TB
        RootCA["Cluster Root CA"]:::ca
        EtcdCA["etcd-CA"]:::ca
        ExtCA["External/Public CA"]:::ca
    end

    %% Control Plane
    subgraph "Control Plane"
        direction TB
        APIServer["kube-apiserver"]:::server
        Scheduler["kube-scheduler"]:::client
        Controller["kube-controller-manager"]:::client
    end

    %% etcd
    subgraph "Data Store"
        direction TB
        ETCD["etcd"]:::server
    end

    %% Worker Nodes
    subgraph "Worker Node"
        direction TB
        Kubelet["kubelet"]:::client
        Proxy["kube-proxy"]:::client
    end

    %% Connections
    Seema -->|"HTTPS/TLS, client-cert & server-cert"| APIServer
    Scheduler -->|"mTLS"| APIServer
    Controller -->|"mTLS"| APIServer
    APIServer -->|"mTLS, etcd-CA"| ETCD
    ETCD -->|"mTLS, etcd-CA"| APIServer
    APIServer -->|"mTLS client auth & NodeRestriction"| Kubelet
    Kubelet -->|"mTLS client auth & NodeRestriction"| APIServer

    %% Legend
    subgraph Legend
        direction TB
        L1["Yellow = CA"]:::ca
        L2["Blue = Client"]:::client
        L3["Green = Server"]:::server
        L4["Purple = User"]:::user
        L5["Orange Dashed = CSR Flow"]:::dashed
    end

    %% Click Events
    click RootCA "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click EtcdCA "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click ExtCA "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click APIServer "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Scheduler "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Controller "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click ETCD "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Kubelet "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Proxy "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Seema "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click CSR "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Kubeconfig "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/blob/main/README.md"
    click Legend "https://github.com/cloudwithvarjosh/tls-in-kubernetes-masterclass/tree/main/images/testfile"

    %% Styles
    classDef ca fill:#f9e79f,stroke:#b7950b,color:#784212
    classDef client fill:#aed6f1,stroke:#5dade2,color:#1b4f72
    classDef server fill:#a9dfbf,stroke:#52be80,color:#145a32
    classDef user fill:#d7bde2,stroke:#884ea0,color:#4a235a
    classDef dashed stroke-dasharray: 5 5,stroke:#e67e22,color:#e67e22
    classDef api fill:#f5cba7,stroke:#d35400,color:#78281f
```
