Hello World - Kotlin

A simple web app written in Kotlin using Ktor that you can
use for testing. It reads in an env variable TARGET and prints “Hello
\${TARGET}“. If TARGET is not specified, it will use “World” as the TARGET.

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:

# Use the official gradle image to create a build artifact.# https://hub.docker.com/_/gradle FROM gradle:4.10 as builder# Copy local code to the container image. COPY build.gradle . COPY src ./src# Build a release artifact. RUN gradle clean build --no-daemon# Use AdoptOpenJDK for base image.# It's important to use OpenJDK 8u191 or above that has container support enabled.# https://hub.docker.com/r/adoptopenjdk/openjdk8# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds FROM adoptopenjdk/openjdk8:jdk8u202-b08-alpine-slim# Copy the jar to the production image from the builder stage. COPY --from=builder /home/gradle/build/libs/gradle.jar /helloworld.jar# Run the web service on container startup. CMD ["java", "-jar", "-Djava.security.egd=file:/dev/./urandom", "/helloworld.jar"]

Create a new file, service.yaml and copy the following service definition
into the file. Make sure to replace {username} with your Docker Hub
username.

After the build has completed and the container is pushed to docker hub, you
can deploy the app into your cluster. Ensure that the container image value
in service.yaml matches the container you built in the previous step. Apply
the configuration using kubectl:

kubectl apply --filename service.yaml

Now that your service is created, Knative will perform the following steps:

Automatically scale your pods up and down (including to zero active pods).

To find the IP address for your service, use
kubectl get service knative-ingressgateway --namespace istio-system to get
the ingress IP for your cluster. If your cluster is new, it may take sometime
for the service to get assigned an external IP address.

kubectl get service knative-ingressgateway --namespace istio-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
knative-ingressgateway LoadBalancer 10.23.247.74 35.203.155.229 80:32380/TCP,443:32390/TCP,32400:32400/TCP 2d
# Now you can assign the external IP address to the env variable.exportIP_ADDRESS=<EXTERNAL-IP column from the command above>
# Or just execute:exportIP_ADDRESS=$(kubectl get svc $INGRESSGATEWAY\
--namespace istio-system \
--output jsonpath="{.status.loadBalancer.ingress[*].ip}")