Use the OpenFeature Operator to install and run flagd on a Kubernetes cluster.
The operator includes flagd (no need to install flagd separately).
- Install cert-manager if you don't already have it on the cluster
- Install the OpenFeature Operator (see below)
- Define CRDs which describe the feature flag source (flagd) and the feature flags themselves
- Annotate your deployment to enable flagd feature flagging for that pod
helm repo add openfeature https://open-feature.github.io/open-feature-operator/
helm repo update
helm upgrade --install openfeature openfeature/open-feature-operator
Create a namespace to house your flags:
kubectl create namespace flags
Next, define your feature flag(s) using the FeatureFlag custom resource definition (CRD).
This example specifies one flag called foo
which has two variants bar
and baz
. The defaultVariant
is bar
.
kubectl apply -n flags -f - <<EOF
apiVersion: core.openfeature.dev/v1beta1
kind: FeatureFlag
metadata:
name: sample-flags
spec:
featureFlagSpec:
flags:
foo:
state: "ENABLED"
variants:
"bar": "BAR"
"baz": "BAZ"
defaultVariant: "bar"
targeting: {}
EOF
Next, tell the OpenFeature operator where to find flags.
Do so by creating a FeatureFlagSource CRD.
This example specifies that the CRD called sample-flags
(created above) can be found in the flags
namespace and that the provider is kubernetes
.
The port
parameter defines the port on which the flagd API will be made available via the sidecar (more on this below).
kubectl apply -n flags -f - <<EOF
apiVersion: core.openfeature.dev/v1beta1
kind: FeatureFlagSource
metadata:
name: feature-flag-source
spec:
sources:
- source: flags/sample-flags
provider: kubernetes
port: 8080
EOF
The operator looks for Deployment
objects annotated with particular annotations.
openfeature.dev/enabled: "true"
enables this deployment for flagdopenfeature.dev/featureflagsource: "flags/feature-flag-source"
makes the given feature flag sources available to this deployment
When these two annotations are added, the OpenFeature operator will inject a sidecar into your workload.
flagd will then be available via http://localhost
the port specified in the FeatureFlagSource
(e.g. 8080
)
Your Deployment YAML might look like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: busybox-curl
spec:
replicas: 1
selector:
matchLabels:
app: my-busybox-curl-app
template:
metadata:
labels:
app: my-busybox-curl-app
annotations:
# here are the annotations for OpenFeature Operator
openfeature.dev/enabled: "true"
openfeature.dev/featureflagsource: "flags/feature-flag-source"
spec:
containers:
- name: busybox
image: yauritux/busybox-curl:latest
ports:
- containerPort: 80
args:
- sleep
- "30000"
// From within the pod
curl --location 'http://localhost:8080/flagd.evaluation.v1.Service/ResolveString' --header 'Content-Type: application/json' --data '{ "flagKey":"foo"}'
In a real application, rather than curl
, you would probably use the OpenFeature SDK with the flagd
provider.
The operator will look for the annotations above and, when found, inject a sidecar into the relevant pods.
flagd reads the feature flag CRD(s) and makes an API endpoint available so your application can interact with flagd.