Scenario: A developer wants to configure the Timoni CLI for a fitness tracker application. The fitness tracker application will utilize Timoni to manage and deploy Kubernetes objects based on user-supplied values. In this guide, we will walk through the process of configuring the Timoni CLI for this application.
First, let’s familiarize ourselves with the Timoni project structure and documentation:
- Familiarize with the Timoni project: https://github.com/stefanprodan/timoni
- Understand the module structure: https://github.com/stefanprodan/timoni#module-structure
- Learn about Timoni bundles: https://github.com/stefanprodan/timoni#timoni-bundles
Now, let’s configure the CLI for our fitness tracker application.
Step 1: Initialize a new local Timoni module
To initialize a new local Timoni module, navigate to the desired directory and run the following command:
timoni mod init <module-name>
Replace <module-name>
with the desired name for your fitness tracker module.
Step 2: Set up the module structure
Create the following files and directories in your new module:
touch README.md
mkdir cue
touch cue/module.cue
mkdir pkg
touch pkg/timoni.cue
touch pkg/timoni.ignore
mkdir templates
touch templates/config.cue
touch templates/deployment.cue
touch templates/service.cue
touch values.cue
Step 3: Configure the module metadata (cue/module.cue)
Edit the cue/module.cue
file to include the module name and version:
name: "<module-name>"
version: "0.1.0"
Step 4: Define the module entry point (pkg/timoni.cue)
Edit the pkg/timoni.cue
file to import the Timoni API:
import "github.com/stefanprodan/timoni/api/v1alpha1"
Step 5: Define the module ignore rules (pkg/timoni.ignore)
Edit the pkg/timoni.ignore
file to ignore unnecessary files:
node_modules
*.log
Step 6: Define the module values (values.cue)
Edit the values.cue
file to define any required values for your fitness tracker application:
replicas: 3
image: "<image-name>:<image-tag>"
Replace <image-name>
and <image-tag>
with the appropriate values for your fitness tracker application’s container image.
Step 7: Define the module templates
Edit the templates/config.cue
, templates/deployment.cue
, and templates/service.cue
files to define the Kubernetes objects for your fitness tracker application.
Step 8: Configure the fitness tracker application values
Create a new file named values-fitness-tracker.cue
in the values.d
directory:
replicas: 3
image: "<image-name>:<image-tag>"
Replace <image-name>
and <image-tag>
with the appropriate values for your fitness tracker application’s container image.
Step 9: Configure the fitness tracker application bundle
Create a new file named bundle.cue
in the root directory of your module:
apiVersion: v1alpha1
name: fitness-tracker
instances:
fitnessTracker:
module:
url: "oci://<registry>/<module-name>:<version>"
namespace: fitness-tracker
values:
${import "values-fitness-tracker.cue"}
Replace <registry>
with the appropriate container registry URL and <module-name>
and <version>
with the name and version of your fitness tracker module.
Step 10: Lint and build the module
To lint and build your module, run the following commands:
timoni mod lint .
timoni bundle build -f bundle.cue
Tests:
To verify the configuration, you can run the following tests:
- Lint the module:
timoni mod lint .
- Build the module:
timoni bundle build -f bundle.cue
- Apply the bundle:
timoni bundle apply -f bundle.cue
- Inspect the deployed resources:
timoni inspect resources
- Delete the resources:
timoni delete -f
These tests will ensure that your fitness tracker application is correctly configured and deployed using Timoni.