struct

RailsApp

Inherits YAML::Serializable / JSON::Serializable / Kubernetes::Serializable / Struct / Value / Object

The RailsApp represents the resource being specified. It is the spec in the Kubernetes YAML.

This resource comprises several different resources:

  • Deployment per entrypoint
  • Service for each entrypoint with a port specified
  • Ingress for each entrypoint with a domain specified
  • Certificate (via CertManager) for each entrypoint with a domain specified
  • Job for before_create (automatically GCed upon completion)
  • Job for before_update (automatically GCed upon completion)

NOTE: despite this being called a RailsApp, it's not only for Ruby on Rails apps. It was designed for them originally, but it quickly became useful for much more than apps built with that framework.

Example:

---
apiVersion: jgaskins.dev/v1beta1
kind: RailsApp
metadata:
  name: my-rails-app
spec:
  image: repo/image:tag
  env:
  - name: RAILS_ENV
    value: production
  - name: DATABASE_URL
    value: postgres://user:password@host/db
  - name: REDIS_URL
    value: redis://redis

  entrypoints:
  - name: web                    # Pods will be called `my-rails-app-web-*-*`
    domain: example.com          # The domain people will use to reach your app
    port: 3000                   # What port the server listens on
    command: [bin/rails, server] # Run the Rails server
  - name: worker                 # Pods will be called `my-rails-app-worker-*-*`
    command: [bin/sidekiq]       # Run the Sidekiq job processor

  before_create:
    command: [bin/rails, db:schema:load]
  before_update:
    command: [bin/rails, db:migrate]

Constructors

new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
new(pull : JSON::PullParser)
new(*, __pull_for_json_serializable pull : JSON::PullParser)
new(*, __context_for_yaml_serializable ctx : YAML::ParseContext, __node_for_yaml_serializable node : YAML::Nodes::Node)
new(*, image : String, image_pull_policy : String = "IfNotPresent", image_pull_secrets : Array(String) = Array(String).new, env_from : Array(RailsApp::EnvFrom) = Array(EnvFrom).new, env : Array(RailsApp::Env) = Array(Env).new, node_selector : Hash(String, JSON::Any) = {} of String => JSON::Any, directories : Array(RailsApp::Directories) = Array(Directories).new, annotations : Hash(String, JSON::Any) = {} of String => JSON::Any, entrypoints : Array(RailsApp::Entrypoints), before_create : RailsApp::BeforeCreate, before_update : RailsApp::BeforeUpdate, service_account : Nil | String = nil)
Source

Instance methods

annotations
before_create

When the RailsApp is created, this job is executed. Usually this is used to provision the database schema.

before_update

When the RailsApp is updated, this job is executed. Usually this is used to run database schema and data migrations.

directories

Create directories on the container's filesystem

directories:
  - path: /containing/path
    name: config
    files:
      - filename: app.yml
        content: |
          production:
            database: postgres://user:password@host/db_name
            redis: redis://redis
entrypoints

The entrypoints for your application — each type of process you run, such as a Rails server and Sidekiq, is a separate entrypoint. This is similar to entries in a Procfile.

env

A list of Env objects representing environment variables. Either a value or value_from (in YAML: valueFrom) must be provided.

env:
  - name: REDIS_URL
    value: redis://redis
  - name: DATABASE_URL
    valueFrom:
      secretKeyRef:
        name: "postgres-app"
        value: "uri"
env_from

The source of an environment variable, such as a ConfigMap or Secret.

image

The image tag to use by default for all entrypoints in this RailsApp

image_pull_policy

Describes how images are pulled: Always pulls a fresh container image each time and IfNotPresent will pull a container image once and keep it cached. Use Always if your container images use mutable tags, such as latest.

image_pull_secrets

The name of the secret that contains container-registry credentials, allowing Kubernetes to pull the image from its repo. For more information, see the Kubernetes documentation on pulling images from a private registry.

node_selector

A Hash(String, String) containing label/value pairs — pods for this RailsApp or Entrypoints will only be assigned to nodes that have these labels. For example, if you set kubernetes.io/arch: arm64 here, pods will only be assigned to nodes running Arm64 processors.

service_account

Use the given Kubernetes ServiceAccount to run pods for this app. This is extremely rare to need to set, so if you don't know what to set here, you almost certainly want to leave it blank.

Nested types