Creating a simple Knative build

Use this page to learn how to create and then run a simple build in Knative. In this topic, you create a Knative Build configuration file for a simple app, deploy that build to Knative, and then test that the build completes.

The following demonstrates the process of deploying and then testing that the build completed successfully. This sample build uses a hello-world-type app that uses busybox to simply print “hello build”.

Tip: See the build code samples for examples of more complex builds, including code samples that use container images, authentication, and include multiple steps.

Before you begin

Before you can run a Knative Build, you must have Knative installed in your Kubernetes cluster, and it must include the Knative Build component:

Creating and running a build

  1. Create a configuration file named build.yaml that includes the following code.

This Build resource definition includes a single “step” that performs the task of simply printing “hello build“:

   apiVersion: build.knative.dev/v1alpha1
   kind: Build
   metadata:
     name: hello-build
   spec:
     steps:
       - name: hello
         image: busybox
         args: ["echo", "hello", "build"]

Notice that this definition specifies kind as a Build, and that the name of this Build resource is hello-build. For more information about defining build configuration files, See the Build reference topic.

  1. Deploy the build.yaml configuration file and run the hello-build build on Knative by running the kubectl apply command:
   kubectl apply --filename build.yaml

Response:

   build "hello-build" created
  1. Verify that the hello-build build resource has been created by running the kubectl get command:
   kubectl get builds

Response:

   NAME          AGE
   hello-build   4s
  1. After the build is created, you can run the following kubectl get command to retrieve details about the hello-build build, specifically, in which cluster and pod the build is running:
   kubectl get build hello-build --output yaml

Response:

   apiVersion: build.knative.dev/v1alpha1
   kind: Build

   ...

   status:
     builder: Cluster
     cluster:
       namespace: default
       podName: hello-build-jx4ql
     conditions:
     - state: Complete
       status: "True"
     stepStates:
     - terminated:
         reason: Completed
     - terminated:
         reason: Completed

Notice that the values of completed indicate that the build was successful, and that hello-build-jx4ql is the pod where the build ran.

Tip: You can also retrieve the podName by running the following command:

   kubectl get build hello-build --output jsonpath={.status.cluster.podName}
  1. Optional: Run the following kubectl get command to retrieve details about the hello-build-[ID] pod, including the name of the Init container:
   kubectl get pod hello-build-[ID] --output yaml

where [ID] is the suffix of your pod name, for example hello-build-jx4ql.

The response of this command includes a lot of detail, as well as the build-step-hello name of the Init container.

Tip: The name of the Init container is determined by the name that is specified in the steps field of the build configuration file, for example build-step-[ID].

  1. To verify that your build performed the single task of printing “hello build”, you can run the kubectl logs command to retrieve the log files from the build-step-hello Init container in the hello-build-[ID] pod:
   kubectl logs $(kubectl get build hello-build --output jsonpath={.status.cluster.podName}) --container build-step-hello

Response:

   hello build

Learn more

To learn more about the objects and commands used in this topic, see:

For information about contributing to the Knative Build project, see the Knative Build code repo.


Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License.