Deploy to Kubernetes
Kubernetes Deployment
Section titled “Kubernetes Deployment”Deploy your Jac application to Kubernetes with a single command.
Prerequisites
- Completed: Local API Server
- Kubernetes cluster running (minikube, Docker Desktop, or cloud provider)
kubectlconfigured- jac-scale installed:
pip install jac-scale- Time: ~10 minutes
Overview
Section titled “Overview”jac start --scale handles everything automatically:
- Deploys your application to Kubernetes
- Auto-provisions Redis (caching) and MongoDB (persistence)
- Creates all necessary Kubernetes resources
- Exposes your application via NodePort
graph TD subgraph cluster["Kubernetes Cluster (Auto-Created)"] subgraph app["Application"] P1["Pod: jac-app"] end subgraph data["Data Layer (Auto-Provisioned)"] R["Redis<br/>Caching"] M["MongoDB<br/>Persistence"] end P1 --> R P1 --> M end LB["NodePort :30001"] --> P1Quick Start
Section titled “Quick Start”1. Prepare Your Application
Section titled “1. Prepare Your Application”# app.jacnode Todo { has title: str; has done: bool = False;}
walker:pub add_todo { has title: str;
can create with Root entry { todo = here ++> Todo(title=self.title); report {"id": todo[0].id, "title": todo[0].title}; }}
walker:pub list_todos { can fetch with Root entry { todos = [-->](?:Todo); report [{"id": t.id, "title": t.title, "done": t.done} for t in todos]; }}
walker:pub health { can check with Root entry { report {"status": "healthy"}; }}2. Deploy to Kubernetes
Section titled “2. Deploy to Kubernetes”jac start app.jac --scaleThat’s it. Your application is now running on Kubernetes.
Access your application:
- API: http://localhost:30001
- Swagger docs: http://localhost:30001/docs
Deployment Modes
Section titled “Deployment Modes”Development Mode (Default)
Section titled “Development Mode (Default)”Deploys without building a Docker image. Fastest for iteration.
jac start app.jac --scaleProduction Mode
Section titled “Production Mode”Builds a Docker image and pushes to DockerHub before deploying.
jac start app.jac --scale --buildRequirements for production mode:
Create a .env file with your Docker credentials:
DOCKER_USERNAME=your-dockerhub-usernameDOCKER_PASSWORD=your-dockerhub-password-or-tokenConfiguration
Section titled “Configuration”Configure deployment via environment variables in .env:
Application Settings
Section titled “Application Settings”| Variable | Description | Default |
|---|---|---|
APP_NAME | Name of your application | jaseci |
K8s_NAMESPACE | Kubernetes namespace | default |
K8s_NODE_PORT | Port for accessing the app | 30001 |
Resource Limits
Section titled “Resource Limits”| Variable | Description | Default |
|---|---|---|
K8s_CPU_REQUEST | CPU request | - |
K8s_CPU_LIMIT | CPU limit | - |
K8s_MEMORY_REQUEST | Memory request | - |
K8s_MEMORY_LIMIT | Memory limit | - |
Health Checks
Section titled “Health Checks”| Variable | Description | Default |
|---|---|---|
K8s_READINESS_INITIAL_DELAY | Readiness probe delay (seconds) | 10 |
K8s_READINESS_PERIOD | Readiness probe interval | 20 |
K8s_LIVENESS_INITIAL_DELAY | Liveness probe delay (seconds) | 10 |
K8s_LIVENESS_PERIOD | Liveness probe interval | 20 |
Database Options
Section titled “Database Options”| Variable | Description | Default |
|---|---|---|
K8s_MONGODB | Enable MongoDB | True |
K8s_REDIS | Enable Redis | True |
MONGODB_URI | External MongoDB URL | Auto-provisioned |
REDIS_URL | External Redis URL | Auto-provisioned |
Authentication
Section titled “Authentication”| Variable | Description | Default |
|---|---|---|
JWT_SECRET | JWT signing key | Auto-generated |
JWT_EXP_DELTA_DAYS | Token expiration (days) | 7 |
SSO_GOOGLE_CLIENT_ID | Google OAuth client ID | - |
SSO_GOOGLE_CLIENT_SECRET | Google OAuth secret | - |
Managing Your Deployment
Section titled “Managing Your Deployment”Check Status
Section titled “Check Status”kubectl get podskubectl get servicesView Logs
Section titled “View Logs”kubectl logs -l app=jaseci -fClean Up
Section titled “Clean Up”Remove all Kubernetes resources created by jac-scale:
jac destroy app.jacThis removes:
- Application deployments and pods
- Redis and MongoDB StatefulSets
- Services and persistent volumes
- ConfigMaps and secrets
How It Works
Section titled “How It Works”When you run jac start --scale, the following happens automatically:
- Namespace Setup - Creates or uses the specified Kubernetes namespace
- Database Provisioning - Deploys Redis and MongoDB as StatefulSets with persistent storage (first run only)
- Application Deployment - Creates a deployment for your Jac application
- Service Exposure - Exposes the application via NodePort
Subsequent deployments only update the application - databases persist across deployments.
Setting Up Kubernetes
Section titled “Setting Up Kubernetes”Option A: Docker Desktop (Easiest)
Section titled “Option A: Docker Desktop (Easiest)”- Install Docker Desktop
- Open Settings > Kubernetes
- Check “Enable Kubernetes”
- Click “Apply & Restart”
Option B: Minikube
Section titled “Option B: Minikube”# Install minikubebrew install minikube # macOS# or see https://minikube.sigs.k8s.io/docs/start/
# Start clusterminikube start
# For minikube, access via:minikube service jaseci -n defaultOption C: MicroK8s (Linux)
Section titled “Option C: MicroK8s (Linux)”sudo snap install microk8s --classicmicrok8s enable dns storagealias kubectl='microk8s kubectl'Troubleshooting
Section titled “Troubleshooting”Application not accessible
Section titled “Application not accessible”# Check pod statuskubectl get pods
# Check servicekubectl get svc
# For minikube, use tunnelminikube service jaseciDatabase connection issues
Section titled “Database connection issues”# Check StatefulSetskubectl get statefulsets
# Check persistent volumeskubectl get pvc
# View database logskubectl logs -l app=mongodbkubectl logs -l app=redisBuild failures (—build mode)
Section titled “Build failures (—build mode)”- Ensure Docker daemon is running
- Verify
.envhas correctDOCKER_USERNAMEandDOCKER_PASSWORD - Check disk space for image building
General debugging
Section titled “General debugging”# Describe a pod for eventskubectl describe pod <pod-name>
# Get all resourceskubectl get all
# Check eventskubectl get events --sort-by='.lastTimestamp'Example: Full-Stack App with Auth
Section titled “Example: Full-Stack App with Auth”# Create a new full-stack projectjac create todo --use clientcd todo
# Deploy to Kubernetesjac start app.jac --scaleAccess:
- Frontend: http://localhost:30001/cl/app
- Backend API: http://localhost:30001
- Swagger docs: http://localhost:30001/docs
Next Steps
Section titled “Next Steps”- Local API Server - Development without Kubernetes
- Authentication - Add user authentication
- jac-scale Reference - Full configuration options