# rsalesfreitas/kubernetes-deploy-go architecture

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

- Interactive diagram: https://gitdiagram.com/rsalesfreitas/kubernetes-deploy-go
- Repository: https://github.com/rsalesfreitas/kubernetes-deploy-go

## Overview

##### Project type and purpose
- This is not a full-stack web app but a single-service Go application whose primary goal is to illustrate a CI/CD workflow via Rancher Pipeline. The key use case is: commit Go code → pipeline builds and tests → produces a Docker image → deploys to Kubernetes.

##### File structure
- Top-level files:
- .rancher-pipeline.yml → Rancher CI/CD pipeline definition
- Dockerfile → containerize the Go binary
- deployment.yaml → Kubernetes manifest to deploy the container
- main.go / main_test.go → the Go “hello-server” source & unit test
- No separate frontend or external libraries—this is a single microservice with a CI/CD focus.

##### Architecture components
a. Source Code Repository (GitHub/GitLab/etc.)
b. Rancher Pipeline Server
c. Build Agent / Runner
d. Go Build & Test Step
e. Docker Build & Push Step
f. Container Registry (Docker Hub / Private Registry)
g. Kubernetes Cluster (API Server, Nodes, Pods)
h. “hello-server” Pod & Service (as described in deployment.yaml)
i. External Traffic (LoadBalancer or Ingress)

##### Relationships and data flow
1. Developer pushes code to the Source Repository
2. Rancher Pipeline Server is notified (webhook)
3. Build Agent checks out code
4. Agent runs `go build` & `go test` (main.go, main_test.go)
5. On success, Agent uses Dockerfile to build an image
6. Agent pushes image to the Container Registry
7. Pipeline applies `deployment.yaml` to the Kubernetes Cluster
8. Kubernetes API schedules a Pod running the new image
9. External Traffic (user requests) → LoadBalancer/Ingress → Cluster Service → Pod

##### Architectural patterns & design principles
- CI/CD pipeline pattern (build-test-deploy)
- Immutable artifacts (Docker images)
- Declarative infrastructure (Kubernetes manifests)
- Separation of concerns: build/test vs. deploy vs. run

Layer 1: Developer & Source Control
Layer 2: Rancher Pipeline (Webhook → Build Agent → Steps)
Layer 3: Container Registry
Layer 4: Kubernetes Cluster (API Server → Nodes → Pods & Services)
Layer 5: External Users or LoadBalancer

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entities
    Dev["Developer"]:::external
    Repo["Source Code Repository"]:::external
    Doc["Project Documentation (README.md)"]:::external

    %% CI/CD Layer
    Pipeline["Rancher Pipeline Server"]:::cicd
    Agent["Build Agent"]:::cicd
    Step1["Go Build & Test Step"]:::cicd
    Step2["Docker Build & Push Step"]:::cicd

    %% Artifact Store
    Registry["Container Registry"]:::registry

    %% Runtime Environment
    KubeAPI["Kubernetes API Server"]:::runtime
    Pod["hello-server Pod & Service"]:::runtime
    LB["LoadBalancer / Ingress"]:::runtime
    User["External User"]:::external

    %% Flow
    Dev -->|"1. commit code"| Repo
    Repo -->|"2. webhook"| Pipeline
    Pipeline -->|"3. start build"| Agent
    Agent -->|"4. go build & test"| Step1
    Step1 -->|"5. build image"| Step2
    Step2 -->|"6. push image"| Registry
    Pipeline -->|"7. deploy (kubectl apply)"| KubeAPI
    KubeAPI -->|"8. schedule Pod"| Pod
    User -->|"9. HTTP GET"| LB
    LB -->|"forward to Service"| Pod

    %% Click Events
    click Pipeline "https://github.com/rsalesfreitas/kubernetes-deploy-go/blob/master/.rancher-pipeline.yml"
    click Step1 "https://github.com/rsalesfreitas/kubernetes-deploy-go/blob/master/main.go"
    click Step1 "https://github.com/rsalesfreitas/kubernetes-deploy-go/blob/master/main_test.go"
    click Step2 "https://github.com/rsalesfreitas/kubernetes-deploy-go/tree/master/Dockerfile"
    click Pod "https://github.com/rsalesfreitas/kubernetes-deploy-go/blob/master/deployment.yaml"
    click Doc "https://github.com/rsalesfreitas/kubernetes-deploy-go/blob/master/README.md"

    %% Styles
    classDef cicd fill:#f9f,stroke:#333,stroke-width:2px
    classDef registry fill:#ff9,stroke:#333,stroke-width:2px
    classDef runtime fill:#9f9,stroke:#333,stroke-width:2px
    classDef external fill:#ccf,stroke:#333,stroke-width:2px
```
