Skip to content

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!".

Do the following steps 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:

git clone -b "main" knative-docs
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.
  • Java JDK8 or later installed locally.
  • Scala's standard build tool sbt installed locally.

Configuring the sbt build

If you want to use your Docker Hub repository, set the repository to "".

If you use Minikube, you first need to run:

eval $(minikube docker-env)

If want to use the Docker Repository inside Minikube, either set this to "dev.local" or if you want to use another repository name, then you need to run the following command after docker:publishLocal:

docker tag yourreponame/helloworld-scala:<version> dev.local/helloworld-scala:<version>

Otherwise Knative Serving won't be able to resolve this image from the Minikube Docker Repository.

You specify the repository in build.sbt:

dockerRepository := Some("your_repository_name")

You can learn more about the build configuration syntax here.

Configuring the Service descriptor

Importantly, in the service.yaml file, change the image reference to match up with the repository, name, and version specified in the build.sbt in the previous section.

kind: Service
  name: helloworld-scala
  namespace: default
        - image: "your_repository_name/helloworld-scala:0.0.1"
            - name: MESSAGE
              value: "Scala & Akka on Knative says hello!"
            - name: HOST
              value: "localhost"

Publishing to Docker

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

sbt docker:publishLocal


sbt docker:publish

Which of them to use is depending on whether you are publishing to a remote or a local Docker Repository.

Deploying to Knative Serving

Apply the Service yaml definition:

kubectl apply -f service.yaml

With kn you can deploy the service with

kn service create helloworld-scala{username}/helloworld-scala --env TARGET="Scala Sample v1"

This will wait until your service is deployed and ready, and ultimately it will print the URL through which you can access the service.

The output will look like:

``` Creating service 'helloworld-scala' in namespace 'default':

0.035s The Configuration is still working to reflect the latest desired specification.
0.139s The Route is still working to reflect the latest desired specification.
0.250s Configuration "helloworld-scala" is waiting for a Revision to become ready.
8.040s ...
8.136s Ingress has not yet been reconciled.
8.277s unsuccessfully observed a new generation
8.398s Ready to serve.

Service 'helloworld-scala' created to latest revision 'helloworld-scala-abcd-1' is available at URL: ```

Then find the service host:

kubectl get ksvc helloworld-scala \,URL:.status.url

# It will print something like this, the URL is what you're looking for.
# NAME                URL
# helloworld-scala

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

curl -v
kn service describe helloworld-scala -o url


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

curl -v


kubectl delete -f service.yaml
kn service delete helloworld-scala
Back to top

We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.

× OK