Skip to content

Commit

Permalink
Added Kong Demo guide
Browse files Browse the repository at this point in the history
  • Loading branch information
frjaraur committed Sep 8, 2018
1 parent 7055ba6 commit 91ac909
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 7 deletions.
101 changes: 101 additions & 0 deletions demo/DEMO_Kong_Ingress_Controller.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
## DEMO_Kong_Ingress_Controller

asciinema rec -t "DEMO_Kong_Ingress_Controller"

# We deploy complete Kong Environment with Postgresql.

curl https://raw.githubusercontent.com/Kong/kubernetes-ingress-controller/master/deploy/single/all-in-one-postgres.yaml | kubectl create -f -


# We have created 'kong' namespace so we will wait until all Kong components are ready.

kubectl get all --namespace kong


# We deploy now two deployments with their services (red-app and blue-app with red-svc and blue-svc)

curl https://raw.githubusercontent.com/Codegazers/k8s-vagrant/master/examples/colors/colors.yml | kubectl create -f -


# We review the deployments

kubectl get all --namespace default


# We review Kong

kubectl get all --namespace kong


# For quick access we prepare some envirnment variables (for Kong admin and Kong proxy access)

export KONG_ADMIN_PORT=$(minikube service -n kong kong-ingress-controller --url --format "{{ .Port }}")

export KONG_ADMIN_IP=$(minikube service -n kong kong-ingress-controller --url --format "{{ .IP }}")

export PROXY_IP=$(minikube service -n kong kong-proxy --url --format "{{ .IP }}" | head -1)

export HTTP_PORT=$(minikube service -n kong kong-proxy --url --format "{{ .Port }}" | head -1)

export HTTPS_PORT=$(minikube service -n kong kong-proxy --url --format "{{ .Port }}" | tail -1)


# Now we deploy colors-ingress ingress resource for accesing both applications

curl https://raw.githubusercontent.com/Codegazers/k8s-vagrant/master/examples/colors/colors-ingress.yml | kubectl apply -f -


# We just set up host routing

kubectl get ingress colors-ingress -o yaml


# And now we can access our applications setting host headers

http ${PROXY_IP}:${HTTP_PORT}/text Host:red.example.com

http ${PROXY_IP}:${HTTP_PORT}/text Host:blue.example.com


# We review targets because red-app has 3 replicas

http ${KONG_ADMIN_IP}:${KONG_ADMIN_PORT}/upstreams/default.red-svc.80/targets


# We now add a KongPluggin resource for reate limitting to route

echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: add-ratelimiting-to-route
config:
minute: 20
limit_by: ip
second: 5
" | kubectl create -f -


# We review deployed Kong Plugins

kubectl get kongplugins


# And now we apply rate limit to one of our deployed services (red one)

kubectl patch svc red-svc \
-p '{"metadata":{"annotations":{"rate-limiting.plugin.konghq.com": "add-ratelimiting-to-route\n"}}}'


# We can review the plugin, associated to route and routes deployed

http ${KONG_ADMIN_IP}:${KONG_ADMIN_PORT}/plugins

http ${KONG_ADMIN_IP}:${KONG_ADMIN_PORT}/routes


# Accessing to our applications we can review proxying requests and limits applied

http ${PROXY_IP}:${HTTP_PORT}/text Host:red.example.com

http ${PROXY_IP}:${HTTP_PORT}/text Host:blue.example.com
11 changes: 9 additions & 2 deletions demo/DEMO_NGINX_Ingress_Controller_ActiveHealthChecks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ kubectl get pods -l app=blue

# And create /tmp/down on latest pod ...

kubectl exec -ti $(kubectl get pods -o name -l app=blue|tail -1|cut -d "/" -f2) -- touch /tmp/down
# We get latest pod
latest_blue_pod=$(kubectl get pods -o name -l app=blue|tail -1|cut -d "/" -f2)

# or
latest_blue_pod=$(kubectl get pods --selector=app=blue -o jsonpath='{.items[:1].metadata.name}')


kubectl exec -ti ${latest_blue_pod} -- touch /tmp/down


# And now we can review status again
Expand Down Expand Up @@ -93,7 +100,7 @@ http ${INGRESS_IP}:${INGRESS_HTTP_PORT}/text Host:blue.example.com

# Now we set "alive" our "failed" backend

kubectl exec -ti $(kubectl get pods -o name -l app=blue|tail -1|cut -d "/" -f2) -- rm /tmp/down
kubectl exec -ti ${latest_blue_pod} -- rm /tmp/down


# After some seconds, all backends will be available again
Expand Down
2 changes: 1 addition & 1 deletion demo/MinikubeKongQuickDemo.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export HTTPS_PORT=$(minikube service -n kong kong-proxy --url --format "{{ .Port

### Now we deploy colors-ingress ingress resource for accesing both applications
~~~
curl https://raw.githubusercontent.com/Codegazers/k8s-vagrant/master/examples/colors/colors-ingress.yml | kubectl create -f -
curl https://raw.githubusercontent.com/Codegazers/k8s-vagrant/master/examples/colors/colors-ingress.yml | kubectl apply -f -
~~~

### We just set up host routing
Expand Down
8 changes: 4 additions & 4 deletions demo/MinikubeNginxQuickDemo.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,16 @@ http --session red ${INGRESS_IP}:${INGRESS_HTTP_PORT}/text Host:red.example.com
~~~
Results will show same red application pod everytime we use same session.

## __NOTE:__
We can use curl too passing Cookie session id
## __NOTES:__

### We can use curl too passing Cookie session id
~~~
curl -vvv --resolve red.example.com:${INGRESS_HTTP_PORT}:${INGRESS_IP}-b "red_svc_id=<red_svc_id VALUE>" http://red.example.com:${INGRESS_HTTP_PORT}/text
~~~


~~~
-------


### Dashboard will be accesible on http://127.0.0.1:8080/dashboard.html after nginx-ingress pod port forwarding:
~~~
kubectl port-forward $(kubectl get pods -n nginx-ingress -o name) 8080:8080 --namespace=nginx-ingress
Expand Down

0 comments on commit 91ac909

Please sign in to comment.