Files
site11/k8s/news-api
jungwoo choi 3ce504e0b1 chore: Update News API HPA minReplicas to 3
- Change HPA minReplicas from 2 to 3
- Maintain maxReplicas at 10
- Default 3 pods, auto-scale up to 10 based on CPU/Memory

🤖 Generated with [Claude Code](https://claude.ai/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-03 17:39:45 +09:00
..

News API Kubernetes Deployment

Overview

Multi-language news articles REST API service for Kubernetes deployment.

Features

  • 9 Language Support: ko, en, zh_cn, zh_tw, ja, fr, de, es, it
  • REST API: FastAPI with async MongoDB
  • Auto-scaling: HPA based on CPU/Memory
  • Health Checks: Liveness and readiness probes

Deployment

Option 1: Local Kubernetes

# Build Docker image
docker build -t site11/news-api:latest services/news-api/backend/

# Deploy to K8s
kubectl apply -f k8s/news-api/news-api-deployment.yaml

# Check status
kubectl -n site11-news get pods

Option 2: Docker Hub

# Set Docker Hub user
export DOCKER_HUB_USER=your-username

# Build and push
docker build -t ${DOCKER_HUB_USER}/news-api:latest services/news-api/backend/
docker push ${DOCKER_HUB_USER}/news-api:latest

# Deploy
envsubst < k8s/news-api/news-api-dockerhub.yaml | kubectl apply -f -

Option 3: Kind Cluster

# Build image
docker build -t site11/news-api:latest services/news-api/backend/

# Load to Kind
kind load docker-image site11/news-api:latest --name site11-cluster

# Deploy
kubectl apply -f k8s/news-api/news-api-deployment.yaml

API Endpoints

Get Articles List

GET /api/v1/{language}/articles?page=1&page_size=20&category=tech

Get Latest Articles

GET /api/v1/{language}/articles/latest?limit=10

Search Articles

GET /api/v1/{language}/articles/search?q=keyword&page=1

Get Article by ID

GET /api/v1/{language}/articles/{article_id}

Get Categories

GET /api/v1/{language}/categories

Testing

Port Forward

kubectl -n site11-news port-forward svc/news-api-service 8050:8000

Test API

# Health check
curl http://localhost:8050/health

# Get Korean articles
curl http://localhost:8050/api/v1/ko/articles

# Get latest English articles
curl http://localhost:8050/api/v1/en/articles/latest?limit=5

# Search Japanese articles
curl "http://localhost:8050/api/v1/ja/articles/search?q=AI"

Monitoring

View Pods

kubectl -n site11-news get pods -w

View Logs

kubectl -n site11-news logs -f deployment/news-api

Check HPA

kubectl -n site11-news get hpa

Describe Service

kubectl -n site11-news describe svc news-api-service

Scaling

Manual Scaling

# Scale up
kubectl -n site11-news scale deployment news-api --replicas=5

# Scale down
kubectl -n site11-news scale deployment news-api --replicas=2

Auto-scaling

HPA automatically scales between 2-10 replicas based on:

  • CPU usage: 70% threshold
  • Memory usage: 80% threshold

Cleanup

# Delete all resources
kubectl delete namespace site11-news

Troubleshooting

Issue: ImagePullBackOff

Solution: Use Docker Hub deployment or load image to Kind

Issue: MongoDB Connection Failed

Solution: Ensure MongoDB is running at host.docker.internal:27017

Issue: No Articles Returned

Solution: Check if articles exist in MongoDB collections

Issue: 404 on all endpoints

Solution: Verify correct namespace and service name in port-forward