Scenario: A developer wants to deploy bundles for a weather application using Timoni. In this example, we will walk through the process of creating a Timoni bundle for a weather application and deploying it to a Kubernetes cluster.
First, let’s create a new directory for our weather application and initialize a new Timoni module:
$ mkdir weather-app
$ cd weather-app
$ timoni mod init weather-app
Next, let’s create a values.cue
file to define the values for our application:
apiVersion: v1alpha1
kind: Values
metadata:
name: weather-app-values
values:
replicas: 3
image:
repository: stefanprodan/weather-app
tag: v1.0.0
service:
type: ClusterIP
port: 80
Now, let’s create a timoni.cue
file to define the entry point for our module:
apiVersion: v1alpha1
kind: Timoni
metadata:
name: weather-app
values:
- import "./values.cue"
- apiVersion: apps/v1
- kind: Deployment
- metadata:
name: weather-app
labels:
app: weather-app
- spec:
replicas: ${values.replicas}
selector:
matchLabels:
app: weather-app
template:
metadata:
labels:
app: weather-app
spec:
containers:
- name: weather-app
image: ${values.image.repository}:${values.image.tag}
ports:
- containerPort: ${values.service.port}
Next, let’s create a bundle.cue
file to define the bundle:
apiVersion: v1alpha1
kind: Bundle
metadata:
name: weather-app-bundle
instances:
- name: weather-app
module:
url: .
version: v1
namespace: weather-app
values: ${file("values.cue")}
Now, let’s build and lint our bundle:
$ timoni bundle build -f bundle.cue
$ timoni bundle lint -f bundle.cue
Assuming the bundle builds and lints successfully, we can now deploy it to our Kubernetes cluster using the timoni bundle apply
command:
$ timoni bundle apply -f bundle.cue
This command will create a new deployment, service, and namespace for our weather application in the cluster.
To verify the deployment, we can use the kubectl
command-line tool:
$ kubectl get deployments
NAME READY UP-TO-DATE AVAILABLE AGE
weather-app 3/3 3 3 1m
$ kubectl get services
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 2d1h
weather-app ClusterIP 10.100.123.123 <none> 80/TCP 1m
We can also verify that the deployment is running by checking the logs:
$ kubectl logs weather-app-<pod-name>
Replace <pod-name>
with the name of one of the running pods.
Tests:
- Verify that the bundle builds and lints successfully:
$ timoni bundle build -f bundle.cue
$ timoni bundle lint -f bundle.cue
- Verify that the bundle is applied successfully:
$ timoni bundle apply -f bundle.cue
- Verify that the deployment is running:
$ kubectl get deployments
$ kubectl get services
$ kubectl logs weather-app-<pod-name>