struct RailsApp::Entrypoints

Overview

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.

Included Modules

Defined in:

rails_app_operator.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

def self.new(pull : JSON::PullParser) #

def self.new(*, name : String, image : Nil | String = nil, command : Nil | Array(String) = nil, port : Int64 | Nil = nil, domain : Nil | String = nil, path : String = "/", path_type : RailsApp::Entrypoints::PathType = "Prefix", replicas : Int64 = 1, deployment_strategy : RailsApp::Entrypoints::DeploymentStrategy = {} of String => JSON::Any, resources : RailsApp::Entrypoints::Resources | Nil = nil, node_selector : Hash(String, JSON::Any) = {} of String => JSON::Any, annotations : Hash(String, JSON::Any) = {} of String => JSON::Any, health_check : RailsApp::Entrypoints::HealthCheck | Nil = nil, ingress : RailsApp::Entrypoints::Ingress | Nil = nil, env_from : Array(RailsApp::Entrypoints::EnvFrom) = Array(EnvFrom).new, env : Array(RailsApp::Entrypoints::Env) = Array(Env).new, service_account : Nil | String = nil) #

[View source]

Instance Method Detail

def annotations : Hash(String, JSON::Any) #

def command : Array(String) | Nil #

Optional override for the command to run to run this entrypoint if it differs from the CMD directive in your container image. For example, to run Sidekiq:

command: [bundle, exec, sidekiq]

def deployment_strategy : DeploymentStrategy #

The strategy to use when updating this entrypoint, useful for slow canary rollouts.

When you need to deploy your app safely, it can be best to roll it out slowly over several minutes. If your first few pods fail health checks, the deployment will pause. You can then use kubectl rollout undo deployment in your deployment script to roll the deployment back.

How those health checks fail is specific to your app, but a useful pattern is for the pod to track the number of failures (for example, the number of HTTP 500s or exceptions raised in background jobs) as a percentage of all units of work since the pod started and, when that number exceeds some threshold (for example, 5%), return a failure response for the health check.

deployment_strategy:
  duration_minutes: 10
  surge: 5%
  max_unavailable: 0%

WARNING This is an experimental property and is subject to change.


def domain : String | Nil #

The domain your app should be accessible on. This will provision Ingress and Certificate resources so that this entrypoint will be reachable via the public internet. Without this property, it will only be accessible via plaintext inside the cluster.


def env : Array(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"

def env_from : Array(EnvFrom) #

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


def health_check : HealthCheck | Nil #

HTTP health checks to ensure 2 things:

  1. New pods must pass these health checks before old pods are terminated
  2. Pods will be checked on the run_every interval to make sure it's still alive. If it fails failure_threshold times, the pod will be restarted. If it continues to fail, it will enter a CrashLoopBackOff state.

def image : String | Nil #

Optional override for the container image for this entrypoint if it differs from the rest of your app. This is useful when you want to deploy something to support your app, such as a Prometheus exporter.


def ingress : Ingress | Nil #

Properties to assign to any Ingress that gets created for this entrypoint.


def name : String #

The name of your entrypoint, such as web or worker


def node_selector : Hash(String, JSON::Any) #

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.


def path : String #

The path matcher for the Ingress resource, defaults to "/". All incoming requests from outside the cluster with this entrypoint's #domain and #path will be routed to this entrypoint.


def path_type : PathType #

Defines the way the #path is matched, defaulting to Prefix.

  • Prefix matches any request path that starts with #path
  • Exact matches only that exact path
  • ImplementationSpecific depends on the Kubernetes IngressClass. This operator uses nginx as the IngressClass, which ImplementationSpecific here.
entrypoints:
- name: web
  domain: example.com
  path: /

def port : Int64 | Nil #

The port your entrypoint will be listening on. This will provision a Service resource so the entrypoint will be reachable from inside the Kubernetes cluster.


def replicas : Int64 #

The number of pods to run for this entrypoint, defaulting to 1.


def resources : Resources | Nil #

The resources you want to allocate for each pod and/or limit each pod to.


def service_account : String | Nil #

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.