5.6 KiB
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:
-
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.
Creating and running a build
-
Create a configuration file named
build.yamlthat includes the following code.This
Buildresource 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
kindas aBuild, and that the name of thisBuildresource ishello-build. For more information about defining build configuration files, See theBuildreference topic. -
Deploy the
build.yamlconfiguration file and run thehello-buildbuild on Knative by running thekubectl applycommand:kubectl apply --filename build.yamlResponse:
build "hello-build" created -
Verify that the
hello-buildbuild resource has been created by running thekubectl getcommand:kubectl get buildsResponse:
NAME AGE hello-build 4s -
After the build is created, you can run the following
kubectl getcommand to retrieve details about thehello-buildbuild, specifically, in which cluster and pod the build is running:kubectl get build hello-build --output yamlResponse:
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: CompletedNotice that the values of
completedindicate that the build was successful, and thathello-build-jx4qlis the pod where the build ran.Tip: You can also retrieve the
podNameby running the following command:kubectl get build hello-build --output jsonpath={.status.cluster.podName} -
Optional: Run the following
kubectl getcommand to retrieve details about thehello-build-[ID]pod, including the name of the Init container:kubectl get pod hello-build-[ID] --output yamlwhere
[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-helloname of the Init container.Tip: The name of the Init container is determined by the
namethat is specified in thestepsfield 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 logscommand to retrieve the log files from thebuild-step-helloInit container in thehello-build-[ID]pod:kubectl logs $(kubectl get build hello-build --output jsonpath={.status.cluster.podName}) --container build-step-helloResponse:
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.