* Update samples to not use Ingress. This is follow-up of https://github.com/knative/serving/pull/1228. We moved to Istio v1alpha3 / Gateway which requires a different way to get the external IP address to send traffic to our samples. * Also update the command to find service domain. |
||
---|---|---|
.. | ||
README.md | ||
sample.yaml |
README.md
Sample Function
A trivial function for HTTP events, which returns "Hello {name}"
, for a
querystring parameter name
.
This is based on the source code available from: github.com/steren/sample-function
Prerequisites
Running
You can deploy this to Knative Serving from the root directory via:
# Replace the token string with a suitable registry
REPO="gcr.io/<your-project-here>"
perl -pi -e "s@DOCKER_REPO_OVERRIDE@$REPO@g" sample/steren-function/sample.yaml
# Create the Kubernetes resources
kubectl apply -f sample/templates/node-fn.yaml -f sample/steren-function/sample.yaml
Once deployed, you will see that it first builds:
$ kubectl get revision -o yaml
apiVersion: v1
items:
- apiVersion: serving.knative.dev/v1alpha1
kind: Revision
...
status:
conditions:
- reason: Building
status: "False"
type: BuildComplete
...
Once the BuildComplete
status becomes True
the resources will start getting created.
To access this service via curl
, we first need to determine its ingress address:
$ watch kubectl get svc knative-ingressgateway -n istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
knative-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d
Once the ADDRESS
gets assigned to the cluster, you can run:
# Put the Host name into an environment variable.
export SERVICE_HOST=`kubectl get route steren-sample-fn -o jsonpath="{.status.domain}"`
# Put the ingress IP into an environment variable.
export SERVICE_IP=`kubectl get svc knative-ingressgateway -n istio-system -o jsonpath="{.status.loadBalancer.ingress[*].ip}"`
If your cluster is running outside a cloud provider (for example on Minikube),
your services will never get an external IP address. In that case, use the istio hostIP
and nodePort
as the service IP:
export SERVICE_IP=$(kubectl get po -l knative=ingressgateway -n istio-system -o 'jsonpath={.items[0].status.hostIP}'):$(kubectl get svc knative-ingressgateway -n istio-system -o 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
Now curl the service IP as if DNS were properly configured:
$ curl --header "Host:$SERVICE_HOST" http://${SERVICE_IP}/execute?name=${USER}
Hello mattmoor
Cleaning up
To clean up the sample service:
kubectl delete -f sample/templates/node-fn.yaml -f sample/steren-function/sample.yaml