Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions dev/nginx/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PORT ?= 8080

.PHONY: help deploy cleanup logs update port-forward test

help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
@echo "\nVariables:"
@echo " PORT=8080 Port for port-forwarding (default: 8080)"

deploy: ## Deploy nginx and nginx-hello server to Kubernetes
kubectl create configmap nginx-config --from-file=nginx.conf --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -f nginx.yaml
@echo "Waiting for pods to be ready..."
kubectl wait --for=condition=ready pod -l app=nginx-proxy --timeout=60s
kubectl wait --for=condition=ready pod -l app=nginx-hello --timeout=60s

cleanup: ## Delete everything from Kubernetes
kubectl delete configmap nginx-config --ignore-not-found=true
kubectl delete -f nginx.yaml --ignore-not-found=true

logs: ## Show nginx logs
kubectl logs -l app=nginx-proxy -f

update: ## Update nginx config and restart pods
kubectl create configmap nginx-config --from-file=nginx.conf --dry-run=client -o yaml | kubectl apply -f -
kubectl rollout restart deployment/nginx-proxy

port-forward: ## Port forward nginx pod to localhost:PORT (default: 8080)
kubectl port-forward deployment/nginx-proxy $(PORT):80

test: ## Test the setup via port-forward (run 'make port-forward' first)
@echo "Testing nginx health..."
@curl -s http://localhost:$(PORT)/health
@echo "\nTesting nginx-hello backend..."
@curl -s http://localhost:$(PORT)/ | head -5
39 changes: 39 additions & 0 deletions dev/nginx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Deploy NGINX locally for testing

This guide provides an easy way to deploy and experiment with NGINX configs locally

## Quick Start

```bash
# Deploy nginx and nginx-hello server
make deploy

# Port-forward nginx pod (in separate terminal)
make port-forward

# Test it works
make test

# Clean up
make cleanup
```

## Available Commands

- `make deploy` - Deploy nginx and nginx-hello server to Kubernetes
- `make port-forward` - Port forward nginx pod to localhost:8080
- `make test` - Test the setup via curl (assuming port-forward is running)
- `make update` - Update config and restart pods
- `make logs` - View nginx logs
- `make cleanup` - Delete everything

## How it works

1. NGINX pod proxies all requests to nginx-hello server pod
2. Use port-forward to access nginx on localhost:8080
3. Edit `nginx.conf` directly and run `make update`

## URLs (after port-forward)

- http://localhost:8080/health - NGINX health check
- http://localhost:8080/ - Proxied to nginx-hello server
21 changes: 21 additions & 0 deletions dev/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
events {
worker_connections 1024;
}

http {
upstream nginx-hello-backend {
server nginx-hello-service:8080;
}

server {
listen 80;

location /health {
return 200 "OK\n";
}

location / {
proxy_pass http://nginx-hello-backend;
}
}
}
68 changes: 68 additions & 0 deletions dev/nginx/nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-proxy
namespace: default
labels:
app: nginx-proxy
spec:
replicas: 1
selector:
matchLabels:
app: nginx-proxy
template:
metadata:
labels:
app: nginx-proxy
spec:
containers:
- name: nginx
image: nginx:alpine
ports:
- containerPort: 80
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
volumes:
- name: nginx-config
configMap:
name: nginx-config

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-hello
namespace: default
labels:
app: nginx-hello
spec:
replicas: 1
selector:
matchLabels:
app: nginx-hello
template:
metadata:
labels:
app: nginx-hello
spec:
containers:
- name: nginx-hello
image: nginxdemos/nginx-hello:plain-text
ports:
- containerPort: 8080

---
apiVersion: v1
kind: Service
metadata:
name: nginx-hello-service
namespace: default
spec:
selector:
app: nginx-hello
ports:
- port: 8080
targetPort: 8080
Loading