Knative Tutorial

At the end of this chapter you will be able to :

Prerequisite

The following checks ensure that each chapter exercises are done with the right environment settings.

  • Kubernetes

  • OpenShift

  • Set your local docker to use minikube docker daemon

eval $(minikube docker-env)

  • Kubernetes should be v1.12+

kubectl version

  • OpenShift CLI should be v4.1+

oc version

The output should be like

oc version
Client Version: version.Info{Major:"4", Minor:"1+", GitVersion:"v4.1.0+b4261e0", GitCommit:"b4261e07ed", GitTreeState:"clean", BuildDate:"2019-07-06T03:16:01Z", GoVersion:"go1.12.6", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"14+", GitVersion:"v1.14.6+73b5d76", GitCommit:"73b5d76", GitTreeState:"clean", BuildDate:"2019-09-23T16:18:51Z", GoVersion:"go1.12.8", Compiler:"gc", Platform:"linux/amd64"}
  • Make sure to be on knativetutorial OpenShift project

oc project -q

If you are not on knativetutorial project, then run following command to change to knativetutorial project:

oc project knativetutorial

Ensure Tekton piplines is deployed and the API is available for use

  • Kubernetes

  • OpenShift

kubectl api-resources --api-group='tekton.dev'

oc api-resources --api-group='tekton.dev'

The command show an output like:

NAME                SHORTNAMES   APIGROUP     NAMESPACED   KIND
clustertasks                     tekton.dev   false        ClusterTask
conditions                       tekton.dev   true         Condition
pipelineresources                tekton.dev   true         PipelineResource
pipelineruns        pr,prs       tekton.dev   true         PipelineRun
pipelines                        tekton.dev   true         Pipeline
taskruns            tr,trs       tekton.dev   true         TaskRun
tasks                            tekton.dev   true         Task

Verify the Tekton cli

tkn version

The command should show a result like:

Client version: 0.4.0

Create a pipeline resource

If you are not in tutorial chapter folder, then navigate to the folder:

cd $TUTORIAL_HOME/06-pipelines

The following snippet shows what a Knative service YAML looks like:

apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: git-source
spec:
  type: git
  params:
  - name: url
    value: https://github.com/redhat-developer-demos/knative-tutorial
  - name: revision
    value: release/0.7.x
---
apiVersion: tekton.dev/v1alpha1
kind: PipelineResource
metadata:
  name: knative-tutorial-greeter-image
spec:
  type: image
  params:
  - name: url
    value: "dev.local/rhdevelopers/knative-tutorial-greeter"
    # if you are on OpenShift uncomment the line below
    #value: "image-registry.openshift-image-registry.svc:5000/tutorial/helloworld"

Each pipeline resource has:

  • name: the name using which it will be referred in other places

  • type: the type of the pipeline resource, in this example we have two types

    • git - this type of resource refers to a GitHub repository

    • image - this type of resource is linux container image

  • params: each type can have one or more parameters that will be used to configure the underlying type. In the above example for the git-source pipeline resource, the parameters url and revision are used to identify the GitHub repository url and revision of the sources respectively.

More details on other types of pipeline resource types is available here.

Deploy a pipeline resource

The pipeline resource could be created using the command:

  • Kubernetes

  • OpenShift

kubectl create -n knativetutorial -f build-resources.yaml

oc create -n knativetutorial -f build-resources.yaml

See what you have deployed

We will use the Tekton cli to inspect the created resources

tkn res ls

The above command should list two resources as shown below:

NAME                             TYPE    DETAILS
git-source                       git     url: https://github.com/redhat-developer-demos/knative-tutorial
knative-tutorial-greeter-image   image   url: registry.kube-system:80/rhdevelopers/knative-tutorial-greeter

Use the command help via tkn res --help

e.g. Running a command tkn res describe git-source will return an output like:

Name:                    git-source
Namespace:               knativetutorial
PipelineResource Type:   git

Params
NAME       VALUE
url        https://github.com/redhat-developer-demos/knative-tutorial
revision   release/0.7.x

Secret Params
No secret params