Creating a Service

You can create a Knative service by applying a YAML file or using the kn service create CLI command.

Prerequisites

To create a Knative service, you will need:

Procedure

Tip

The following commands create a helloworld-go sample service. You can modify these commands, including the container image URL, to deploy your own application as a Knative service.

Create a sample service:

Apply YAML

  1. kubectl apply -f - <<EOF
  2. apiVersion: serving.knative.dev/v1
  3. kind: Service
  4. metadata:
  5. name: helloworld-go
  6. namespace: default
  7. spec:
  8. template:
  9. spec:
  10. containers:
  11. - image: gcr.io/knative-samples/helloworld-go
  12. env:
  13. - name: TARGET
  14. value: "Go Sample v1"
  15. EOF

kn CLI

  1. kn service create helloworld-go --image gcr.io/knative-samples/helloworld-go

After the service has been created, Knative performs the following tasks:

  • Creates a new immutable revision for this version of the app.
  • Performs network programming to create a route, ingress, service, and load balancer for your app.
  • Automatically scales your pods up and down based on traffic, including to zero active pods.