Skip to content

configcat-labs/feature-flags-with-kubernetes

Repository files navigation

Using Feature Flags with Kubernetes for Smoother Deployments

This is a sample application that demonstrates how to use ConfigCat feature flags with Kubernetes for smoother deployments.

How it works

In this sample app, we utilize the Python Kubernetes client to create deployments and services. This choice was made to seamlessly integrate Kubernetes with ConfigCat feature flags. It's important to note that the integration of ConfigCat feature flags with Kubernetes can be approached in various ways. The explanation below details how these components work together:

  1. Two Docker images are created for the backend. Each of these are built from a Separate Dockerfile. The Dockerfile.with-node18 uses Node 18 and the Dockerfile.with-node20 uses Node 20.

  2. The kubernetes-script.py script is run to create the deployments and services. A default deployment logic gets executed to create a Pod with a container that contains the Docker image built from the Dockerfile.with-node18. Afterwards, the feature flag value is checked and if it is true, the Pod's container image is updated/patched to use the Docker image built from the Dockerfile.with-node20.

Build & Run

Setup

Python environment setup

  1. Create a virtual environment
python3 -m venv venv
  1. Activate the virtual environment
source venv/bin/activate
  1. Install the dependencies
pip3 install -r requirements.txt

Docker setup

  1. Build the images for the backend that Kubernetes will use
docker build -f Dockerfile.with-node18 -t backend-with-node18:latest .
docker build -f Dockerfile.with-node20 -t backend-with-node20:latest .

Kubernetes setup

In this setup, we are using Docker Desktop with Kubernetes enabled.

  1. Create the deployments and services
python3 kubernetes-script.py
  1. Check the deployments
kubectl get deployments

You should see something like this:

NAME                 READY   UP-TO-DATE   AVAILABLE   AGE
backend-deployment   1/1     1            1           35m

Learn more

Useful links to technical resources.

ConfigCat also supports many other frameworks and languages. Check out the full list of supported SDKs here.

You can also explore other code samples for various languages, frameworks, and topics here in the ConfigCat labs on GitHub.

Keep up with ConfigCat on X, Facebook, LinkedIn, and GitHub.

Author

Chavez Harris

Contributions

Contributions are welcome!

About

A companion repo for the blog article: Using Feature Flags with Kubernetes for Smoother Deployments.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published