Configuration
Overview
In the Application Hub, configuration is vital for defining Kubernetes objects through YAML files, ensuring consistent and scalable deployments. This approach allows users to specify the desired state of resources, with Kubernetes managing the necessary adjustments to align with this state.
Developing Kubernetes manifests or configuring the cluster using YAML files can be challenging and prone to errors. To simplify this process, a Python-based configuration generator can be used to produce clean, well-structured YAML files. This reduces the risk of misconfiguration and improves maintainability. Users can programmatically define and customize various Kubernetes resources(e.g.Pods, Volumes, and ConfigMaps), well as handling the External Secrets Operator, define profiles, and manage Helm releases. This approach offers flexibility and empowers users to tailor deployments to their specific requirements.
Apphub-configurator
The Configuration Generator is a Python module designed to facilitate the creation of configuration files for Application Hub deployments. It offers various utilities to streamline the configuration process.
Python utilities:
-
load_config_map(name, key, file_name, mount_path)
: Reads a specified file and returns aConfigMap
object with the file's content, intended for use within Kubernetes configurations. -
load_manifests(name, key, file_path)
: Loads a YAML file containing Kubernetes manifests and returns aManifest
object. This is useful for deploying one or multiple Kubernetes objects, such as Roles, RoleBindings, ServiceAccounts, and Releases. -
create_init_container(image, volume, mount_path)
: Sets up an init container that executes specified commands during pod initialization. -
load_init_script(file_name)
: Loads a bash script intended for pod initialization and returns aConfigMap
object.
By utilizing these utilities, users can efficiently generate and manage configuration files, ensuring consistent and scalable deployments within the Application Hub environment.
Kubernetes Object Data Classes
The module defines several Pydantic-based data classes representing Kubernetes objects, facilitating structured and validated configuration management:
-
ConfigMapKeyRef
: Represents a reference to a specific key within a Kubernetes ConfigMap, including thename
of the ConfigMap and thekey
within it. -
ConfigMapEnvVarReference
: Encapsulates a reference to a ConfigMap key, used to define environment variables in Kubernetes pods sourced from ConfigMap data. -
SubjectKind
: An enumeration specifying the type of subject (e.g.,ServiceAccount
,User
) for role-based access control (RBAC) configurations. -
Verb
: An enumeration listing the allowed actions (e.g.,get
,list
,create
) for RBAC roles and role bindings. -
Subject
: Defines a subject in RBAC, comprising aname
and akind
(type). -
Role
: Represents a Kubernetes Role, detailing thename
, a list ofresources
it governs, permissibleverbs
(actions), and optionalapi_groups
. -
RoleBinding
: Binds aRole
to specificsubjects
, assigning the defined permissions within a namespace. It includes aname
, a list ofsubjects
, the associatedrole
, and apersist
flag indicating whether the binding should be saved. -
VolumeMount
: Specifies how a volume is mounted into a pod, detailing thename
of the volume and themount_path
within the container's filesystem. -
InitContainerVolumeMount
: ExtendsVolumeMount
by adding asub_path
, allowing a specific file or directory within the volume to be mounted at the desired path. -
Volume
: Describes a Kubernetes volume, including itsname
,claim_name
for persistent volumes,size
,storage_class
,access_modes
, an associatedvolume_mount
, and apersist
flag. -
Manifest
: Represents a collection of Kubernetes objects, encompassing aname
, akey
, optionalcontent
(a list of dictionaries representing Kubernetes resources), and apersist
flag. -
ConfigMap
: Defines a Kubernetes ConfigMap, including aname
,key
, optionalmount_path
for mounting the ConfigMap as a file, an optionaldefault_mode
for file permissions, areadonly
flag, optionalcontent
, and apersist
flag. -
KubespawnerOverride
: Allows customization of Kubernetes spawner settings for JupyterHub, specifying resource limits and guarantees such ascpu_limit
, optionalcpu_guarantee
,mem_limit
, optionalmem_guarantee
,image
, and dictionaries forextra_resource_limits
andextra_resource_guarantees
. -
InitContainer
: Details an initialization container within a pod, specifying itsname
,image
, a list ofcommand
arguments to execute, and a list ofvolume_mounts
(which can be eitherVolumeMount
orInitContainerVolumeMount
). -
ProfileDefinition
: Describes a user profile within the Application-Hub, including adisplay_name
, an optionaldescription
, aslug
for identification, adefault
flag, andkubespawner_override
settings. -
ImagePullSecret
: Represents a secret used for pulling container images, including aname
, apersist
flag, and optionaldata
(e.g., authentication credentials). -
SecretMount
: Specifies a secret to be mounted into a pod, detailing thename
of the secret, themount_path
within the container, an optionalsub_path
to a specific file within the secret, and adefault_mode
for file permissions. -
Profile
: Encapsulates a user profile, including anid
, a list ofgroups
the user belongs to, adefinition
(of typeProfileDefinition
), optional lists ofconfig_maps
andvolumes
, optional environment variable settings (pod_env_vars
), optionaldefault_url
,node_selector
for pod scheduling, optionalrole_bindings
,image_pull_secrets
,init_containers
,manifests
, environment variables sourced from ConfigMaps and Secrets, and optionalsecret_mounts
. -
Config
: Serves as the root configuration object, containing a list ofprofiles
(of typeProfile
).
These data classes provide a structured approach to defining Kubernetes resources.
Examples:
The user can follow the examples provided to setup different profiles on Application Hub through the provided notebook under example folder. In the notebook, the user is able to configure different profile including:
-
Coder
-
Coder with a init.sh
-
Jupyter Lab
-
JupyterLab Plus
-
E-learning
-
QGIS
Output format:
The apphub-configurator
package generates a config.yaml
file to define various profiles for your application deployment. Each profile includes several key attributes that need to be configured:
- id: the profile identifier of your app
- groups: the group list containing the users groups that can use the declared app
- definition: display name, reference slug identifying the app, cpu/ram requirements alloted for it, reference docker image for the app-level
- config-maps: definition of env variables expressed as '
: ' or config/secret files together with their mount_path, access, default_mode - volumes: handle the volumes, their persistency, their kubernetes access type (e.g. ReadWriteOnce, ReadWriteMany, ...), their size claim and their mount_path
- pod_env_vars: Handle the environment variables for the pod.
- default_url: default uri where to find the app
- node_selector: identifies on which node pool the app is executed
- role_bindings: A list of
RoleBinding
objects that associate users or groups with specific roles within the Kubernetes cluster, controlling access to resources. - image_pull_secrets: A list of
ImagePullSecret
objects containing credentials for pulling private Docker images required by the application. - init_containers: A list of
InitContainer
objects specifying containers that run before the main application containers, typically used for initialization tasks. - manifests: A list of
Manifest
objects representing Kubernetes manifests to be applied during deployment, allowing for the creation and management of various Kubernetes resources. - env_from_config_maps: A list of strings specifying the names of ConfigMaps whose data should be exposed as environment variables to the application pods.
- env_from_secrets: A list of strings specifying the names of Secrets whose data should be exposed as environment variables to the application pods.
- secret_mounts: A list of
SecretMount
objects defining Secrets to be mounted as files within the application pods, providing secure storage for sensitive data.