Hello World - Scala using Akka HTTP

    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:

    • A Kubernetes cluster installation with Knative Serving up and running.
    • installed locally, and running, optionally a Docker Hub account configured or some other Docker Repository installed locally.
    • Java JDK8 or later installed locally.
    • standard build tool sbt installed locally.

    Configuring the sbt build

    If you want to use your Docker Hub repository, set the repository to “docker.io/yourusername/yourreponame”.

    If you use Minikube, you first need to run:

    1. 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:

    1. 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:

    1. dockerRepository := Some("your_repository_name")

    You can learn more about the build configuration syntax .

    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.

    1. kind: Service
    2. metadata:
    3. name: helloworld-scala
    4. namespace: default
    5. template:
    6. spec:
    7. containers:
    8. - image: "your_repository_name/helloworld-scala:0.0.1"
    9. env:
    10. - name: MESSAGE
    11. value: "Scala & Akka on Knative says hello!"
    12. - name: HOST

    Publishing to Docker

    or

    1. sbt docker:publish

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

    yaml

    Apply the Service yaml definition:

    1. kubectl apply -f service.yaml

    kn

    With kn you can deploy the service with

    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:

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

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

    kubectl

    Then find the service host:

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

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

    kn

    1. kn service describe helloworld-scala -o url

    Example:

    1. http://helloworld-scala.default.1.2.3.4.sslip.io

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

      Cleanup

      kubectl

      1. kn service delete helloworld-scala