An open API service indexing awesome lists of open source software.

https://github.com/brkcvlk/hello-k8s

A simple hello-k8s REST API deployed on Kubernetes with GitOps via ArgoCD
https://github.com/brkcvlk/hello-k8s

argocd cicd devops docker fastapi gitops k8s kubernetes minikube nginx python

Last synced: about 1 month ago
JSON representation

A simple hello-k8s REST API deployed on Kubernetes with GitOps via ArgoCD

Awesome Lists containing this project

README

          

# hello-k8s

> [!NOTE]
> This project was built for learning and practicing Kubernetes concepts.

A Kubernetes project that serves a simple REST API (`GET /` : `{"message": "hello k8s!"}`) using FastAPI behind an Nginx reverse proxy, with a CI/CD pipeline and GitOps deployment via ArgoCD.

## Architecture

```
Internet


nginx-service (NodePort)
port: 30080 → targetPort: 80


nginx Pod ×1 (nginx:alpine)
listens on :80
reverse proxy → http://fastapi-service:80


fastapi-service (ClusterIP)
port: 80 → targetPort: 8000


fastapi Pod ×2 (ghcr.io/brkcvlk/hello-k8s-fastapi:{{Github-SHA}})
listens on :8000
/ → {"message": "hello k8s!"}
/health → liveness probe
/ready → readiness probe
```
### Example ArgoCD application view : K8s objects and their relationships in the hello-k8s namespace

![ArgoCD Overview](assets/argocd-overview.png)

## Prerequisites

- [minikube](https://minikube.sigs.k8s.io/)
- [ArgoCD](https://argo-cd.readthedocs.io/)

## Quick start

### 1. Start the Cluster

```bash
minikube start --cpus=2 --memory=4096
```

> [!NOTE]
> If kubectl isnt installed, you can use it via minikube.
> Set an alias:
>`alias kubectl="minikube kubectl --"` or use `minikube kubectl --` directly.

### 2. Setup ArgoCD

```bash
kubectl create namespace argocd
kubectl apply -n argocd --server-side --force-conflicts \
-f https://raw.githubusercontent.com/argoproj/argo-cd/v2.13.3/manifests/install.yaml
kubectl get pods -n argocd
```

Access the ArgoCD UI : `argocd-server` is ClusterIP, minikube opens a tunnel
```bash
minikube service argocd-server -n argocd --url
```

Retrieve the initial admin password
```bash
kubectl -n argocd get secret argocd-initial-admin-secret \
-o jsonpath="{.data.password}" | base64 -d
```

Connect to repository
```bash
argocd login --username admin --password --insecure

argocd repo add https://github.com/brkcvlk/hello-k8s \
--username brkcvlk \
--password
```

### 3. Apply ArgoCD Manifest
```bash
kubectl apply -f manifests/argocd-app.yml
```

## Endpoints

| Endpoint | Probe | Description |
|---|---|---|
| `GET /` | — | Returns `{"message": "hello k8s!"}` |
| `GET /health` | liveness | Process is alive |
| `GET /ready` | readiness | App is ready to serve traffic |