Deploying your first Knative Service

Tip

Hit . on your keyboard to move forward in the tutorial. Use , to go back at any time.

In this tutorial, you will deploy a “Hello world” service.

This service will accept an environment variable, TARGET, and print “Hello ${TARGET}!.”

Since our “Hello world” Service is being deployed as a Knative Service, not a Kubernetes Service, it gets some super powers out of the box 🚀.

Knative Service: “Hello world!”

kn

  1. kn service create hello \
  2. --image gcr.io/knative-samples/helloworld-go \
  3. --port 8080 \
  4. --env TARGET=World \
  5. --revision-name=world

Why did I pass in revision-name?

Note the name “world” which you passed in as “revision-name,” naming your Revisions will help you to more easily identify them, but don’t worry, you’ll learn more about Revisions later.

Expected output:

  1. Service hello created to latest revision 'hello-world' is available at URL:
  2. http://hello.default.127.0.0.1.nip.io

YAML

  1. apiVersion: serving.knative.dev/v1
  2. kind: Service
  3. metadata:
  4. name: hello
  5. spec:
  6. template:
  7. metadata:
  8. # This is the name of our new "Revision," it must follow the convention {service-name}-{revision-name}
  9. name: hello-world
  10. spec:
  11. containers:
  12. - image: gcr.io/knative-samples/helloworld-go
  13. ports:
  14. - containerPort: 8080
  15. env:
  16. - name: TARGET
  17. value: "World"

Once you’ve created your YAML file (named something like “hello.yaml”):

  1. kubectl apply -f hello.yaml

Why did I pass in the second name, hello-world?

Note the name “hello-world” which you passed in under “metadata” in your YAML file. Naming your Revisions will help you to more easily identify them, but don’t worry if this if a bit confusing now, you’ll learn more about Revisions later.

Expected output:

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

To see the URL where your Knative Service is hosted, leverage the kn CLI:

  1. kn service list

Ping your Knative Service

Ping your Knative Service by opening http://hello.default.127.0.0.1.nip.io in your browser of choice or by running the command:

  1. curl http://hello.default.127.0.0.1.nip.io

Expected output:

  1. Hello World!

Congratulations 🎉, you’ve just created your first Knative Service. Up next, Autoscaling!