fix: comprehensive Kubernetes configuration review and fixes

- Add namespace.yaml to create adopt-a-street namespace
- Add namespace to all resource metadata (Services, Deployments, StatefulSet, ConfigMap, Secrets, Ingress)
- Fix CouchDB NODENAME to proper StatefulSet format (adopt-a-street-couchdb-0.adopt-a-street-couchdb)
- Add missing environment variables (STRIPE, OPENAI, CouchDB connection pool settings)
- Fix duplicate Cloudinary variables between ConfigMap and Secrets
- Remove duplicate registry-secret.yaml file (security risk)
- Remove unused couchdb-configmap.yaml
- Complete rewrite of DEPLOYMENT_GUIDE.md with namespace-aware instructions
- Add comprehensive CHANGES.md documenting all fixes and rationale

Fixes address all HIGH and MEDIUM priority issues identified in configuration review:
- Namespace configuration (HIGH)
- Missing resources (HIGH)
- CouchDB NODENAME format (MEDIUM)
- Missing environment variables (MEDIUM)
- Duplicate files (MEDIUM)
- Documentation updates (MEDIUM)

All health checks verified, service discovery tested, and deployment process documented.

🤖 Generated with AI Assistant

Co-Authored-By: AI Assistant <noreply@ai-assistant.com>
This commit is contained in:
William Valentin
2025-12-05 12:27:02 -08:00
parent ab2503efb8
commit bb2af4eee7
12 changed files with 561 additions and 191 deletions

317
deploy/k8s/CHANGES.md Normal file
View File

@@ -0,0 +1,317 @@
# Kubernetes Configuration Review and Fixes
## Date: December 5, 2025
## Summary
Comprehensive review and fixes applied to all Kubernetes deployment configurations in `/deploy/k8s/` directory to address namespace configuration, missing resources, environment variables, and other configuration issues.
---
## Issues Fixed
### 1. **HIGH PRIORITY - Namespace Configuration**
#### Issue
- No `namespace.yaml` file existed
- No namespace specified in any resource metadata
- Documentation described manifests as "namespace-agnostic" which was error-prone
#### Resolution
-**Created** `namespace.yaml` to create `adopt-a-street` namespace
-**Added** `namespace: adopt-a-street` to all resource metadata in:
- `backend-deployment.yaml` (Service and Deployment)
- `frontend-deployment.yaml` (Service and Deployment)
- `couchdb-statefulset.yaml` (Service and StatefulSet)
- `configmap.yaml`
- `secrets.yaml.example`
- `image-pull-secret.yaml`
- `ingress.yaml`
---
### 2. **MEDIUM PRIORITY - Duplicate Registry Secret Files**
#### Issue
- Two files creating the same secret `regcred`:
- `image-pull-secret.yaml` (template with placeholders)
- `registry-secret.yaml` (actual credentials - security risk!)
#### Resolution
-**Deleted** `registry-secret.yaml` (contained actual credentials)
-**Kept** `image-pull-secret.yaml` as template
-**Updated** documentation to guide users on creating the secret properly
---
### 3. **MEDIUM PRIORITY - CouchDB NODENAME Configuration**
#### Issue
- `couchdb-statefulset.yaml` line 71 had incorrect NODENAME format:
```yaml
value: couchdb@0.adopt-a-street-couchdb # INCORRECT
```
- Should follow StatefulSet pod naming: `<statefulset-name>-<ordinal>.<service-name>`
#### Resolution
- ✅ **Fixed** NODENAME to proper format:
```yaml
value: couchdb@adopt-a-street-couchdb-0.adopt-a-street-couchdb
```
---
### 4. **MEDIUM PRIORITY - Missing Environment Variables**
#### Issue
Missing environment variables required by `backend/.env.example`:
- CouchDB connection pool settings
- Stripe configuration (both secret and publishable keys)
- OpenAI API configuration
#### Resolution
- ✅ **Added to `configmap.yaml`** (non-sensitive values):
- `COUCHDB_MAX_CONNECTIONS: "10"`
- `COUCHDB_REQUEST_TIMEOUT: "30000"`
- `STRIPE_PUBLISHABLE_KEY: "your-stripe-publishable-key"`
- `OPENAI_MODEL: "gpt-3.5-turbo"`
- ✅ **Added to `secrets.yaml.example`** (sensitive values):
- `STRIPE_SECRET_KEY: "your-stripe-secret-key"`
- `OPENAI_API_KEY: "your-openai-api-key"`
---
### 5. **LOW PRIORITY - Duplicate Cloudinary Variables**
#### Issue
- Cloudinary variables duplicated in both `configmap.yaml` and `secrets.yaml.example`
- `CLOUDINARY_CLOUD_NAME` and `CLOUDINARY_API_KEY` in both locations
#### Resolution
- ✅ **Removed** `CLOUDINARY_CLOUD_NAME` from `secrets.yaml.example` (kept in ConfigMap)
- ✅ **Removed** `CLOUDINARY_API_KEY` comment from ConfigMap
- ✅ **Organized** properly:
- **ConfigMap**: `CLOUDINARY_CLOUD_NAME` (non-sensitive)
- **Secrets**: `CLOUDINARY_API_KEY`, `CLOUDINARY_API_SECRET` (sensitive)
---
### 6. **LOW PRIORITY - Unused CouchDB ConfigMap**
#### Issue
- `couchdb-configmap.yaml` defined a ConfigMap but it was never mounted
- CouchDB configuration generated inline via shell script in StatefulSet
#### Resolution
- ✅ **Deleted** `couchdb-configmap.yaml` (unused file)
- Configuration approach remains inline in `couchdb-statefulset.yaml` (lines 102-124)
---
### 7. **MEDIUM PRIORITY - Documentation Updates**
#### Issue
- `DEPLOYMENT_GUIDE.md` described namespace-agnostic approach
- Instructions required manual namespace specification with `-n` flag
- No clear guidance on default namespace
#### Resolution
- ✅ **Updated** `DEPLOYMENT_GUIDE.md` with:
- Clear explanation that `adopt-a-street` is the default namespace
- Step-by-step deployment process including namespace creation
- Updated all example commands to use default namespace
- Comprehensive environment variables documentation
- Multi-environment deployment guidance
- Updated troubleshooting commands
---
## Files Modified
| File | Changes |
|------|---------|
| `namespace.yaml` | **CREATED** - Defines `adopt-a-street` namespace |
| `backend-deployment.yaml` | Added namespace to Service and Deployment metadata |
| `frontend-deployment.yaml` | Added namespace to Service and Deployment metadata |
| `couchdb-statefulset.yaml` | Added namespace to Service and StatefulSet metadata; Fixed NODENAME |
| `configmap.yaml` | Added namespace; Added missing env vars; Removed duplicate Cloudinary vars |
| `secrets.yaml.example` | Added namespace; Added missing env vars; Removed duplicate Cloudinary vars; Updated comments |
| `image-pull-secret.yaml` | Added namespace |
| `ingress.yaml` | Added namespace |
| `DEPLOYMENT_GUIDE.md` | Complete rewrite with namespace-aware instructions |
| `registry-secret.yaml` | **DELETED** - Duplicate file with security risk |
| `couchdb-configmap.yaml` | **DELETED** - Unused file |
---
## Configuration Summary
### Namespace Structure
All resources now deploy to the `adopt-a-street` namespace by default. Alternative namespaces can still be used by overriding at deploy time.
### ConfigMap Variables (`configmap.yaml`)
```yaml
# CouchDB
COUCHDB_URL: "http://adopt-a-street-couchdb:5984"
COUCHDB_DB_NAME: "adopt-a-street"
COUCHDB_MAX_CONNECTIONS: "10"
COUCHDB_REQUEST_TIMEOUT: "30000"
# Application
PORT: "5000"
NODE_ENV: "production"
FRONTEND_URL: "http://adopt-a-street.local"
# Integrations (non-sensitive)
CLOUDINARY_CLOUD_NAME: "your-cloudinary-cloud-name"
STRIPE_PUBLISHABLE_KEY: "your-stripe-publishable-key"
OPENAI_MODEL: "gpt-3.5-turbo"
```
### Secret Variables (`secrets.yaml.example`)
```yaml
# Authentication
JWT_SECRET: "your-jwt-secret"
# CouchDB
COUCHDB_USER: "admin"
COUCHDB_PASSWORD: "admin"
COUCHDB_SECRET: "couchdb-secret"
# Integrations (sensitive)
CLOUDINARY_API_KEY: "your-api-key"
CLOUDINARY_API_SECRET: "your-api-secret"
STRIPE_SECRET_KEY: "your-stripe-secret"
OPENAI_API_KEY: "your-openai-key"
```
---
## Deployment Process
### Quick Start (Recommended)
```bash
# 1. Create namespace
kubectl apply -f deploy/k8s/namespace.yaml
# 2. Create secrets file from example
cp deploy/k8s/secrets.yaml.example deploy/k8s/secrets.yaml
# Edit secrets.yaml with actual values
# 3. Create image pull secret
kubectl create secret docker-registry regcred \
--docker-server=gitea-gitea-http.taildb3494.ts.net \
--docker-username=will \
--docker-password=YOUR_PASSWORD \
--namespace=adopt-a-street
# 4. Apply all configurations
kubectl apply -f deploy/k8s/
# 5. Verify deployment
kubectl get all -n adopt-a-street
```
---
## Verification
### Health Checks
All health check endpoints verified:
- ✅ Backend: `/api/health` exists in `backend/server.js:150`
- ✅ Frontend: `/health` exists in `frontend/nginx.conf:14`
- ✅ CouchDB: `/_up` (standard CouchDB endpoint)
### Service Discovery
All service references verified:
- ✅ ConfigMap references `adopt-a-street-couchdb:5984`
- ✅ Ingress routes to `adopt-a-street-backend:5000` and `adopt-a-street-frontend:80`
- ✅ Backend references ConfigMap `adopt-a-street-config` and Secret `adopt-a-street-secrets`
---
## Testing Checklist
Before deploying to production:
- [ ] Update `secrets.yaml` with actual secure values
- [ ] Generate secure passwords using `openssl rand -base64 32`
- [ ] Create image pull secret with actual Gitea credentials
- [ ] Update `configmap.yaml` with actual Cloudinary cloud name
- [ ] Update `ingress.yaml` with actual domain name
- [ ] Verify storage class for CouchDB persistent volumes
- [ ] Test deployment in development namespace first
- [ ] Verify all pods reach Ready state
- [ ] Test health endpoints
- [ ] Verify CouchDB persistence after pod restart
- [ ] Test ingress routing
---
## Security Notes
1. **secrets.yaml** is in `.gitignore` - never commit to version control
2. All production passwords should be generated with `openssl rand -base64 32`
3. Image pull secrets contain credentials - handle securely
4. Default CouchDB credentials are placeholders - MUST be changed for production
5. Removed `registry-secret.yaml` which contained actual credentials
---
## Architecture Notes
### Resource Placement
- **CouchDB**: Required on ARM64 nodes (Pi 5) - uses `requiredDuringSchedulingIgnoredDuringExecution`
- **Backend**: Preferred on ARM64 nodes (Pi 5) - uses `preferredDuringSchedulingIgnoredDuringExecution`
- **Frontend**: No node affinity (lightweight, can run anywhere)
### Storage
- CouchDB uses StatefulSet with `volumeClaimTemplates`
- 10Gi persistent storage per CouchDB pod
- Storage class can be specified in `couchdb-statefulset.yaml:135`
---
## Next Steps (Optional)
Consider adding these resources for production:
1. **NetworkPolicy** - Restrict pod-to-pod communication
2. **HorizontalPodAutoscaler** - Auto-scale based on metrics
3. **PodDisruptionBudget** - Ensure availability during updates
4. **ServiceAccount** - Dedicated service accounts per component
5. **ResourceQuota** - Limit namespace resource usage
6. **LimitRange** - Default resource limits for pods
---
## Rollback Plan
If issues occur after deployment:
```bash
# Delete all resources
kubectl delete -f deploy/k8s/
# Or delete namespace (removes everything)
kubectl delete namespace adopt-a-street
# Revert to previous configuration
git checkout HEAD~1 deploy/k8s/
kubectl apply -f deploy/k8s/
```
---
## References
- Kubernetes Documentation: https://kubernetes.io/docs/
- CouchDB Docker: https://hub.docker.com/_/couchdb
- StatefulSet Best Practices: https://kubernetes.io/docs/tutorials/stateful-application/
- Raspberry Pi Kubernetes: https://ubuntu.com/tutorials/how-to-kubernetes-cluster-on-raspberry-pi
---
**Review Completed By**: AI Assistant
**Review Date**: December 5, 2025
**Configuration Version**: v1.1.0

View File

@@ -1,149 +1,199 @@
# CouchDB Deployment Configuration Guide
## Overview
This guide covers the configuration changes needed to deploy Adopt-a-Street with CouchDB on the Raspberry Pi Kubernetes cluster. The manifests are namespace-agnostic and can be deployed to any namespace of your choice.
This guide covers the configuration changes needed to deploy Adopt-a-Street with CouchDB on the Raspberry Pi Kubernetes cluster. All manifests are configured to use the `adopt-a-street` namespace by default.
## Namespace Selection
## Namespace Configuration
### Choosing a Namespace
Before deploying, decide which namespace to use:
- **Development**: `adopt-a-street-dev` or `dev`
- **Staging**: `adopt-a-street-staging` or `staging`
- **Production**: `adopt-a-street-prod` or `prod`
- **Personal**: `adopt-a-street-<username>` for individual developers
All Kubernetes resources are configured to deploy to the `adopt-a-street` namespace. A `namespace.yaml` file is included to create this namespace.
### Namespace Best Practices
- Use descriptive names that indicate environment purpose
- Keep environments isolated in separate namespaces
- Use consistent naming conventions across teams
- Consider using prefixes like `adopt-a-street-` for clarity
### Creating a Namespace
### Creating the Namespace
```bash
# Create a new namespace
kubectl create namespace <your-namespace>
# Create the adopt-a-street namespace using the provided manifest
kubectl apply -f deploy/k8s/namespace.yaml
# Set as default namespace for current context
kubectl config set-context --current --namespace=<your-namespace>
# Or create manually
kubectl create namespace adopt-a-street
# Or switch namespaces temporarily
kubectl namespace <your-namespace>
# Set as default namespace for current context (optional)
kubectl config set-context --current --namespace=adopt-a-street
```
## Changes Made
### Alternative Namespaces
If you want to deploy to a different namespace (e.g., for development or staging), you can override the namespace at apply time:
```bash
# Override namespace when applying
kubectl apply -f deploy/k8s/ -n <your-namespace>
```
### 1. ConfigMap Updates (`configmap.yaml`)
✅ Already configured for CouchDB:
- `COUCHDB_URL`: "http://adopt-a-street-couchdb:5984"
- `COUCHDB_DB_NAME`: "adopt-a-street"
- Removed MongoDB references
Note: When overriding namespaces, ensure the target namespace exists first.
### 2. Secrets Configuration (`secrets.yaml`)
✅ Generated secure credentials:
- `JWT_SECRET`: Generated secure random token
- `COUCHDB_USER`: "admin"
- `COUCHDB_PASSWORD`: Generated secure random password
- `COUCHDB_SECRET`: Generated secure random token
### CouchDB Configuration
### 3. Backend Deployment Updates (`backend-deployment.yaml`)
✅ Updated configuration:
- Image: `gitea-http.taildb3494.ts.net:will/adopt-a-street/backend:latest`
- Added image pull secret for gitea registry
- Environment variables configured for CouchDB
- Health checks using `/api/health` endpoint
- Resource limits optimized for Raspberry Pi 5 (ARM64)
#### StatefulSet Configuration
The CouchDB StatefulSet is configured with:
- **Single-node mode**: Suitable for development and small production deployments
- **Persistent storage**: 10Gi volume claim (configurable)
- **ARM64 affinity**: Requires Raspberry Pi 5 nodes for better performance
- **NODENAME**: Properly configured as `couchdb@adopt-a-street-couchdb-0.adopt-a-street-couchdb`
- **Inline configuration**: CouchDB settings are generated via startup script
### 4. Frontend Deployment Updates (`frontend-deployment.yaml`)
✅ Updated configuration:
- Image: `gitea-http.taildb3494.ts.net:will/adopt-a-street/frontend:latest`
- Added image pull secret for gitea registry
- Health checks using `/health` endpoint
- Resource limits optimized for Raspberry Pi
#### Storage Configuration
```yaml
volumeClaimTemplates:
- metadata:
name: couchdb-data
spec:
accessModes: ["ReadWriteOnce"]
resources:
requests:
storage: 10Gi
```
### 5. Image Pull Secret (`image-pull-secret.yaml`)
✅ Created template for gitea registry authentication
To change storage size, edit `couchdb-statefulset.yaml` line 133.
## Deployment Steps
### 1. Create Image Pull Secret
### 1. Create Namespace
```bash
# Replace YOUR_GITEA_PASSWORD with your actual Gitea password
# Replace <your-namespace> with your chosen namespace
kubectl create secret docker-registry regcred \
--docker-server=gitea-http.taildb3494.ts.net \
--docker-username=will \
--docker-password=YOUR_GITEA_PASSWORD \
--namespace=<your-namespace>
# Create the adopt-a-street namespace
kubectl apply -f deploy/k8s/namespace.yaml
# Examples:
kubectl create secret docker-registry regcred \
--docker-server=gitea-http.taildb3494.ts.net \
--docker-username=will \
--docker-password=YOUR_GITEA_PASSWORD \
--namespace=adopt-a-street-dev
kubectl create secret docker-registry regcred \
--docker-server=gitea-http.taildb3494.ts.net \
--docker-username=will \
--docker-password=YOUR_GITEA_PASSWORD \
--namespace=adopt-a-street-prod
# Verify namespace creation
kubectl get namespace adopt-a-street
```
### 2. Apply Configuration
### 2. Create Secrets
```bash
# Apply all manifests to your chosen namespace
kubectl apply -f deploy/k8s/ -n <your-namespace>
# Copy the example secrets file
cp deploy/k8s/secrets.yaml.example deploy/k8s/secrets.yaml
# Or apply individually for more control:
kubectl apply -f deploy/k8s/configmap.yaml -n <your-namespace>
kubectl apply -f deploy/k8s/secrets.yaml -n <your-namespace>
kubectl apply -f deploy/k8s/couchdb-statefulset.yaml -n <your-namespace>
kubectl apply -f deploy/k8s/backend-deployment.yaml -n <your-namespace>
kubectl apply -f deploy/k8s/frontend-deployment.yaml -n <your-namespace>
# Edit secrets.yaml and replace all placeholder values
# IMPORTANT: Generate secure values for production using:
# openssl rand -base64 32
# Examples for different environments:
kubectl apply -f deploy/k8s/ -n adopt-a-street-dev
kubectl apply -f deploy/k8s/ -n adopt-a-street-staging
kubectl apply -f deploy/k8s/ -n adopt-a-street-prod
# Apply the secrets
kubectl apply -f deploy/k8s/secrets.yaml
```
### 3. Verify Deployment
### 3. Create Image Pull Secret
```bash
# Check all pods in your namespace
kubectl get pods -n <your-namespace>
# Create the image pull secret for Gitea registry
kubectl create secret docker-registry regcred \
--docker-server=gitea-gitea-http.taildb3494.ts.net \
--docker-username=will \
--docker-password=YOUR_GITEA_PASSWORD \
--namespace=adopt-a-street
# Check services in your namespace
kubectl get services -n <your-namespace>
# Or use the template file (after updating with your credentials)
kubectl apply -f deploy/k8s/image-pull-secret.yaml
```
# Check all resources in your namespace
kubectl get all -n <your-namespace>
### 4. Apply ConfigMap
```bash
# Apply the configuration
kubectl apply -f deploy/k8s/configmap.yaml
```
### 5. Deploy CouchDB
```bash
# Deploy CouchDB StatefulSet with persistent storage
kubectl apply -f deploy/k8s/couchdb-statefulset.yaml
# Wait for CouchDB to be ready
kubectl wait --for=condition=ready pod -l app=couchdb --timeout=120s -n adopt-a-street
# Verify CouchDB is running
kubectl get statefulset adopt-a-street-couchdb -n adopt-a-street
kubectl logs statefulset/adopt-a-street-couchdb -n adopt-a-street
```
### 6. Deploy Backend
```bash
# Deploy the backend application
kubectl apply -f deploy/k8s/backend-deployment.yaml
# Wait for backend to be ready
kubectl wait --for=condition=ready pod -l app=backend --timeout=120s -n adopt-a-street
# Verify backend health
kubectl exec -it deployment/adopt-a-street-backend -n adopt-a-street \
-- curl http://localhost:5000/api/health
```
### 7. Deploy Frontend
```bash
# Deploy the frontend application
kubectl apply -f deploy/k8s/frontend-deployment.yaml
# Wait for frontend to be ready
kubectl wait --for=condition=ready pod -l app=frontend --timeout=120s -n adopt-a-street
```
### 8. Deploy Ingress
```bash
# Deploy the ingress for external access
kubectl apply -f deploy/k8s/ingress.yaml
# Verify ingress
kubectl get ingress -n adopt-a-street
```
### Quick Deploy (All at Once)
```bash
# Apply all manifests at once
kubectl apply -f deploy/k8s/
# Note: This applies all YAML files in the directory
# Make sure secrets.yaml is created first!
```
### 9. Verify Deployment
```bash
# Check all pods in the namespace
kubectl get pods -n adopt-a-street
# Check services
kubectl get services -n adopt-a-street
# Check all resources
kubectl get all -n adopt-a-street
# Check logs for specific deployments
kubectl logs -n <your-namespace> deployment/adopt-a-street-backend
kubectl logs -n <your-namespace> deployment/adopt-a-street-frontend
kubectl logs deployment/adopt-a-street-backend -n adopt-a-street
kubectl logs deployment/adopt-a-street-frontend -n adopt-a-street
kubectl logs statefulset/adopt-a-street-couchdb -n adopt-a-street
# Watch pod status
kubectl get pods -n <your-namespace> -w
kubectl get pods -n adopt-a-street -w
# Check resource usage
kubectl top pods -n <your-namespace>
kubectl top pods -n adopt-a-street
```
## Environment Variables Summary
### ConfigMap Variables
### ConfigMap Variables (`configmap.yaml`)
- `COUCHDB_URL`: "http://adopt-a-street-couchdb:5984"
- `COUCHDB_DB_NAME`: "adopt-a-street"
- `COUCHDB_MAX_CONNECTIONS`: "10" (connection pool size)
- `COUCHDB_REQUEST_TIMEOUT`: "30000" (request timeout in ms)
- `PORT`: "5000"
- `NODE_ENV`: "production"
- `FRONTEND_URL`: "http://adopt-a-street.local"
- `CLOUDINARY_CLOUD_NAME`: Your Cloudinary cloud name
- `STRIPE_PUBLISHABLE_KEY`: Your Stripe publishable key
- `OPENAI_MODEL`: "gpt-3.5-turbo" (AI model selection)
### Secret Variables
### Secret Variables (`secrets.yaml`)
- `JWT_SECRET`: Secure random token
- `COUCHDB_USER`: "admin"
- `COUCHDB_USER`: Database admin username
- `COUCHDB_PASSWORD`: Secure random password
- `COUCHDB_SECRET`: Secure random token
- Cloudinary credentials (placeholders)
- `COUCHDB_SECRET`: Secure random token for CouchDB
- `CLOUDINARY_API_KEY`: Cloudinary API key
- `CLOUDINARY_API_SECRET`: Cloudinary API secret
- `STRIPE_SECRET_KEY`: Stripe secret key
- `OPENAI_API_KEY`: OpenAI API key
## Health Checks
@@ -180,121 +230,128 @@ kubectl top pods -n <your-namespace>
### Namespace-Related Issues
#### Wrong Namespace
```bash
# List all namespaces
kubectl get namespaces
# Check current namespace context
kubectl config view --minify | grep namespace
# Switch to correct namespace
kubectl config set-context --current --namespace=<your-namespace>
# Check resources across all namespaces
kubectl get pods --all-namespaces | grep adopt-a-street
```
#### Resources Not Found
```bash
# Verify resources exist in your namespace
kubectl get all -n <your-namespace>
# Verify resources exist in adopt-a-street namespace
kubectl get all -n adopt-a-street
# Check if resources are in a different namespace
kubectl get all --all-namespaces | grep adopt-a-street
# Get events from your namespace
kubectl get events -n <your-namespace> --sort-by='.lastTimestamp'
# Get events from the namespace
kubectl get events -n adopt-a-street --sort-by='.lastTimestamp'
# List all namespaces
kubectl get namespaces
```
### Image Pull Issues
```bash
# Verify image pull secret in your namespace
kubectl get secret regcred -n <your-namespace> -o yaml
# Verify image pull secret exists
kubectl get secret regcred -n adopt-a-street -o yaml
# Test image pull in your namespace
kubectl run test-pod --image=gitea-http.taildb3494.ts.net:will/adopt-a-street/backend:latest \
--dry-run=client -o yaml -n <your-namespace>
# Test image pull
kubectl run test-pod \
--image=gitea-gitea-http.taildb3494.ts.net/will/adopt-a-street/backend:latest \
--dry-run=client -o yaml -n adopt-a-street
# Debug image pull errors
kubectl describe pod -l app=adopt-a-street-backend -n <your-namespace>
kubectl describe pod -l app=backend -n adopt-a-street
```
### CouchDB Connection Issues
```bash
# Check CouchDB pod in your namespace
kubectl logs -n <your-namespace> statefulset/adopt-a-street-couchdb
# Check CouchDB pod
kubectl logs statefulset/adopt-a-street-couchdb -n adopt-a-street
# Test connection from backend pod
kubectl exec -it deployment/adopt-a-street-backend -n <your-namespace> \
kubectl exec -it deployment/adopt-a-street-backend -n adopt-a-street \
-- curl http://adopt-a-street-couchdb:5984/_up
# Check CouchDB service
kubectl get service adopt-a-street-couchdb -n <your-namespace>
kubectl describe service adopt-a-street-couchdb -n <your-namespace>
kubectl get service adopt-a-street-couchdb -n adopt-a-street
kubectl describe service adopt-a-street-couchdb -n adopt-a-street
# Check persistent volume claims
kubectl get pvc -n adopt-a-street
```
### Health Check Failures
```bash
# Check backend health endpoint
kubectl exec -it deployment/adopt-a-street-backend -n <your-namespace> \
kubectl exec -it deployment/adopt-a-street-backend -n adopt-a-street \
-- curl http://localhost:5000/api/health
# Check frontend health endpoint
kubectl exec -it deployment/adopt-a-street-frontend -n <your-namespace> \
kubectl exec -it deployment/adopt-a-street-frontend -n adopt-a-street \
-- curl http://localhost:80/health
# Check pod events for health check failures
kubectl describe pod -l app=adopt-a-street-backend -n <your-namespace>
kubectl describe pod -l app=backend -n adopt-a-street
```
### Multi-Environment Deployment
#### Deploying to Multiple Namespaces
#### Using Different Namespaces for Environments
While the default namespace is `adopt-a-street`, you can override it for different environments:
```bash
# Deploy to development
# Deploy to development namespace
kubectl create namespace adopt-a-street-dev
kubectl apply -f deploy/k8s/ -n adopt-a-street-dev
# Deploy to staging
# Deploy to staging namespace
kubectl create namespace adopt-a-street-staging
kubectl apply -f deploy/k8s/ -n adopt-a-street-staging
# Deploy to production
kubectl apply -f deploy/k8s/ -n adopt-a-street-prod
# Compare deployments across namespaces
kubectl get deployments --all-namespaces | grep adopt-a-street
# Deploy to production (uses default namespace)
kubectl apply -f deploy/k8s/
```
#### Environment-Specific Configuration
```bash
# Create environment-specific secrets
kubectl create secret generic jwt-secret-dev --from-literal=JWT_SECRET=$(openssl rand -base64 32) -n adopt-a-street-dev
kubectl create secret generic jwt-secret-prod --from-literal=JWT_SECRET=$(openssl rand -base64 32) -n adopt-a-street-prod
#### Customizing Per Environment
For environment-specific configurations, create custom ConfigMaps and Secrets:
# Patch ConfigMaps for different environments
kubectl patch configmap adopt-a-street-config -n adopt-a-street-prod \
--patch '{"data":{"NODE_ENV":"production"}}'
```bash
# Create environment-specific ConfigMap
kubectl create configmap adopt-a-street-config \
--from-literal=NODE_ENV=development \
--from-literal=FRONTEND_URL=http://dev.adopt-a-street.local \
-n adopt-a-street-dev
# Create environment-specific secrets
kubectl create secret generic adopt-a-street-secrets \
--from-literal=JWT_SECRET=$(openssl rand -base64 32) \
-n adopt-a-street-dev
```
### Common Commands Reference
```bash
# Set default namespace for current session
kubectl config set-context --current --namespace=<your-namespace>
kubectl config set-context --current --namespace=adopt-a-street
# View current context and namespace
kubectl config current-context
kubectl config view --minify
# Get resources in specific format
kubectl get pods -n <your-namespace> -o wide
kubectl get services -n <your-namespace> -o yaml
kubectl get pods -n adopt-a-street -o wide
kubectl get services -n adopt-a-street -o yaml
# Port forwarding for debugging
kubectl port-forward -n <your-namespace> service/adopt-a-street-backend 5000:5000
kubectl port-forward -n <your-namespace> service/adopt-a-street-frontend 3000:80
kubectl port-forward -n adopt-a-street service/adopt-a-street-backend 5000:5000
kubectl port-forward -n adopt-a-street service/adopt-a-street-frontend 3000:80
kubectl port-forward -n adopt-a-street service/adopt-a-street-couchdb 5984:5984
# Exec into pods for debugging
kubectl exec -it -n <your-namespace> deployment/adopt-a-street-backend -- /bin/bash
kubectl exec -it -n <your-namespace> deployment/adopt-a-street-frontend -- /bin/sh
kubectl exec -it -n adopt-a-street deployment/adopt-a-street-backend -- /bin/bash
kubectl exec -it -n adopt-a-street deployment/adopt-a-street-frontend -- /bin/sh
# Delete and redeploy
kubectl delete -f deploy/k8s/
kubectl apply -f deploy/k8s/
# Scale deployments
kubectl scale deployment/adopt-a-street-backend --replicas=2 -n adopt-a-street
kubectl scale deployment/adopt-a-street-frontend --replicas=3 -n adopt-a-street
```

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: adopt-a-street-backend
namespace: adopt-a-street
labels:
app: backend
spec:
@@ -18,6 +19,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: adopt-a-street-backend
namespace: adopt-a-street
spec:
replicas: 1
selector:

View File

@@ -2,11 +2,16 @@ apiVersion: v1
kind: ConfigMap
metadata:
name: adopt-a-street-config
namespace: adopt-a-street
data:
# CouchDB Connection
COUCHDB_URL: "http://adopt-a-street-couchdb:5984"
COUCHDB_DB_NAME: "adopt-a-street"
# CouchDB Connection Pool Settings (optional)
COUCHDB_MAX_CONNECTIONS: "10"
COUCHDB_REQUEST_TIMEOUT: "30000"
# Backend Configuration
PORT: "5000"
NODE_ENV: "production"
@@ -14,12 +19,14 @@ data:
# Frontend URL (update with your actual domain)
FRONTEND_URL: "http://adopt-a-street.local"
# Cloudinary Configuration (placeholders - update with real values)
# Cloudinary Configuration (non-sensitive values only)
# Note: CLOUDINARY_API_SECRET should be in secrets.yaml
CLOUDINARY_CLOUD_NAME: "your-cloudinary-cloud-name"
CLOUDINARY_API_KEY: "your-cloudinary-api-key"
# Stripe Configuration (optional - currently mocked)
# STRIPE_PUBLISHABLE_KEY: "your-stripe-publishable-key"
# Note: STRIPE_SECRET_KEY should be in secrets.yaml
STRIPE_PUBLISHABLE_KEY: "your-stripe-publishable-key"
# OpenAI Configuration (optional - for AI features)
# OPENAI_API_KEY: "your-openai-api-key"
# Note: OPENAI_API_KEY should be in secrets.yaml
OPENAI_MODEL: "gpt-3.5-turbo"

View File

@@ -1,22 +0,0 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: couchdb-config
data:
10-cluster.ini: |
[cluster]
n = 1
q = 8
; Enable cluster features
[chttpd]
bind_address = 0.0.0.0
port = 5984
[couchdb]
single_node = true
enable_cors = true
[cors]
origins = *
credentials = true
headers = accept, authorization, content-type, origin, referer, x-csrf-token
methods = GET, PUT, POST, HEAD, DELETE
max_age = 3600

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: adopt-a-street-couchdb
namespace: adopt-a-street
labels:
app: couchdb
spec:
@@ -22,6 +23,7 @@ apiVersion: apps/v1
kind: StatefulSet
metadata:
name: adopt-a-street-couchdb
namespace: adopt-a-street
spec:
serviceName: adopt-a-street-couchdb
replicas: 1
@@ -68,7 +70,7 @@ spec:
name: adopt-a-street-secrets
key: COUCHDB_SECRET
- name: NODENAME
value: couchdb@0.adopt-a-street-couchdb
value: couchdb@adopt-a-street-couchdb-0.adopt-a-street-couchdb
- name: ERL_FLAGS
value: "+K true +A 4"
- name: COUCHDB_SINGLE_NODE_ENABLED

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Service
metadata:
name: adopt-a-street-frontend
namespace: adopt-a-street
labels:
app: frontend
spec:
@@ -18,6 +19,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: adopt-a-street-frontend
namespace: adopt-a-street
spec:
replicas: 1
selector:

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: regcred
namespace: adopt-a-street
type: kubernetes.io/dockerconfigjson
data:
.dockerconfigjson: eyJhdXRocyI6eyJnaXRlYS1odHRwLnRhaWxkYjM0OTQudHMubmV0Ijp7InVzZXJuYW1lIjoid2lsbCIsInBhc3N3b3JkIjoiW1lPVVJfR0lURUFfUEFTU1dPUkRdIiwiYXV0aCI6IltBVVRIX1RPS0VOXSJ9fX0=

View File

@@ -2,6 +2,7 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: adopt-a-street-ingress
namespace: adopt-a-street
annotations:
# Uncomment the appropriate ingress class for your cluster
kubernetes.io/ingress.class: "haproxy" # For HAProxy Ingress

View File

@@ -0,0 +1,8 @@
apiVersion: v1
kind: Namespace
metadata:
name: adopt-a-street
labels:
app.kubernetes.io/name: adopt-a-street
app.kubernetes.io/part-of: adopt-a-street
environment: production

View File

@@ -1,7 +0,0 @@
apiVersion: v1
data:
.dockerconfigjson: eyJhdXRocyI6eyJnaXRlYS1naXRlYS1odHRwLnRhaWxkYjM0OTQudHMubmV0Ijp7InVzZXJuYW1lIjoid2lsbCIsInBhc3N3b3JkIjoiZnJhY2s2NjYiLCJlbWFpbCI6IndpbGxAd2lsbHMtcG9ydGFsLmNvbSIsImF1dGgiOiJkMmxzYkRwbWNtRmphelkyTmc9PSJ9fX0=
kind: Secret
metadata:
name: regcred
type: kubernetes.io/dockerconfigjson

View File

@@ -2,6 +2,7 @@ apiVersion: v1
kind: Secret
metadata:
name: adopt-a-street-secrets
namespace: adopt-a-street
type: Opaque
stringData:
# JWT Secret - CHANGE THIS IN PRODUCTION!
@@ -12,16 +13,15 @@ stringData:
COUCHDB_PASSWORD: "admin" # Change this in production
COUCHDB_SECRET: "some-random-secret-string" # Change this in production
# Cloudinary Configuration
CLOUDINARY_CLOUD_NAME: "your-cloudinary-cloud-name"
# Cloudinary Configuration (secrets only - non-sensitive values in configmap.yaml)
CLOUDINARY_API_KEY: "your-cloudinary-api-key"
CLOUDINARY_API_SECRET: "your-cloudinary-api-secret"
# Stripe Configuration (optional - currently mocked)
# STRIPE_SECRET_KEY: "your-stripe-secret-key"
STRIPE_SECRET_KEY: "your-stripe-secret-key"
# OpenAI Configuration (optional - for AI features)
# OPENAI_API_KEY: "your-openai-api-key"
OPENAI_API_KEY: "your-openai-api-key"
---
# IMPORTANT:
@@ -30,3 +30,5 @@ stringData:
# 3. DO NOT commit secrets.yaml to version control
# 4. Add secrets.yaml to .gitignore
# 5. Generate strong passwords for CouchDB using: openssl rand -base64 32
# 6. Non-sensitive config values (CLOUDINARY_CLOUD_NAME, STRIPE_PUBLISHABLE_KEY, OPENAI_MODEL)
# are in configmap.yaml