Kubernetes
v1.8+ deployed somewhere. Minikube is a great way to get a cluster up quickly.kubectl
to interact with kubernetes.glooctl
to interact with gloo.azure
account
minikube start --extra-config=apiserver.Authorization.Mode=RBAC --cpus 4 --memory 4096
kubectl create clusterrolebinding permissive-binding \
--clusterrole=cluster-admin \
--user=admin \
--user=kubelet \
--group=system:serviceaccounts
glooctl install kube
Wait \ Verify that all the pods are in Running status:
kubectl get pods --all-namespaces
If you installed kubernetes using minikube as mentioned above, you can use this command:
export GATEWAY_URL=http://$(minikube ip):$(kubectl get svc ingress -n gloo-system -o 'jsonpath={.spec.ports[?(@.name=="http")].nodePort}')
mkdir joke-gen
cd joke-gen
Select functions app from list
Click create
- Give an application name
- Select your resource group previously created
- Give a name for storage account
Click create
Click Get publish profile
Save it in previously created directory
You should have file with a xml content looking like this
Create a very simple script to create kubernetes secret containing the publish profile data
(adjust the name of the secret in metadata)
#!/bin/bash
DATA=$(cat $1 | base64)
tee $2 <<EOF
apiVersion: v1
kind: Secret
metadata:
name: joke-gen
data:
publish_profile: $DATA
EOF
bash gen-secret.sh publish-profile-filename yaml-secret-file-name
# eg: bash gen-secret.sh gloo-azure-app.PublishSettings secret.yaml
You should get something like this
Note - Don't forget to create secret in gloo-system
namespace
# create
kubectl apply -f secret.yaml -n gloo-system
# check kubernetes
kubectl get secret -n gloo-system
+--------------------+------------------------------------+-------+-------+
| NAME | TYPE | DATA | AGE |
+--------------------+------------------------------------+-------+-------+
|default-token-jrhbj | kubernetes.io/service-account-token| 3 | 3d |
|joke-gen Opaque | | 1 | 1m |
+--------------------+------------------------------------+-------+-------+
# check gloo
glooctl secret get
+---------------------+---------+-----------+
| NAME | TYPE | IN USE BY |
+---------------------+---------+-----------+
| default-token-jrhbj | Unknown | |
| joke-gen | Unknown | |
+---------------------+---------+-----------+
For example a function that retrieve Chuck Norris jokes from an api
- Create a file (upstream.yaml) with this content
name: joke-gen-upstream
type: azure
spec:
secret_ref: joke-gen
function_app_name: gloo-azure-app
metadata:
annotations:
gloo.solo.io/azure_publish_profile: joke-gen
where
name
is the name of the upstreamsecret_ref
is the name of the secretfunction_app_name
is the name of the Azure Functions Appgloo.solo.io/azure_publish_profile
is the name of the secret. this annotation is mandatory
- Create the upstream
glooctl upstream create -f upstream.yaml
+-------------------+-------+--------+----------+
| NAME | TYPE | STATUS | FUNCTION |
+-------------------+-------+--------+----------+
| joke-gen-upstream | azure | | |
+-------------------+-------+--------+----------+
- Check functions discovery is ok
glooctl upstream get joke-gen-upstream
+-------------------+-------+--------+----------+
| NAME | TYPE | STATUS | FUNCTION |
+-------------------+-------+--------+----------+
| joke-gen-upstream | azure | | joke-gen |
+-------------------+-------+--------+----------+
You should see in column the names of your functions in azure function app
glooctl route create --sort \
--upstream joke-gen-upstream \
--function 'joke-gen' \
--path-exact /joke
+----+------------+-------------+------+--------+-----------------------+----------+-----------+
| ID | MATCHER | TYPE | VERB | HEADER | UPSTREAM | FUNCTION | EXTENSION |
+----+------------+-------------+------+--------+-----------------------+----------+-----------+
| 1 | /joke | Exact Path | * | | joke-gen-upstream | joke-gen | |
+----+------------+-------------+------+--------+-----------------------+----------+-----------+
If you installed kubernetes using minikube, you can use this command:
export GATEWAY_URL=http://$(minikube ip):$(kubectl get svc ingress -n gloo-system -o 'jsonpath={.spec.ports[?(@.name=="http")].nodePort}')
Try out the route using curl:
curl $GATEWAY_URL/joke
{"category":["dev"],"icon_url":"https://assets.chucknorris.host/img/avatar/chuck-norris.png","id":"ag_6paerrkg-mxfjjqw4ba","url":"https://api.chucknorris.io/jokes/ag_6paerrkg-mxfjjqw4ba","value":"Chuck Norris's beard can type 140 wpm."}