How to Access a Knative Service?
I was getting confused and frustrated working with different platforms for running Knative experiments, specifically, what should be the IP_ADDRESS in this curl
command? 🤔
curl -H "Host: helloworld-nodejs.default.example.com" http://{IP_ADDRESS}
Hello Node.js Sample v1!
I generally switch among the following platforms on my Mac to experiment Knative Serving samples/features/use cases:
Here is my cheat sheet on how to access a sample Knative service on all three platforms:
Minikube
Step 1: Determine which Gateway are you using. This mostly sets the gateway to istio-ingressgateway
since Knative 0.3.x and onwards use istio-ingressgateway
.
INGRESSGATEWAY=knative-ingressgateway
if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
INGRESSGATEWAY=istio-ingressgateway
fi
Step 2: Find the IP address of your cluster with the Port
echo $(minikube ip):$(kubectl get svc $INGRESSGATEWAY --namespace istio-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
192.168.64.19:31282
Step 3: Access the Knative Service
curl -H "Host: helloworld-nodejs.default.example.com" http://192.168.64.19:31282
Hello Node.js Sample v1!
Docker For Desktop
Step 1: Determine which Gateway are you using
INGRESSGATEWAY=knative-ingressgateway
if kubectl get configmap config-istio -n knative-serving &> /dev/null; then
INGRESSGATEWAY=istio-ingressgateway
fi
Step 2: Find the NodePort of the ingress gateway for port 80
echo $(kubectl get svc $INGRESSGATEWAY --namespace istio-system --output 'jsonpath={.spec.ports[?(@.port==80)].nodePort}')
31082
Step 3: Access the Knative Service
curl -H "Host: helloworld-nodejs.default.example.com" http://127.0.0.1:31082
Hello Node.js Sample v1!
IBM Cloud
Step 1. Determine the Host
kubectl get ksvc helloworld-nodejs
NAME DOMAIN LATESTCREATED LATESTREADY READY REASON
helloworld-nodejs helloworld-nodejs.default.<cluster-name>.<region>.containers.appdomain.cloud helloworld-nodejs-f2w4p helloworld-nodejs-f2w4p True
Step 2. Access the Knative Service
curl helloworld-nodejs.default.<cluster-name>.<region>.containers.appdomain.cloud
Hello Node.js Sample v1!
Hopefully this cheat sheet is helpful and minimizes any confusion with your cluster IP and Port. 👍