Skip to content

Latest commit

 

History

History

knative-go

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Tutorial: Restate and Knative

This tutorial shows how to set up Knative and Restate in a local Kubernetes cluster, to run the example shown in the Knative Restate blog post.

Requirements:

Set up the cluster

Set up the cluster using kn quickstart:

kn quickstart kind

And then set up the local registry using the provided script:

./install_registry.sh

The local registry will be used to push your application's image.

Deploy Restate

To deploy Restate, apply the Helm Chart:

helm install restate oci://ghcr.io/restatedev/restate-helm --namespace restate --create-namespace

The Helm chart setups a Restate instance in a restate namespace. It won't set up any Ingress though, so for the time being, in order to access Restate from the local machine, set up a port forwarding using kubectl:

kubectl port-forward -n restate svc/restate 9070:9070 8080:8080

Run:

restate whoami

And you should see at the bottom:

✅ Admin Service 'http://localhost:9070/' is healthy!

Deploy the golang application

Build with ko:

KO_DOCKER_REPO=localhost:5001 ko build main.go -B

And then deploy it with kn:

kn service create example \
  --image localhost:5001/main.go \
  --port h2c:8080

Now, you can register counter to Restate using:

restate deployments register http://example.default.svc

You will be asked for confirmation:

❯ SERVICES THAT WILL BE ADDED:
  - User
    Type: VirtualObject ⬅️ 🚶🚶🚶
     HANDLER     INPUT                                     OUTPUT                                   
     Activate    none                                      none                                     
     Get         none                                      value of content-type 'application/json' 
     Initialize  value of content-type 'application/json'  none                                     

  - Signup
    Type: Service 
     HANDLER  INPUT                                     OUTPUT                                   
     Signup   value of content-type 'application/json'  value of content-type 'application/json'                                           


✔ Are you sure you want to apply those changes? · yes

Confirm it, and now you're ready to invoke your signup.

Send requests

To send requests a signup request, just send an HTTP request to the signup service:

curl -v http://localhost:8080/Signup/Signup --json '{"username":"slinkydeveloper","name":"Francesco","surname":"Guardiani","password":"very-secret"}'

Now look into the logs of the running pod, you'll get the command to resolve the awakeable (simulating the email click):

kubectl logs -n default example-00001-deployment-<deployment_id>

The command should look like the following:

curl -v -X POST http://localhost:8080/restate/awakeables/<awakeable_id>/resolve

Now in the previous shell where you started the signup, you'll see the response:

The new user slinkydeveloper is signed up and activated

If you try to signup again re-executing the aforementioned signup request command, you'll get the following response:

{
  "code": 500,
  "message": "[500] the user was already initialized"
}

Next steps

To explore more, we suggest to take a look at our documentation.