struct RailsApp
- RailsApp
- Struct
- Value
- Object
Overview
The RailsApp represents the resource being specified. It is the spec in the Kubernetes YAML.
This resource comprises several different resources:
DeploymentperentrypointServicefor eachentrypointwith aportspecifiedIngressfor eachentrypointwith adomainspecifiedCertificate(via CertManager) for eachentrypointwith adomainspecifiedJobfor#before_create(automatically GCed upon completion)Jobfor#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]
Included Modules
- JSON::Serializable
- Kubernetes::Serializable
- YAML::Serializable
Defined in:
rails_app_operator.crConstructors
- .new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
- .new(pull : JSON::PullParser)
- .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)
Instance Method Summary
- #annotations : Hash(String, JSON::Any)
-
#before_create : BeforeCreate
When the
RailsAppis created, this job is executed. -
#before_update : BeforeUpdate
When the
RailsAppis updated, this job is executed. -
#directories : Array(Directories)
Create directories on the container's filesystem
-
#entrypoints : Array(Entrypoints)
The entrypoints for your application — each type of process you run, such as a Rails server and Sidekiq, is a separate entrypoint.
-
#env : Array(Env)
A list of
Envobjects representing environment variables. -
#env_from : Array(EnvFrom)
The source of an environment variable, such as a
ConfigMaporSecret. -
#image : String
The image tag to use by default for all entrypoints in this
RailsApp -
#image_pull_policy : String
Describes how images are pulled:
Alwayspulls a fresh container image each time andIfNotPresentwill pull a container image once and keep it cached. -
#image_pull_secrets : Array(String)
The name of the secret that contains container-registry credentials, allowing Kubernetes to pull the image from its repo.
-
#node_selector : Hash(String, JSON::Any)
A
Hash(String, String)containing label/value pairs — pods for thisRailsApporEntrypointswill only be assigned to nodes that have these labels. -
#service_account : String | Nil
Use the given Kubernetes
ServiceAccountto run pods for this app.
Constructor Detail
Instance Method Detail
When the RailsApp is created, this job is executed. Usually this is used to provision the database schema.
When the RailsApp is updated, this job is executed. Usually this is used to run database schema and data migrations.
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
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.
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"
The source of an environment variable, such as a ConfigMap or Secret.
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.
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.
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.
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.