Deploying a Knative Service

In this tutorial, you will deploy a “Hello world” Knative Service that accepts the environment variable TARGET and prints Hello ${TARGET}!.

knYAML

Deploy the Service by running the command:

  1. kn service create hello \
  2. --image ghcr.io/knative/helloworld-go:latest \
  3. --port 8080 \
  4. --env TARGET=World

Expected output

  1. Service hello created to latest revision 'hello-0001' is available at URL:
  2. http://hello.default.${LOADBALANCER_IP}.sslip.io

The value of ${LOADBALANCER_IP} above depends on your type of cluster, for kind it will be 127.0.0.1 for minikube depends on the local tunnel.

  1. Copy the following YAML into a file named hello.yaml:

    1. apiVersion: serving.knative.dev/v1
    2. kind: Service
    3. metadata:
    4. name: hello
    5. spec:
    6. template:
    7. spec:
    8. containers:
    9. - image: ghcr.io/knative/helloworld-go:latest
    10. ports:
    11. - containerPort: 8080
    12. env:
    13. - name: TARGET
    14. value: "World"
  2. Deploy the Knative Service by running the command:

    1. kubectl apply -f hello.yaml

    Expected output

    1. service.serving.knative.dev/hello created