Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

122 lines (85 sloc) 4.58 KB

Hello World Serving

Knative Serving has a samples page with helloworld demos for various languages. You can choose your language of choice. For the purposes of this tutorial, we will go with helloworld-csharp sample and assume .NET Core 2.2 runtime.

Hello World - .NET Core sample

Let's start with deploying an ASP.NET Core service on Knative as described on Hello World .NET - Core sample page with a few minor changes to the instructions:

  1. When building the Docker image, we tag our image with v1, v2, etc., so we can keep track of different versions of the service:

  2. instead of service.yaml, we use service-v1.yaml for the first version. Again, to keep track of different service versions better.

Build and push Docker image

With these changes in mind, in helloworld-csharp folder, build and push the container image. Replace meteatamel with your actual Docker Hub username:

docker build -t meteatamel/helloworld-csharp:v1 .

docker push meteatamel/helloworld-csharp:v1

Deploy the Knative service

Create a service-v1.yaml file.

apiVersion: serving.knative.dev/v1alpha1
kind: Service
metadata:
  name: helloworld-csharp
  namespace: default
spec:
  runLatest:
    configuration:
      revisionTemplate:
        spec:
          container:
            # replace meteatamel with your DockerHub 
            image: docker.io/meteatamel/helloworld-csharp:v1
            env:
              - name: TARGET
                value: "C# Sample v1"

After the container is pushed, deploy the app.

kubectl apply -f service-v1.yaml

Check that pods are created and all Knative constructs (service, configuration, revision, route) have been deployed:

kubectl get pod,ksvc,configuration,revision,route

NAME                                                      READY     STATUS    RESTARTS   
pod/helloworld-csharp-c4pmt-deployment-7fdb5c5dc9-wf2bp   3/3       Running   0          

NAME                                            
service.serving.knative.dev/helloworld-csharp   

NAME                                                  
configuration.serving.knative.dev/helloworld-csharp   

NAME                                                   
revision.serving.knative.dev/helloworld-csharp-00001   

NAME                                          
route.serving.knative.dev/helloworld-csharp   

(Optional) Install watch

Watch is a command-line tool that runs the specified command repeatedly and displays the results on standard output so you can watch it change over time. It can be useful to watch Knative pods, services, etc. If you're using Mac, you can install watch using homebrew or a similar tool.

To watch pods, Knative service, configuration, revision and route using watch, you can do this:

watch -n 1 kubectl get pod,ksvc,configuration,revision,route

Every 1.0s: kubectl get pod,ksvc,config...

NAME                                                     READY     STATUS    RESTARTS   AGE
pod/helloworld-csharp-00001-deployment-b6c485d9f-rm7l4   3/3       Running   0          1m

NAME                                            AGE
service.serving.knative.dev/helloworld-csharp   1m

NAME                                                  AGE
configuration.serving.knative.dev/helloworld-csharp   1m

NAME                                                   AGE
revision.serving.knative.dev/helloworld-csharp-c4pmt   1m

NAME                                          AGE
route.serving.knative.dev/helloworld-csharp   1m

Test the service

To test the service, we need to find the IP address of the Istio ingress gateway and the URL of the service.

The IP address of Istio ingress is listed under EXTERNAL_IP:

kubectl get svc istio-ingressgateway -n istio-system

Let's set this EXTERNAL_IP to an ISTIO_INGRESS variable:

export ISTIO_INGRESS=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')

The URL of the service follows this format: {service}.{namespace}.example.com. In this case, we have helloworld-csharp.default.example.com.

Make a request to your service:

curl -H "Host: helloworld-csharp.default.example.com" http://$ISTIO_INGRESS
Hello World C# v1

What's Next?

Configure Domain

You can’t perform that action at this time.