Created
June 30, 2022 22:00
-
-
Save mouchar/fb051803544ece917fa272f5436a765e to your computer and use it in GitHub Desktop.
Featurehub with postgresql-ha, running in kind cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Reproducer for https://github.com/featurehub-io/featurehub/issues/801 | |
# Set your OAuth2 client and secret in variables as in example: | |
# CLIENT_ID="Google OAuth2 client_id" CLIENT_SECRET="Google OAuth2 secret" ./deploy.sh | |
# Required SW: kubectl, docker, kind and helm | |
: "${CLIENT_ID:?Client id is missing}" | |
: "${CLIENT_SECRET:?Client secret is missing}" | |
set -e | |
# Infrastructure setup | |
## Comment out if you already have other k8s configured and running | |
kind create cluster --config - <<EOF | |
kind: Cluster | |
apiVersion: kind.x-k8s.io/v1alpha4 | |
name: kind | |
nodes: | |
- role: control-plane | |
kubeadmConfigPatches: | |
- | | |
kind: InitConfiguration | |
nodeRegistration: | |
kubeletExtraArgs: | |
node-labels: "ingress-ready=true" | |
authorization-mode: "AlwaysAllow" | |
extraPortMappings: | |
- containerPort: 80 | |
hostPort: 80 | |
- role: worker | |
- role: worker | |
- role: worker | |
EOF | |
echo "🪰 Waiting for nodes to become ready" | |
kubectl wait --for=condition=Ready nodes --all --timeout=120s | |
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/kind/deploy.yaml | |
echo "🪰 Waiting for ingress ctl" | |
kubectl wait --namespace ingress-nginx \ | |
--for=condition=ready pod \ | |
--selector=app.kubernetes.io/component=controller \ | |
--timeout=200s | |
helm repo list|grep -E '^bitnami\s' || { | |
helm repo add bitnami https://charts.bitnami.com/bitnami | |
} | |
helm repo list|grep -E '^featurehub\s' || { | |
helm repo add featurehub https://featurehub-io.github.io/featurehub-install/ | |
} | |
helm repo update | |
# Preload images so we don't waste network bandwidth on duplicate pulls | |
## Comment out if you don't mind confusing errors during deployment | |
IMAGES=( | |
featurehub/mr:1.5.7 featurehub/edge:1.5.7 featurehub/dacha:1.5.7 | |
nats:2.7.2-alpine natsio/prometheus-nats-exporter:0.9.1 natsio/nats-server-config-reloader:0.6.2 | |
bitnami/pgpool:4.3.1-debian-10-r70 bitnami/postgresql-repmgr:14.2.0-debian-10-r78 bitnami/bitnami-shell:10-debian-10-r413 | |
) | |
echo "🪰 Preloading important images" | |
for img in "${IMAGES[@]}" ; do | |
docker pull -q "$img" | |
kind --name kind load docker-image "$img" | |
done | |
# Postgresql-HA | |
cat > pg-values.yaml <<EOF | |
pgpool: | |
replicaCount: 2 | |
numInitChildren: 20 | |
maxPool: 4 | |
adminPassword: adminpass | |
# This needs to be set to allow using postgresql.extendedConf | |
volumePermissions: | |
enabled: true | |
persistence: | |
# just to avoid the need to delete PVC on repeated tests | |
enabled: false | |
# size: 1Gi | |
postgresql: | |
database: featurehub | |
username: featurehub | |
password: featurehub | |
repmgrPassword: repmgrpass | |
extendedConf: |- | |
max_connections = 500 | |
shared_buffers = 128MB | |
work_mem = 8MB | |
log_statement = 'all' | |
EOF | |
helm -n featurehub upgrade --install --create-namespace \ | |
postgresql-ha bitnami/postgresql-ha --version 9.0.5 --wait \ | |
-f pg-values.yaml | |
kubectl -n featurehub get pod --selector app.kubernetes.io/name=postgresql-ha | |
# Featurehub | |
cat > fh-values.yaml <<EOF | |
global: | |
# This is only used for the short-cut KinD ingress, you would not use this in your own cluster | |
ingress: | |
enabled: false | |
managementRepository: | |
environmentVars: | |
db.url: jdbc:postgresql://postgresql-ha-pgpool:5432/featurehub | |
db.username: featurehub | |
db.password: featurehub | |
portfolio.admin.group.suffix: Administrators | |
auth.disable-login: "true" | |
# auth.userMustBeCreatedFirst: "true" | |
oauth2.providers: oauth2-google | |
oauth2.redirectUrl: http://localhost/oauth/auth | |
oauth2.adminUiUrlSuccess: http://localhost/ | |
oauth2.adminUiUrlFailure: http://localhost/oauth2-failure | |
oauth2.providers.google.id: '$CLIENT_ID' | |
oauth2.providers.google.secret: '$CLIENT_SECRET' | |
ingress: | |
enabled: true | |
className: "nginx" | |
hosts: | |
- host: localhost | |
paths: | |
- path: / | |
pathType: Prefix | |
edge: | |
# replicaCount: 1 | |
ingress: | |
enabled: true | |
className: "nginx" | |
hosts: | |
- host: localhost | |
paths: | |
- path: /features | |
pathType: ImplementationSpecific | |
# dacha: | |
# replicaCount: 1 | |
# disabling pg subcharts, we'll use standalone deployment | |
postgresql: | |
enabled: false | |
EOF | |
helm -n featurehub upgrade --install --create-namespace \ | |
featurehub featurehub/featurehub --version 3.0.3 --wait \ | |
-f fh-values.yaml | |
kubectl -n featurehub get pod --selector app.kubernetes.io/instance=featurehub | |
echo "🪰 All set, ready to test" | |
# Hints: | |
# * log_statement is turned on, unfortunately there's somehow high traffic from | |
# repmgr and k8s probes, so logs are hard to parse. | |
# to tail all the postgres logs at once, use: | |
# $ kubectl logs -n featurehub -l app.kubernetes.io/component=postgresql -c postgresql -f --prefix=true | |
# Note where the queries are being executed - inserts will always go to master (usually pod 0) | |
# * To save time, it's possible to wipe persistent data using: | |
# $ helm -n featurehub uninstall postgresql-ha | |
# $ helm -n featurehub upgrade --install --create-namespace postgresql-ha bitnami/postgresql-ha --version 9.0.5 --wait -f pg-values.yaml | |
# $ kubectl -n featurehub rollout restart deployment featurehub-management-repository | |
# $ kubectl wait --namespace featurehub --for=condition=ready pod --selector=app.kubernetes.io/name=featurehub-management-repository --timeout=60s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment