Skip to content

Instantly share code, notes, and snippets.

@juzhiyuan
Last active August 15, 2022 10:05
Show Gist options
  • Save juzhiyuan/d83a2a0f08c0079c4126ef8d95ee2848 to your computer and use it in GitHub Desktop.
Save juzhiyuan/d83a2a0f08c0079c4126ef8d95ee2848 to your computer and use it in GitHub Desktop.

README

Reference

  1. https://apisix.apache.org/blog/2022/07/06/use-keycloak-with-api-gateway-to-secure-apis/

Steps

# 0. Install Ingress Controller

$ helm repo add apisix https://charts.apiseven.com
$ helm repo add bitnami https://charts.bitnami.com/bitnami
$ helm repo update
$ kubectl create ns ingress-apisix
$ helm install apisix apisix/apisix \
  --set gateway.type=LoadBalancer \
  --set ingress-controller.enabled=true \
  --namespace ingress-apisix \
  --set ingress-controller.config.apisix.serviceNamespace=ingress-apisix

$ kubectl get service --namespace ingress-apisix

# 1. Create a HTTPBIN Service
$ kubectl run httpbin --image kennethreitz/httpbin --port 80 -n ingress-apisix
$ kubectl expose pod httpbin --port 80 -n ingress-apisix

# 2. Get the APISIX Instance's External IP

$ kubectl get service apisix-gateway --namespace ingress-apisix -o jsonpath='{.status.loadBalancer.ingress[].ip}'

# 3. Update Auth0 Configuration
# Login Auth0 and navigate to your Application's Dashboard, set the "Allowed Callback URLs" field to "http://157.230.193.76/anything/callback"

# 4. Create the route-okta.yaml
# Please check the file content: https://gist.github.com/juzhiyuan/30b3873788d591892ceee2ebb95ba5ff

# 5. Apply the route-okta.yaml
$ kubectl apply -f route-okta.yaml -n ingress-apisix

# 6. Veriry if CRD apply successfully
$ kubectl exec -it -n ingress-apisix apisix-79df85f978-pp49g -- curl http://127.0.0.1:9180/apisix/admin/routes -H 'X-API-Key: edd1c9f034335f136f87ad84b625c8f1'

# 7. Open browser and visit http://157.230.193.76/anything/get, it will redirect to Auth0's login page

# 8. After login successfully, you will see the protected content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment