1
0
mirror of https://github.com/tektoncd/catalog.git synced 2024-12-03 07:00:01 +00:00
catalog/kn
Navid Shaikh fa97c4d820 Default kn image to the latest released version
Use `latest` tag for kn image at https://gcr.io/knative-releases/knative.dev/client/cmd/kn
 which points to the latest released version of kn.
 User can still parameterize the kn image to use, for example nightly build of kn image
 at https://gcr.io/knative-nightly/knative.dev/client/cmd/kn:latest
2020-02-24 05:28:42 -06:00
..
knative-dockerfile-deploy Update README and align the numbered list 2020-02-10 01:53:56 -06:00
kn-deployer.yaml Array arguments based kn task 2019-09-24 08:28:12 -05:00
kn.yaml Default kn image to the latest released version 2020-02-24 05:28:42 -06:00
OWNERS Add initial OWNERS to some folders 📄 2019-10-23 04:53:23 -05:00
README.md Use serviceAccountName instead of serviceAccount 💺 2020-01-28 05:23:52 -06:00

Knative with kn

This Task performs operations on Knative resources (services, revisions, routes) using kn CLI.

Install the Task

kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/kn/kn.yaml

Inputs

Parameters

  • kn-image: kn CLI container image to run this task.

    default: gcr.io/knative-releases/knative.dev/client/cmd/kn:v0.10.0

    You can use nightly build of the kn CLI using gcr.io/knative-nightly/knative.dev/client/cmd/kn.

  • ARGS: The arguments to pass to kn CLI. default: ["help"]

Resources

  • image: An image-type PipelineResource specifying the location of the container image to deploy for Knative Service.

    User provides the image-type resource to kn CLI in parameter ARGS as an element of the array, for e.g. "--image=$(inputs.resources.image.url)".

Usage

Authorizing the Deployment

In order to create Knative services, you must first define a ServiceAccount with permission to manage Knative resources.

To create a ServiceAccount with these permissions, you can run:

kubectl apply -f https://raw.githubusercontent.com/tektoncd/catalog/master/kn/kn-deployer.yaml

Running the Task

Let's take examples of creating and updating a Knative Service using kn task.

  1. Following TaskRun runs the Task to create a Knative Service using given image.
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  generateName: kn-create-
spec:
  serviceAccountName: kn-deployer-account  # <-- run as the authorized SA
  taskRef:
    name: kn
  inputs:
    resources:
    - name: image
      resourceSpec:
        type: image
        params:
        - name: url
          value: gcr.io/knative-samples/helloworld-go
    params:
    - name: ARGS
      value:
      - "service"
      - "create"
      - "hello"
      - "--force"
      - "--image=$(inputs.resources.image.url)"

Run this with:

kubectl create -f kn-create-taskrun.yaml
  1. Following TaskRun runs the Task to update a Knative Service using given image or parameters.
apiVersion: tekton.dev/v1alpha1
kind: TaskRun
metadata:
  generateName: kn-update-
spec:
  serviceAccountName: kn-deployer-account  # <-- run as the authorized SA
  taskRef:
    name: kn
  inputs:
    resources:
    - name: image
      resourceSpec:
        type: image
        params:
        - name: url
          value: gcr.io/knative-samples/helloworld-go
    params:
    - name: ARGS
      value:
      - "service"
      - "update"
      - "hello"
      - "--image=$(inputs.resources.image.url)"
      - "--env=TARGET=Tekton"

Run this with:

kubectl create -f kn-update-taskrun.yaml

In these examples, the image resource can be built before hand, most likely using a previous task.

Pipeline

Checkout the sample Pipelines for building your git source and deploying as Knative Service here.