Skip to content

Commit

Permalink
remove metalLB
Browse files Browse the repository at this point in the history
  • Loading branch information
Breee committed Feb 11, 2024
1 parent 7cc0724 commit 1ef9f91
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 40 deletions.
17 changes: 17 additions & 0 deletions dev/apps/keycloak-provider/keycloak-provider-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
apiVersion: v1
kind: Secret
metadata:
name: keycloak-credentials
namespace: crossplane-system
type: Opaque
stringData:
credentials: |
{
"client_id":"admin-cli",
"username": "admin",
"password": "admin",
"url": "http://keycloak-keycloakx-http.keycloak.svc:8080",
"base_path": "/auth",
"realm": "master"
}
2 changes: 1 addition & 1 deletion dev/apps/keycloak.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
value: >-
-Djgroups.dns.query={{ include "keycloak.fullname" . }}-headless
service:
type: LoadBalancer
type: ClusterIP
destination:
server: https://kubernetes.default.svc
namespace: keycloak
Expand Down
79 changes: 40 additions & 39 deletions dev/setup_dev_environment.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
#!/bin/bash
set -eou pipefail

kill_port_forward() {
echo "Killing port forward"
echo "Killing ArgoCD port forward with PID $ARGOCD_PORT_FORWARD_PID"
kill $ARGOCD_PORT_FORWARD_PID
echo "Killing Keycloak port forward with PID $KEYCLOAK_PORT_FORWARD_PID"
kill $KEYCLOAK_PORT_FORWARD_PID
}

# trap ctrl-c and call kill_port_forward()
trap kill_port_forward INT


# check if user can run docker without sudo, if not create an alias for sudo docker for this session
if ! docker ps >/dev/null 2>&1; then
echo "You need to be able to run docker without sudo. Adding alias for this session."
alias docker='sudo docker'
fi


echo "Checking dependencies"
command -v docker >/dev/null 2>&1 || { echo >&2 "Docker is required but not installed. Aborting."; exit 1; }
command -v kind >/dev/null 2>&1 || { echo >&2 "Kind is required but not installed. Aborting."; exit 1; }
Expand All @@ -18,7 +30,7 @@ command -v sed >/dev/null 2>&1 || { echo >&2 "sed is required but not installed.
echo "All dependencies are installed."

echo "Creating cluster"
kind create cluster --name fenrir-1 --config kind-config.yaml --kubeconfig $HOME/.kube/fenrir-1
kind create cluster --name fenrir-1 --config kind-config.yaml --kubeconfig $HOME/.kube/fenrir-1 || true

echo "Running some commands to make sure the cluster is ready"
export KUBECONFIG=$HOME/.kube/fenrir-1
Expand All @@ -28,35 +40,9 @@ kubectl get nodes
echo "Switching context to fenrir-1"
kubectl config use-context kind-fenrir-1

echo "########### Setup MetalLB ###########"
echo "* Installing MetalLB"
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.13.7/config/manifests/metallb-native.yaml
echo "* Waiting for MetalLB to be ready"
kubectl wait --namespace metallb-system --for=condition=ready pod --selector=app=metallb

echo "* Get IPAM config: "
docker network inspect kind
export IP_PREFIX=$(docker network inspect kind | jq -r .[].IPAM.Config[0].Subnet | sed -r 's|\.0/[0-9]+||g')
echo "* IP Prefix: $IP_PREFIX"
export IP_RANGE_START="$IP_PREFIX.30"
export IP_RANGE_END="$IP_PREFIX.80"
echo "* IP Range: $IP_RANGE_START - $IP_RANGE_END"
cat metallb/pools.yaml | envsubst | kubectl apply -f -

echo "########### Installing ArgoCD ###########"
kubectl create namespace argocd
kubectl create namespace argocd || true
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
echo "* Exposing ArgoCD"
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

while [[ -z $(kubectl get svc -n argocd argocd-server -o jsonpath="{.status.loadBalancer.ingress}" 2>/dev/null) ]]; do
echo "** still waiting for argocd/argocd-server to get ingress"
sleep 1
done
echo "* argocd/argocd-server now has ingress."

export ARGOCD_IP=$(kubectl -n argocd get svc argocd-server -o json | jq -r .status.loadBalancer.ingress[0].ip)

echo "* Waiting for ArgoCD to be ready"
kubectl wait pod --all --for=condition=Ready --namespace argocd --timeout=300s

Expand All @@ -65,38 +51,53 @@ echo "########### Installing Keycloak ###########"
kubectl apply -f apps/keycloak.yaml
sleep 5
kubectl wait pod --all --for=condition=Ready --namespace keycloak --timeout=300s
# patch svc to be ClusterIP
kubectl patch svc keycloak-keycloakx-http -n keycloak --type='json' -p '[{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'

while [[ -z $(kubectl get svc -n keycloak keycloak-keycloakx-http -o jsonpath="{.status.loadBalancer.ingress}" 2>/dev/null) ]]; do
echo "** still waiting for service keycloak/keycloak-keycloakx-http to get ingress"
sleep 1
done

export KEYCLOAK_IP=$(kubectl -n keycloak get svc keycloak-keycloakx-http -o json | jq -r .status.loadBalancer.ingress[0].ip)
export KEYCLOAK_PORT=$(kubectl -n keycloak get svc keycloak-keycloakx-http -o json | jq -r .spec.ports[0].port)
export KEYCLOAK_USER=admin
export KEYCLOAK_PASSWORD=admin


echo "########### Installing Crossplane ###########"

kubectl apply -f apps/crossplane.yaml
sleep 10
kubectl wait pod --all --for=condition=Ready --namespace crossplane-system --timeout=300s


echo "########### Installing Keycloak Provider secret ###########"
cat iam/keycloak-provider-secret.yaml | envsubst | kubectl apply --namespace crossplane-system -f -
cat apps/keycloak-provider/keycloak-provider-secret.yaml | kubectl apply --namespace crossplane-system -f -

# Port forward ArgoCD and Keycloak and save the process id
# check if ports 8888 and 8080 are already in use
if lsof -Pi :8888 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "Port 8888 is already in use. Aborting."
exit 1
fi
if lsof -Pi :8080 -sTCP:LISTEN -t >/dev/null 2>&1; then
echo "Port 8080 is already in use. Aborting."
exit 1
fi
ARGOCD_PORT_FORWARD_PID=$(kubectl port-forward svc/argocd-server -n argocd 8888:443 > /dev/null 2>&1 & echo $!)
KEYCLOAK_PORT_FORWARD_PID=$(kubectl port-forward svc/keycloak-keycloakx-http -n keycloak 8080:$KEYCLOAK_PORT > /dev/null 2>&1 & echo $!)

echo $ARGOCD_PORT_FORWARD_PID
echo $KEYCLOAK_PORT_FORWARD_PID

echo "#################################################"
echo "You're ready to go!"
echo "ArgoCD is ready at https://$ARGOCD_IP:443"
echo "ArgoCD is ready at https://127.0.0.1:8888"
echo "ArgoCD login: admin / $(kubectl -n argocd get secrets argocd-initial-admin-secret -o json | jq -r .data.password | base64 -d)"
echo "-------------------------------------------------"
echo "Keycloak is ready at http://$KEYCLOAK_IP:$KEYCLOAK_PORT/auth"
echo "Keycloak is ready at http://127.0.0.1:8080/auth"
echo "Keycloak login: admin / admin"
echo "#################################################"
echo "To delete the cluster run: kind delete cluster --name fenrir-1"
echo "#################################################"
echo "You can now run the provider by executing: make run"
echo "#################################################"
echo "Press Ctrl+C to kill the port forwards and exit."

while true; do sleep 10; done


0 comments on commit 1ef9f91

Please sign in to comment.