Basics and Fundamentals
At the end of this chapter you will be able to :
-
Deploy a Knative service
-
View the Kubernetes resources created by Knative
-
Invoke the deployed Knative Service
Prerequisite
The following checks ensure that each chapter exercises are done with the right environment settings.
-
Set your local docker to use minikube docker daemon
eval $(minikube docker-env)
-
Kubernetes should be v1.23.0+
kubectl version --short
The output should be as shown
Client Version: v1.23.0
Server Version: v1.23.0
-
OpenShift CLI should be v4.8+
oc version
The output should be like
Client Version: 4.6.9
Kubernetes Version: v1.23.0
-
Make sure to be on
knativetutorial
OpenShift project
oc project -q
If you are not on knativetutorial
project, then run following command to change to knativetutorial
project:
oc project knativetutorial
Deploy Service
Navigate to the tutorial chapter’s folder serving:
The following snippet shows what a Knative service YAML looks like:
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: greeter
spec:
template:
spec:
containers:
- image: quay.io/rhdevelopers/knative-tutorial-greeter:quarkus
livenessProbe:
httpGet:
path: /healthz
readinessProbe:
httpGet:
path: /healthz
The service can be deployed using the following command:
kn service create greeter \
--image=quay.io/rhdevelopers/knative-tutorial-greeter:quarkus
kubectl apply -f $TUTORIAL_HOME/serving/service.yaml
After successful deployment of the service we should see a Kubernetes Deployment named similar to greeter-nsrbr-deployment
available:
kubectl get deployments
The actual deployment name may vary in your setup |
If you are on OpenShift, then you can deploy a Knative service by just click of buttons via OpenShift web console.
|
Invoke Service
http $(kn service describe greeter -o url)
export SVC_URL=`kubectl get rt greeter -o jsonpath={.status.url}` && \
http $SVC_URL
The http
command should return a response containing a line similar to:
Hi greeter => '6fee83923a9f' : 1
Sometimes the response might not be returned immediately especially when the pod is coming up from dormant state. In that case, repeat service invocation. |
Knative Resources
The Knative service that we deployed now, creates many Knative resources, the following commands will help you to query and find those resources:
configuration
kubectl get configurations.serving.knative.dev greeter
NAME LATESTCREATED LATESTREADY READY REASON
greeter greeter-00001 greeter-00001 True
routes
kn route list
NAME URL READY
greeter http://greeter.knativetutorial.example.com True
kubectl get routes.serving.knative.dev greeter
NAME URL READY REASON
greeter http://greeter.knativetutorial.192.168.64.13.nip.io True
revisions
kn revision list
kubectl get rev \
--selector=serving.knative.dev/service=greeter \
--sort-by="{.metadata.creationTimestamp}"
NAME SERVICE TRAFFIC TAGS GENERATION AGE CONDITIONS READY REASON
greeter-00001 greeter 100% 1 9m37s 3 OK / 4 True
|