Attribute | Details |
---|---|
Dapr runtime version | v1.5.0 |
Knative Serving version | v1.0 |
Language | Javascript, Python, Go, C# |
Environment | Kubernetes > v1.20 |
This is a distributed calculator application from Dapr quickstart using Knative Serving (with Kourier) to host React Calculator. This is built as a proof-of-concept to show how to use Knative Serving with Dapr.
This sample requires you to have the following installed on your machine:
Also, unless you have already done so, clone the repository with the samples and cd
into the right directory:
git clone https://github.com/dapr/samples.git
cd samples/knative-distributed-calculator
The first thing you need is an enabled Kubernetes cluster. This sample was tested on a fully-fledged cluster.
Once you have that make sure you get a positive response from the following kubectl command
kubectl get pods
This should either have output as No resources found in default namespace.
or should list the pods running the default
namespace.
Follow instructions to download and install the Dapr CLI and initialize Dapr.
Note: Here you can find full instruction of how to install and configure Knative Serving. All the information below in steps 3 and 4 is an excerpt from it which was used and tested.
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.0.0/serving-crds.yaml
kubectl apply -f https://github.com/knative/serving/releases/download/knative-v1.0.0/serving-core.yaml
kubectl apply -f https://github.com/knative/net-kourier/releases/download/knative-v1.0.0/kourier.yaml
kubectl patch configmap/config-network \
--namespace knative-serving \
--type merge \
--patch '{"data":{"ingress.class":"kourier.ingress.networking.knative.dev"}}'
kubectl get pods -n knative-serving
All pods inside knative-serving
namespace should have Running
or Completed
status.
kubectl --namespace kourier-system get service kourier
This sample was tested with real DNS. In this case, you need to take the External IP address from the previous step and add it to your DNS wildcard A
record (e.g. *.knative.example.com
).
Please change knative.example.com
below to your domain.
kubectl patch configmap/config-domain \
--namespace knative-serving \
--type merge \
--patch '{"data":{"knative.example.com":""}}'
Follow these instructions to create and configure a Redis store.
Here is a quick excerpt from it using Helm:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install redis bitnami/redis
Navigate to the deploy directory in this quickstart directory:
cd deploy
Deploy all of your resources:
kubectl apply -f .
Note: This is the same Distributed Calculator from quickstart except for the React deployment.
Get URL for your React application:
kubectl get service.serving
Example output:
NAME URL LATESTCREATED LATESTREADY READY REASON
calculator-front-end http://calculator-front-end.default.knative.example.com calculator-front-end-rev1 calculator-front-end-rev1 True
Make sure that READY
is set to True
. Otherwise, please wait until all the necessary components are configured by Knative. The address, in this case, is http://calculator-front-end.default.knative.example.com
.
Navigate to this address with your browser and you should see the distributed calculator. Do some calculations to make sure that all works as expected.
By default, Knative will scale to zero its workloads if there is no traffic to them. Wait for a couple of minutes and run the next command to list all pods in default
namespace:
kubectl get pods
Example output:
NAME READY STATUS RESTARTS AGE
addapp-86cfcb8969-mvzs8 2/2 Running 0 2d23h
divideapp-6b94b477f5-58n92 2/2 Running 0 2d23h
multiplyapp-545c4bc54d-n6vrd 2/2 Running 0 2d23h
redis-master-0 1/1 Running 0 2d23h
redis-replicas-0 1/1 Running 0 2d23h
redis-replicas-1 1/1 Running 0 2d23h
redis-replicas-2 1/1 Running 0 2d23h
subtractapp-5c6c6bc4fc-wlbqv 2/2 Running 0 2d23h
As you can see, there are no calculator-front-end
pods.
Navigate back to the address with your browser to generate some traffic.
Return back to and list all pods once again:
NAME READY STATUS RESTARTS AGE
addapp-86cfcb8969-mvzs8 2/2 Running 0 2d23h
calculator-front-end-rev1-deployment-6fd89f78df-6ttr2 3/3 Running 0 6s
divideapp-6b94b477f5-58n92 2/2 Running 0 2d23h
multiplyapp-545c4bc54d-n6vrd 2/2 Running 0 2d23h
redis-master-0 1/1 Running 0 2d23h
redis-replicas-0 1/1 Running 0 2d23h
redis-replicas-1 1/1 Running 0 2d23h
redis-replicas-2 1/1 Running 0 2d23h
subtractapp-5c6c6bc4fc-wlbqv 2/2 Running 0 2d23h
As you can see there is calculator-front-end-rev1-deployment-6fd89f78df-6ttr2
pod with 3 containers running inside: calculator-front-end
, queue-proxy
and daprd
.