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 can run a Knative Build, you must have Knative installed in your Kubernetes cluster, and it must include the Knative Build component:
-
For details about installing a new instance of Knative in your Kubernetes cluster, see Installing Knative.
-
If you have a component of Knative installed and running, you must ensure that the Knative Build component is also installed.
-
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 aBuild
, and that the name of thisBuild
resource ishello-build
. For more information about defining build configuration files, See theBuild
reference topic. -
Deploy the
build.yaml
configuration file and run thehello-build
build on Knative by running thekubectl apply
command:kubectl apply --filename build.yaml
Response:
build "hello-build" created
-
Verify that the
hello-build
build resource has been created by running thekubectl get
command:kubectl get builds
Response:
NAME AGE hello-build 4s
-
After the build is created, you can run the following
kubectl get
command to retrieve details about thehello-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 thathello-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}
-
Optional: Run the following
kubectl get
command to retrieve details about thehello-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 examplehello-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 thesteps
field of the build configuration file, for examplebuild-step-[ID]
. -
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 thebuild-step-hello
Init container in thehello-build-[ID]
pod:kubectl logs $(kubectl get build hello-build --output jsonpath={.status.cluster.podName}) --container build-step-hello
Response:
hello build
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.