[Serverless Knative] Knative Docs - Deploying your first Knative Service
Deploying your first Knative Service
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 \ |
Expected output:
1 | Service hello created to latest revision 'hello-world' is available at URL: |
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.
YAML
1 | # hello.yaml |
Once you’ve created your YAML file (named something like “hello.yaml”):
1 | kubectl apply -f hello.yaml |
Expected output:
1 | service.serving.knative.dev/hello created |
To see the URL where your Knative Service is hosted, leverage the kubectl
CLI:
1 | kubectl get ksvc |
Expected output:
1 | NAME URL LATESTCREATED LATESTREADY READY REASON |
Or the kn
CLI:
1 | kn service list |
Expected output:
1 | NAME URL LATEST AGE CONDITIONS READY REASON |
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! |
Are you seeing curl
: (6) Could not resolve host: hello.default.127.0.0.1.nip.io
?
In some cases your DNS server may be set up not to resolve *.nip.io
addresses. If you encounter this problem, it can be fixed by using a different nameserver to resolve these addresses.
The exact steps will differ according to your distribution. For example, with Ubuntu derived systems which use systemd-resolved, you can add the following entry to the /etc/systemd/resolved.conf
:
1 | [Resolve] |
Then simply restart the service with sudo service systemd-resolved restart
.
For MacOS users, you can add the DNS and domain using the network settings as explained here - https://support.apple.com/en-gb/guide/mac-help/mh14127/mac.
Congratulations 🎉, you’ve just created your first Knative Service. Up next, Autoscaling!
References
[1] First Knative Service - Knative - https://knative.dev/docs/getting-started/first-service/