qbec — The deployment tool for multiple kubernetes environments

Harsimran Singh Maan
ITNEXT
Published in
4 min readJul 24, 2020

--

DevOps engineers and Kubernetes admins often need to deploy their applications and services to multiple environments. Depending on the setup, an environment could mean a Kubernetes cluster or a namespace in the same cluster or a combination of namespaces spread across clusters. There could be multiple motivations to deploy to different environments. Isolating test environment from production and multi-region(including multi-cloud) deployments are some common examples of multiple environment setup.

The Kubernetes ecosystem has many tools that help developers to deploy an application. If you go through the Kubernetes documentation, you’ll see examples and snippets of YAML files that can be used to create or update Kubernetes objects. Deployments, services, config-maps and secrets are among the most commonly used Kubernetes objects. Managing YAML files can become increasingly complex as the application grows. Jsonnet has emerged as an elegant way of managing this complexity. The overall workflow is further simplified when using qbec.

qbec — pronounced “Quebec” (the Canadian province) is a tool to configure and create Kubernetes objects on multiple environments. The origin of the name qbec has some history to it. According to the creator of qbec, Krishnan Anantheswaran — “I was tired of all my k8s tools beginning with k and getting in the way of tab completion. Also, I wanted a city name (qbec -> Quebec [city]) because I had another OSS tool (that I don’t maintain any more but lives on through other people) called istanbul that was wildly successful”.

The qbec logo
qbec logo (Credits: https://qbec.io)

qbec is a standalone client tool. It does not require running any complementary server components in the Kubernetes cluster or elsewhere.

In this series, we’ll take a look at various features of qbec and how it can be used for a variety of use cases ranging from deployments, pre-deployment tooling to catch common mistakes, garbage collection, and CI/CD workflows.

Getting Started

qbec can be installed by fetching the binaries from github.

For Linux/WSL2, run:

wget https://github.com/splunk/qbec/releases/download/v0.12.1/qbec-linux-amd64.tar.gz # Change version to the latest released version
tar xf qbec-linux-amd64.tar.gz
sudo mv ./qbec /usr/local/bin/

If you use homebrew, run the following commands

brew tap splunk/tap
brew install qbec

Run qbec version to ensure that your setup is successful.

Initializing a qbec application

qbec init can be used to initialize an application for use with qbec.

We’ll use qbec to setup an example application to deploy to a Kubernetes cluster running on docker-desktop. minikube, kind or any other Kubernetes cluster can also be used.

Enabling Kubernetes on Docker Desktop

Run the following command to setup the app for deployment.

qbec init --with-example my-app
cd my-app

The my-app folder contains all the files needed to deploy the application.

hsm@home67:~/my-app$ tree
.
├── components
│ └── hello.jsonnet
├── environments
│ ├── base.libsonnet
│ └── default.libsonnet
├── params.libsonnet
└── qbec.yaml

qbec.yaml contains configuration for qbec. qbec reads this file to know about different environments and how to talk to the corresponding Kubernetes clusters.

The default environment has values to connect to the Kubernetes API server and a namespace is specified for the deployment. Multiple environments can be added here.

The params.libsonnet contains mapping for the environment name to the corresponding file under environments/<env-name>.libsonnet .

default environment maps to the configuration in environments/default.libsonnet

The shared configuration for each environment is set in environments/base.libsonnet and environment specific overrides can be set in the corresponding environment file. In the example above, the default.libsonnet file overrides the configuration(from base) for the default environment.

indexData and replica count is overridden for the default deployment

The components folder contains all components that we want to deploy. The components/hello.jsonnet component contains the Kubernetes object definition for the deployment and the config map.

Next, we’ll use qbec to deploy to the default environment.

Deploying using qbec

Deployments using qbec are very simple and straightforward using the qbec apply command.

Run qbec apply <env-name> to deploy the application to the environment specified by <env-name> .

hsm@home67:~/my-app$ qbec apply default # env-name is default
setting cluster to docker-desktop
setting context to docker-for-desktop
setting context to docker-desktop
cluster metadata load took 32ms
1 components evaluated in 5ms
will synchronize 2 object(s)Do you want to continue [y/n]: y
1 components evaluated in 2ms
create configmaps demo-config -n default (source hello)
create deployments demo-deploy -n default (source hello)
waiting for deletion list to be returned
server objects load took 612ms
---
stats:
created:
- configmaps demo-config -n default (source hello)
- deployments demo-deploy -n default (source hello)

And that’s it! Verify the deployment by using kubectl

hsm@home67:~/my-app$ kubectl get pods
NAME READY STATUS RESTARTS AGE
demo-deploy-78fd78c96-cs8lw 1/1 Running 0 58s
demo-deploy-78fd78c96-n4phl 1/1 Running 0 58s

We’ll explore more qbec features in the subsequent posts. qbec has garbage collection enabled by default and supports dry-runs.qbec diff can show exactly which objects would change and how. qbec validate can do schema validation on kubernetes objects defined in the jsonnet file. And much more!

Stay tuned!

Meanwhile, you can give qbec a try and learn more at https://qbec.io.

--

--