CI/CD with Cellery to update cell instances in the k8s cluster

Asma Zinneera Jabir
wso2-cellery
Published in
5 min readAug 15, 2019

To ensure the speed and reliability of a changing deployment, CI/CD has become an important part and so DevOps engineers have a vital role in ensuring the upgrades/changes are incorporated into the deployment in a swift and automated manner. Therefore, CI/CD has become essential for a reliable deployment and Cellery has integral support for CI/CD and keeps improving to give a smooth ride for DevOps for creating and maintaining deployments.

To set a baseline for this article I shall brief out the terms CI/CD and Cellery.

CI/CD

CI/CD stands for Continuous Integration/Continuous Delivery and the official definitions of these terms are quoted below.

Continuous Integration (CI) is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

Continuous Delivery (CD) is the natural extension of Continuous Integration: an approach in which teams ensure that every change to the system is releasable, and that we can release any version at the push of a button. Continuous Delivery aims to make releases boring, so we can deliver frequently and get fast feedback on what users care about.

Cellery

Cellery is a code-first approach to building, integrating, running and managing composite microservice applications on Kubernetes. Cellery stands as a solution for lengthy yamls and eases out the extend-ability of k8s deployments. Also, it is secure by default and rich with observability, security and tooling. Read the Cellery Documentation to explore more about Cellery. The article is written around the sample hello-world and thus trying out this sample will make it easier to understand this post.

Image Source: https://github.com/wso2-cellery/sdk

As the initial features, Cellery supports CI/CD for updating cell images and for cell testing. For this writing, we shall focus on updating cell images and the cell testing will be discussed in a separate blog post.

Cellery supports updating container image of a running cell instance with a different version which is useful when changes are done in microservices. This writing will give you a kick-start on continuous deployment of cell images into a kubernetes cluster. I have used travis with GitOps to explain the simplicity of updating the changes to the k8s cluster using Cellery. Nonetheless, there is always room to explore and hence you can try out other CI/CD tools and educate us with your experience.

GitOps

GitOps is a productive way of incorporating changes into a k8s deployments. It is a developer friendly methodology for continuous development and deployment. Git is considered to be the single source of truth and any changes added will be set to reflect in the deployment through an automated deployment process.

Travis

Travis is a simple yet powerful continuous integration tool based on Github. Though travis is defined as a CI tool, it also has the ability to perform CD as well.

The example covers how CI/CD can be applied to existing cell based k8s deployment and therefore we need to create a k8s setup in order to test this example.

Setting up a basic Cellery setup with a running cell instance.

  1. Download and Install Cellery
  2. Create a basic cellery setup using the following command
cellery setup create local

3. Build and run the hello-world sample

Build the cell image

cellery build hello-world.bal myorg/hello:1.0.0

Run the built cell image

cellery run myorg/hello:1.0.0 -n foo

4. Configure the host entries correctly as mentioned in the documentation and browse the url http://hello-world.com/. You should see the message Hello World in the browser body.

Steps for creating a CI/CD pipeline for updating cell images

The sample repository used to test this scenario can be found here.

  1. Commit the cell definition ballerina file to the github repository
  2. Create the template for .kube/config file
  3. Create the travis config file
  4. Configure settings in travis for building the repository by setting the appropriate environment variables

Creating the cell definition bal file

A sample cell definition file written using Ballerina can be found here. Commit this file to a github repository.

Creating the .kube/config file

Make sure to keep the values of certificate-authority-data, client-certificate-data and client-key-data fields blank to set in the travis configuration file during the runtime using environment variables and these are sensitive information. Commit this skeleton file also to the the same repository.

Creating the travis yaml file

The travis yaml file should contain the instructions and configs. Travis will spawn a VM according to the configurations provided and run the instructions in the spawned VM.

Travis offers a template for this and the instructions should be saved in a file named .travis.yml and committed to the root level of the git repository.

For our scenario, the .travis.yml should contain the following steps.

Prerequisites/Config

Ballerina

Cellery

Kubectl

.kube/config

Instructions

Cellery build command

This will build the changed cell definition file with a tag different than the previous. I have used the git commit of the travis build.

Cellery update command

This will update the cell image of the running cell instance. Make sure to use the same instance name used when creating the deployment.

The .travis.yml for our scenario is shown below. Commit this file to the root of the github repository.

Configuring travis

Go to build settings and configure general settings and set the environment variables for sensitive fields with encryption.

When a new commit is detected in the git repository, the travis build will run and the cell instance will be updated in the k8s cluster. After the first travis build browse the url http://hello-world.com/ and you should still see the message Hello World in the browser body.

Change the HELLO_NAME environment variable to Cellery in the cell definition bal file and commit it to the github.

envVars: {
HELLO_NAME: { value: “Cellery” }
}

Once the travis build has completed, browse the url http://hello-world.com/ again and you should now see the message being changed to Hello Cellery in the browser body.

Cellery also supports updating the image of a specific component and environment variables attached to the component. refer to them here and feel free to try out and share your thoughts and suggestions.

--

--