Skip to content

Commit

Permalink
add kubernetes setup (#11)
Browse files Browse the repository at this point in the history
Signed-off-by: Todd Baert <[email protected]>
  • Loading branch information
toddbaert authored Nov 8, 2024
1 parent 1d35dbf commit 0ae944f
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,37 @@ To simulate the migration yourself, follow these steps:
If all goes well, you should see the migration complete without any issues.

![telemetry](./public/img/telemetry.png)

## Kubernetes

To run the ToggleShop in a Kind cluster:

Create the cluster with the supplied definition:

```sh
kind create cluster --config kubernetes/cluster.yaml
```

Install cert manager in the cluster (required for the OpenFeature operator):

```sh
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.13.2/cert-manager.yaml && kubectl wait --timeout=60s --for condition=Available=True deploy --all -n 'cert-manager'
```

Install the nginx controller:

```sh
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/main/deploy/static/provider/kind/deploy.yaml && kubectl wait --timeout=60s --for condition=Available=True deploy --all -n 'ingress-nginx'
```

Install the OpenFeature operator:

```sh
helm repo add openfeature https://open-feature.github.io/open-feature-operator/ && helm repo update && helm upgrade --install open-feature-operator openfeature/open-feature-operator
```

Deploy the ToggleShop and supporting infrastructure:

```sh
kubectl -n default apply -f kubernetes/toggle-shop.yaml && kubectl wait --timeout=60s deployment --for condition=Available=True -l 'app=toggle-shop' -n 'default'
```
17 changes: 17 additions & 0 deletions kubernetes/cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kind.x-k8s.io/v1alpha4
kind: Cluster
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraPortMappings:
- containerPort: 80
hostPort: 80
protocol: TCP
- role: worker
- role: worker
- role: worker
169 changes: 169 additions & 0 deletions kubernetes/toggle-shop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# Flags for our UI
apiVersion: core.openfeature.dev/v1beta1
kind: FeatureFlag
metadata:
name: ui-flags
labels:
app: toggle-shop
spec:
flagSpec:
flags:
offer-free-shipping:
state: ENABLED
variants:
'on': true
'off': false
defaultVariant: 'on'
---
# Flags for our backend application
apiVersion: core.openfeature.dev/v1beta1
kind: FeatureFlag
metadata:
name: app-flags
labels:
app: toggle-shop
spec:
flagSpec:
flags:
use-distributed-db:
state: ENABLED
variants:
'on': true
'off': false
defaultVariant: 'off'
use-secure-protocol:
state: ENABLED
variants:
'on': true
'off': false
defaultVariant: 'off'
---
# Feature flag source custom resource, configuring flagd to source flags from FeatureFlag CRDs
apiVersion: core.openfeature.dev/v1beta1
kind: FeatureFlagSource
metadata:
name: ui-flag-source
labels:
app: toggle-shop
spec:
sources:
- source: ui-flags
provider: kubernetes
---
# Feature flag source custom resource, configuring flagd to source flags from FeatureFlag CRDs
apiVersion: core.openfeature.dev/v1beta1
kind: FeatureFlagSource
metadata:
name: app-flag-source
labels:
app: toggle-shop
spec:
sources:
- source: app-flags
provider: kubernetes
---
# Standalone flagd for serving UI
apiVersion: core.openfeature.dev/v1beta1
kind: Flagd
metadata:
name: flagd-ui
spec:
replicas: 1
serviceAccountName: default
featureFlagSource: ui-flag-source
ingress:
enabled: true
annotations:
nginx.ingress.kubernetes.io/use-regex: 'true'
nginx.ingress.kubernetes.io/rewrite-target: /ofrep/$1
nginx.ingress.kubernetes.io/force-ssl-redirect: 'false'
hosts:
- localhost
- ''
ingressClassName: nginx
pathType: ImplementationSpecific
ofrepPath: /api/ofrep/(.*)
---
# Standalone flagd for serving in-process provider
apiVersion: core.openfeature.dev/v1beta1
kind: Flagd
metadata:
name: flagd-in-process
spec:
replicas: 1
serviceType: ClusterIP
serviceAccountName: default
featureFlagSource: app-flag-source
---
# In-process provider configuration
apiVersion: core.openfeature.dev/v1beta1
kind: InProcessConfiguration
metadata:
name: in-process-config
spec:
host: flagd-in-process
---
# Deployment for our application
apiVersion: apps/v1
kind: Deployment
metadata:
name: toggle-shop-deployment
labels:
app: toggle-shop
spec:
replicas: 1
selector:
matchLabels:
app: toggle-shop
template:
metadata:
labels:
app: toggle-shop
annotations:
openfeature.dev/enabled: 'true'
openfeature.dev/inprocessconfiguration: 'in-process-config'
spec:
containers:
- name: toggle-shop
image: ghcr.io/open-feature/toggle-shop:main # x-release-please-version
ports:
- containerPort: 3000
name: app-port
env:
- name: FLAGD_HOST
value: flagd-in-process
---
# Service to expose our application
apiVersion: v1
kind: Service
metadata:
name: toggle-shop-app-service
labels:
app: toggle-shop
spec:
type: NodePort
selector:
app: toggle-shop
ports:
- port: 3000
targetPort: app-port
nodePort: 30000
---
# Ingress for our application
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: toggle-shop-ingress
spec:
ingressClassName: nginx
rules:
- host: localhost
http:
paths:
- pathType: Prefix
path: /
backend:
service:
name: toggle-shop-app-service
port:
number: 3000

0 comments on commit 0ae944f

Please sign in to comment.