-
Notifications
You must be signed in to change notification settings - Fork 0
KUBERNETES
This directory contains Kubernetes manifests for deploying the EpiCalendar application.
- Kubernetes cluster (v1.19+)
- kubectl configured to communicate with your cluster
- NGINX Ingress Controller installed
- cert-manager installed (for automatic TLS certificates)
The application consists of:
- MongoDB: Database (1 replica with persistent storage)
- Server: Backend API (2 replicas)
- Client: Next.js frontend (2 replicas)
- Ingress: Routes traffic to appropriate services
-
namespace.yaml: Creates the epicalendar namespace -
mongodb-pvc.yaml: Persistent volume claim for MongoDB data -
mongodb-secret.yaml: MongoDB credentials -
app-secret.yaml: Application secrets (JWT) -
mongodb-configmap.yaml: MongoDB configuration -
mongodb-deployment.yaml: MongoDB deployment and service -
server-deployment.yaml: Backend API deployment and service -
client-deployment.yaml: Frontend deployment and service -
ingress.yaml: Ingress rules for routing -
kustomization.yaml: Kustomize configuration
Before deploying, update the following files:
- name: CLIENT_URL
value: "https://your-domain.com" # Replace with your actual domain- name: NEXT_PUBLIC_API_URL
value: "https://your-domain.com/api" # Replace with your actual domaintls:
- hosts:
- your-domain.com # Replace with your actual domain
rules:
- host: your-domain.com # Replace with your actual domainFor production, update the secrets with secure values:
stringData:
MONGO_INITDB_ROOT_USERNAME: <secure-username>
MONGO_INITDB_ROOT_PASSWORD: <secure-password>
MONGODB_URI: mongodb://<username>:<password>@mongodb-service:27017/epicalendar?authSource=adminstringData:
JWT_SECRET: <secure-random-string>
JWT_EXPIRATION: 7dApply all manifests using kustomize:
kubectl apply -k kubernetes/Or apply individually:
kubectl apply -f kubernetes/namespace.yaml
kubectl apply -f kubernetes/mongodb-pvc.yaml
kubectl apply -f kubernetes/mongodb-secret.yaml
kubectl apply -f kubernetes/app-secret.yaml
kubectl apply -f kubernetes/mongodb-configmap.yaml
kubectl apply -f kubernetes/mongodb-deployment.yaml
kubectl apply -f kubernetes/server-deployment.yaml
kubectl apply -f kubernetes/client-deployment.yaml
kubectl apply -f kubernetes/ingress.yamlCheck the status of your deployments:
# Check all resources
kubectl get all -n epicalendar
# Check pods status
kubectl get pods -n epicalendar
# Check services
kubectl get svc -n epicalendar
# Check ingress
kubectl get ingress -n epicalendar
# View logs
kubectl logs -f deployment/server -n epicalendar
kubectl logs -f deployment/client -n epicalendar
kubectl logs -f deployment/mongodb -n epicalendarOnce deployed, access your application at https://your-domain.com
Scale deployments as needed:
# Scale server
kubectl scale deployment server --replicas=3 -n epicalendar
# Scale client
kubectl scale deployment client --replicas=3 -n epicalendarTo update the application:
# Update images
kubectl set image deployment/server server=ghcr.io/epitech-nice/epicalendar-server:new-tag -n epicalendar
kubectl set image deployment/client client=ghcr.io/epitech-nice/epicalendar-client:new-tag -n epicalendar
# Or restart to pull latest
kubectl rollout restart deployment/server -n epicalendar
kubectl rollout restart deployment/client -n epicalendarIf you see pod has unbound immediate PersistentVolumeClaims:
# Check PVC status
kubectl get pvc -n epicalendar
# Check available storage classes
kubectl get storageclass
# Describe the PVC to see why it's not binding
kubectl describe pvc mongodb-pvc -n epicalendarSolutions:
-
Delete and recreate the PVC (
⚠️ This will delete MongoDB data!)# Scale down MongoDB to 0 replicas first kubectl scale deployment mongodb --replicas=0 -n epicalendar # Delete the PVC kubectl delete pvc mongodb-pvc -n epicalendar # Reapply with the new storage class kubectl apply -f kubernetes/mongodb-pvc.yaml # Scale MongoDB back up kubectl scale deployment mongodb --replicas=1 -n epicalendar
-
Use the default storage class (if available)
# Check which storage class is default kubectl get storageclass- Remove
storageClassNamefrommongodb-pvc.yamlto use the default - Or update it to match an available storage class name
- Remove
-
For local development/testing (hostPath) Create a simple PersistentVolume manually:
apiVersion: v1 kind: PersistentVolume metadata: name: mongodb-pv spec: capacity: storage: 10Gi accessModes: - ReadWriteOnce hostPath: path: /data/mongodb type: DirectoryOrCreate
Apply:
kubectl apply -f mongodb-pv.yaml -
For cloud providers:
-
GKE: Use
storageClassName: standard-rworpremium-rw -
EKS: Use
storageClassName: gp2orgp3 -
AKS: Use
storageClassName: managedormanaged-premium -
DigitalOcean: Use
storageClassName: do-block-storage
-
GKE: Use
-
Install a storage provisioner (for bare-metal/self-hosted)
# Example: Local Path Provisioner kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml # Then update mongodb-pvc.yaml to use 'local-path'
If you see ImagePullBackOff or ErrImagePull errors:
# Check pod events
kubectl describe pod <pod-name> -n epicalendarCommon causes:
-
Missing image pull secret for private registry (ghcr.io)
- The CI/CD pipeline automatically creates
ghcr-secret - Manually create if needed:
kubectl create secret docker-registry ghcr-secret \ --docker-server=ghcr.io \ --docker-username=<github-username> \ --docker-password=<github-token> \ --docker-email=<email> \ --namespace=epicalendar
- The CI/CD pipeline automatically creates
-
Image doesn't exist or wrong tag
- Verify image exists:
docker pull ghcr.io/epitech-nice/epicalendar-server:latest - Check available tags on GitHub Container Registry
- Verify image exists:
-
Registry authentication issues
- Ensure GitHub token has
read:packagespermission - For GitHub Actions,
GITHUB_TOKENis provided automatically
- Ensure GitHub token has
kubectl logs <pod-name> -n epicalendar
kubectl logs <pod-name> -n epicalendar --previous # Previous container logsIf deployment rollout times out:
# Check rollout status
kubectl rollout status deployment/server -n epicalendar
kubectl rollout status deployment/client -n epicalendar
# Check why pods are failing
kubectl get pods -n epicalendar
kubectl describe pod <failing-pod> -n epicalendar
# Rollback if needed
kubectl rollout undo deployment/server -n epicalendarkubectl describe pod <pod-name> -n epicalendar
kubectl describe deployment <deployment-name> -n epicalendarkubectl exec -it <pod-name> -n epicalendar -- /bin/shkubectl get events -n epicalendar --sort-by='.lastTimestamp'To remove all resources:
kubectl delete namespace epicalendarOr individually:
kubectl delete -k kubernetes/-
Storage Requirements:
- PersistentVolume storage class needs to be configured for your cluster
- Default
storageClassNameis commented out inmongodb-pvc.yaml - Update based on your cluster provider (see Troubleshooting section)
- For testing: consider using hostPath PV or local-path-provisioner
- Resource limits are conservative. Adjust based on your workload.
- Health checks are configured for server and client with appropriate delays.
- TLS is managed by cert-manager with Let's Encrypt.