# Overview

Workload Deploy Applications and Routes

# What is Knative?

Knative is a Kubernetes-based platform to easily deploy and manage modern container workloads and includes a comprehensive feature-set to provide a full Platform-as-a-Service experience for Kubernetes users and developers alike.

It provides components that enable:

  • Rapid deployment of serverless containers and applications
  • Autoscaling including scaling pods down to zero
  • Support for multiple networking layers to provide automatic routing features
  • Point-in-time snapshots of deployed code and configurations

Check out the official documentation here (opens new window) for more information on Knative.

# Quick Tutorial

# Install the Knative CLI

The Knative CLI (kn) provides a quick and easy interface for creating Knative resources, such as Knative Services and Event Sources, without the need to create or modify YAML files directly.

kn also simplifies completion of otherwise complex procedures such as autoscaling and traffic splitting.

Detailed documentation on kn can be found here (opens new window), as well as a list of all commands available (opens new window).

You can install kn by downloading the executable binary for your system and placing it in the system path.

  1. Download the binary for your system from the kn release page (opens new window) (use v0.26.0 for this demo).

  2. Rename the binary to kn and make it executable by running the commands:

    $ mv <path-to-binary-file> kn
    $ chmod +x kn
    

    Where path-to-binary-file is the path to the binary file you downloaded in the previous step, for example, kn-darwin-amd64 or kn-linux-amd64.

  3. Move the executable binary file to a directory on your PATH by running the command:

    $ mv kn /usr/local/bin
    
  4. Verify that the plugin is working by running the command:

    $ kn version
    

# Deploy an application

# Knative Service: "Hello world!"

The easiest way to get started is to just directly deploy an application with kn:

$ kn --namespace demo \
  service create hello-world \
  --image gcr.io/knative-samples/helloworld-go \
  --port 8080 \
  --env TARGET=World

Expected output:

Creating service 'hello-world' in namespace 'demo':

  0.073s The Route is still working to reflect the latest desired specification.
  0.140s ...
  0.159s Configuration "hello-world" is waiting for a Revision to become ready.
 26.017s ...
 26.190s Ingress has not yet been reconciled.
 26.344s Waiting for Envoys to receive Endpoints data.
 26.980s Waiting for load balancer to be ready
 41.133s Ingress has not yet been reconciled.
 41.186s Waiting for Envoys to receive Endpoints data.
 41.709s Waiting for load balancer to be ready
 56.451s Ingress has not yet been reconciled.
 56.514s Waiting for Envoys to receive Endpoints data.
 57.113s Waiting for load balancer to be ready
 57.413s Ready to serve.

Service 'hello-world' created to latest revision 'hello-world-00001' is available at URL:
https://hello-world.demo.kube-plus.cloud

Open https://hello-world.demo.kube-plus.cloud (opens new window) in browser to see your hello-world application up and running.

# Knative YAML

Instead of using kn you could have just as well defined a YAML file and deployed it with kubectl onto the Kubernetes-cluster:

# knative-hello-world.yaml
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: hello-world
  namespace: demo
spec:
  template:
    spec:
      containers:
      - image: gcr.io/knative-samples/helloworld-go
        ports:
        - containerPort: 8080
        env:
        - name: TARGET
          value: "World"
$ kubectl -n demo apply -f knative-hello-world.yaml

The result would be the same as with kn.

Last Updated: 9/12/2022, 7:31:38 PM