Skip to main content
This guide will walk you through creating a complete deployment configuration with Kittyhawk, including a React frontend, Django backend, Redis instance, and a scheduled cron job.

Create Your First Chart

1

Import Kittyhawk constructs

In your main.ts file, import the necessary constructs from Kittyhawk:
import { Construct } from 'constructs';
import { 
  PennLabsChart, 
  ReactApplication, 
  DjangoApplication, 
  RedisApplication, 
  CronJob 
} from '@pennlabs/kittyhawk';

const cronTime = require('cron-time-generator');
2

Create a PennLabsChart

Extend the PennLabsChart class to create your deployment configuration:
export class ExampleChart extends PennLabsChart {
  constructor(scope: Construct) {
    super(scope);

    // Configuration will go here
  }
}
3

Define your application images and configuration

Set up the basic configuration variables:
const backendImage = 'pennlabs/example-backend';
const frontendImage = 'pennlabs/examplefrontend';
const secret = 'secret';
const domain = 'domain';
4

Add a Redis instance

Deploy a Redis instance for caching or session storage:
new RedisApplication(this, 'redis', {});
5

Deploy your Django backend

Configure your Django application with ASGI support:
new DjangoApplication(this, 'django-asgi', {
  deployment: {
    image: backendImage,
    cmd: ['/usr/local/bin/asgi-run'],
    replicas: 2,
    secret: secret,
    env: [
      { name: 'REDIS_HOST', value: 'redis' },
    ],
  },
  djangoSettingsModule: 'example.settings.production',
  domains: [{ host: domain, paths: ['/api/ws'] }],
});
6

Deploy your React frontend

Configure your React application:
new ReactApplication(this, 'react', {
  deployment: {
    image: frontendImage,
    replicas: 2,
  },
  domain: { host: domain, paths: ['/'] },
  portEnv: '80',
});
7

Add a scheduled cron job

Create a cron job that runs daily at 8 AM:
new CronJob(this, 'example-cronjob', {
  schedule: cronTime.everyDayAt(8),
  image: backendImage,
  secret: secret,
  cmd: ['your', 'command'],
});

Complete Example

Here’s the complete main.ts file combining all the steps above:
import { Construct } from 'constructs';
import { PennLabsChart, ReactApplication, DjangoApplication, RedisApplication, CronJob } from '@pennlabs/kittyhawk';

const cronTime = require('cron-time-generator');

export class ExampleChart extends PennLabsChart {
  constructor(scope: Construct) {
    super(scope);

    const backendImage = 'pennlabs/example-backend';
    const frontendImage = 'pennlabs/examplefrontend';

    const secret = 'secret';
    const domain = 'domain';

    new RedisApplication(this, 'redis', {});

    new DjangoApplication(this, 'django-asgi', {
      deployment: {
        image: backendImage,
        cmd: ['/usr/local/bin/asgi-run'],
        replicas: 2,
        secret: secret,
        env: [
          { name: 'REDIS_HOST', value: 'redis' },
        ],
      },
      djangoSettingsModule: 'example.settings.production',
      domains: [{ host: domain, paths: ['/api/ws'] }],
    });

    new ReactApplication(this, 'react', {
      deployment: {
        image: frontendImage,
        replicas: 2,
      },
      domain: { host: domain, paths: ['/'] },
      portEnv: '80',
    });

    /** Cronjobs **/
    new CronJob(this, 'example-cronjob', {
      schedule: cronTime.everyDayAt(8),
      image: backendImage,
      secret: secret,
      cmd: ['your', 'command'],
    });
  }
}

Generating YAML (Local Testing)

You should NOT generate YAML manually for production. YAML generation should be handled by your CI/CD pipeline via Kraken.
For local testing only, you can generate YAML:
  1. Navigate to your k8s directory:
    cd k8s
    
  2. Set required environment variables:
    export RELEASE_NAME="your-app-name"
    export GIT_SHA="$(git rev-parse HEAD)"
    
  3. Generate the YAML:
    yarn compile && yarn synth
    
  4. Find the generated YAML in the dist folder:
    ls dist/
    # Output: RELEASE_NAME.k8s.yaml
    

CI/CD Integration

In production, the DeployJob in Kraken handles YAML generation automatically. For more information, see the Kraken documentation.

Next Steps

API Reference

Explore the full Kittyhawk API documentation

Kraken Integration

Learn how to integrate with Penn Labs’ CI/CD pipeline

Build docs developers (and LLMs) love