Skip to content

Commit 91bcaa3

Browse files
committed
add kubernetes setup
1 parent e7203bd commit 91bcaa3

File tree

3 files changed

+220
-0
lines changed

3 files changed

+220
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,37 @@ To simulate the migration yourself, follow these steps:
7676
If all goes well, you should see the migration complete without any issues.
7777

7878
![telemetry](./public/img/telemetry.png)
79+
80+
## Kubernetes
81+
82+
To run the ToggleShop in a Kind cluster:
83+
84+
Create the cluster with the supplied definition:
85+
86+
```sh
87+
kind create cluster --config kubernetes/cluster.yaml
88+
```
89+
90+
Install cert manager in the cluster (required for the OpenFeature operator):
91+
92+
```sh
93+
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'
94+
```
95+
96+
Install the nginx controller:
97+
98+
```sh
99+
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'
100+
```
101+
102+
Install the OpenFeature operator:
103+
104+
```sh
105+
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
106+
```
107+
108+
Deploy the ToggleShop and supporting infrastructure:
109+
110+
```sh
111+
kubectl -n default apply -f kubernetes/toggle-shop.yaml && kubectl wait --timeout=60s deployment --for condition=Available=True -l 'app=toggle-shop' -n 'default'
112+
```

kubernetes/cluster.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: kind.x-k8s.io/v1alpha4
2+
kind: Cluster
3+
nodes:
4+
- role: control-plane
5+
kubeadmConfigPatches:
6+
- |
7+
kind: InitConfiguration
8+
nodeRegistration:
9+
kubeletExtraArgs:
10+
node-labels: "ingress-ready=true"
11+
extraPortMappings:
12+
- containerPort: 80
13+
hostPort: 80
14+
protocol: TCP
15+
- role: worker
16+
- role: worker
17+
- role: worker

kubernetes/toggle-shop.yaml

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Flags for our UI
2+
apiVersion: core.openfeature.dev/v1beta1
3+
kind: FeatureFlag
4+
metadata:
5+
name: ui-flags
6+
labels:
7+
app: toggle-shop
8+
spec:
9+
flagSpec:
10+
flags:
11+
offer-free-shipping:
12+
state: ENABLED
13+
variants:
14+
'on': true
15+
'off': false
16+
defaultVariant: 'on'
17+
---
18+
# Flags for our backend application
19+
apiVersion: core.openfeature.dev/v1beta1
20+
kind: FeatureFlag
21+
metadata:
22+
name: app-flags
23+
labels:
24+
app: toggle-shop
25+
spec:
26+
flagSpec:
27+
flags:
28+
use-distributed-db:
29+
state: ENABLED
30+
variants:
31+
'on': true
32+
'off': false
33+
defaultVariant: 'off'
34+
use-secure-protocol:
35+
state: ENABLED
36+
variants:
37+
'on': true
38+
'off': false
39+
defaultVariant: 'off'
40+
---
41+
# Feature flag source custom resource, configuring flagd to source flags from FeatureFlag CRDs
42+
apiVersion: core.openfeature.dev/v1beta1
43+
kind: FeatureFlagSource
44+
metadata:
45+
name: ui-flag-source
46+
labels:
47+
app: toggle-shop
48+
spec:
49+
sources:
50+
- source: ui-flags
51+
provider: kubernetes
52+
---
53+
# Feature flag source custom resource, configuring flagd to source flags from FeatureFlag CRDs
54+
apiVersion: core.openfeature.dev/v1beta1
55+
kind: FeatureFlagSource
56+
metadata:
57+
name: app-flag-source
58+
labels:
59+
app: toggle-shop
60+
spec:
61+
sources:
62+
- source: app-flags
63+
provider: kubernetes
64+
---
65+
# Standalone flagd for serving UI
66+
apiVersion: core.openfeature.dev/v1beta1
67+
kind: Flagd
68+
metadata:
69+
name: flagd-ui
70+
spec:
71+
replicas: 1
72+
serviceAccountName: default
73+
featureFlagSource: ui-flag-source
74+
ingress:
75+
enabled: true
76+
annotations:
77+
nginx.ingress.kubernetes.io/use-regex: 'true'
78+
nginx.ingress.kubernetes.io/rewrite-target: /ofrep/$1
79+
nginx.ingress.kubernetes.io/force-ssl-redirect: 'false'
80+
hosts:
81+
- localhost
82+
- ''
83+
ingressClassName: nginx
84+
pathType: ImplementationSpecific
85+
ofrepPath: /api/ofrep/(.*)
86+
---
87+
# Standalone flagd for serving in-process provider
88+
apiVersion: core.openfeature.dev/v1beta1
89+
kind: Flagd
90+
metadata:
91+
name: flagd-in-process
92+
spec:
93+
replicas: 1
94+
serviceType: ClusterIP
95+
serviceAccountName: default
96+
featureFlagSource: app-flag-source
97+
---
98+
# In-process provider configuration
99+
apiVersion: core.openfeature.dev/v1beta1
100+
kind: InProcessConfiguration
101+
metadata:
102+
name: in-process-config
103+
spec:
104+
host: flagd-in-process
105+
---
106+
# Deployment of a demo-app using our custom resources
107+
apiVersion: apps/v1
108+
kind: Deployment
109+
metadata:
110+
name: toggle-shop-deployment
111+
labels:
112+
app: toggle-shop
113+
spec:
114+
replicas: 1
115+
selector:
116+
matchLabels:
117+
app: toggle-shop
118+
template:
119+
metadata:
120+
labels:
121+
app: toggle-shop
122+
annotations:
123+
openfeature.dev/enabled: 'true'
124+
openfeature.dev/inprocessconfiguration: 'in-process-config'
125+
spec:
126+
containers:
127+
- name: toggle-shop
128+
image: ghcr.io/open-feature/toggle-shop:main # x-release-please-version
129+
ports:
130+
- containerPort: 3000
131+
name: demo-port
132+
env:
133+
- name: FLAGD_HOST
134+
value: flagd-in-process
135+
---
136+
# Service to expose our application
137+
apiVersion: v1
138+
kind: Service
139+
metadata:
140+
name: toggle-shop-app-service
141+
labels:
142+
app: toggle-shop
143+
spec:
144+
type: NodePort
145+
selector:
146+
app: toggle-shop
147+
ports:
148+
- port: 3000
149+
targetPort: demo-port
150+
nodePort: 30000
151+
---
152+
# Ingress for our application
153+
apiVersion: networking.k8s.io/v1
154+
kind: Ingress
155+
metadata:
156+
name: toggle-shop-ingress
157+
spec:
158+
ingressClassName: nginx
159+
rules:
160+
- host: localhost
161+
http:
162+
paths:
163+
- pathType: Prefix
164+
path: /
165+
backend:
166+
service:
167+
name: toggle-shop-app-service
168+
port:
169+
number: 3000

0 commit comments

Comments
 (0)