Hello World - Scala using Akka HTTP

A microservice which demonstrates how to get set up and running with Knative Serving when using Scala and Akka HTTP. It will respond to a HTTP request with a text specified as an ENV variable named MESSAGE, defaulting to "Hello World!".

Follow the steps below to create the sample code and then deploy the app to your cluster. You can also download a working copy of the sample, by running the following commands:

  1. git clone -b "{{< branch >}}" https://github.com/knative/docs knative-docs
  2. cd knative-docs/docs/serving/samples/hello-world/helloworld-scala

Before you begin

  • A Kubernetes cluster installation with Knative Serving up and running.
  • Docker installed locally, and running, optionally a Docker Hub account configured or some other Docker Repository installed locally.

Configuring the Service descriptor

Importantly, in service.yaml change the image reference to match up with your designated repository, i.e. replace {username} with your Dockerhub username in the example below.

  1. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. metadata:
  4. name: helloworld-scala
  5. namespace: default
  6. spec:
  7. template:
  8. spec:
  9. containers:
  10. - image: docker.io/{username}/helloworld-scala
  11. env:
  12. - name: TARGET
  13. value: "Scala Sample v1"

Publishing to Docker

In order to build the project and create and push the Docker image, run:

  1. # Build the container on your local machine
  2. docker build -t {username}/helloworld-scala .
  3. # Push the container to docker registry
  4. docker push {username}/helloworld-scala

Deploying to Knative Serving

Apply the Service yaml definition:

  1. kubectl apply --filename service.yaml

Then find the service host:

  1. kubectl get ksvc helloworld-scala \
  2. --output=custom-columns=NAME:.metadata.name,URL:.status.url
  3. # It will print something like this, the URL is what you're looking for.
  4. # NAME URL
  5. # helloworld-scala http://helloworld-scala.default.1.2.3.4.xip.io

Finally, to try your service, use the obtained URL:

  1. curl -v http://helloworld-scala.default.1.2.3.4.xip.io

Cleanup

  1. kubectl delete --filename service.yaml

Feedback

Was this page helpful?

Glad to hear it! Please tell us how we can improve.

Sorry to hear that. Please tell us how we can improve.