Tanzu Build Service uses the open-source Cloud Native Buildpacks project to turn application source code into container images. Build Service executes reproducible builds that align with modern container standards, and additionally keeps images up-to-date. It does so by leveraging Kubernetes infrastructure with kpack, a Cloud Native Buildpacks Platform, to orchestrate the image lifecycle. Tanzu Build Service helps customers develop and automate containerized software workflows securely and at scale.
In this post Tanzu Build Service will monitor git branch and automatically build containers with every push. Then it will upload that container to your image registry for you to pull down and run locally or on Kubernetes cluster
Tanzu Build Service Installation Pre-requisite
- Before we install Tanzu Build Service, you must ensure we have a Kubernetes cluster and ensure that all worker nodes have at least 50 GB of ephemeral storage allocated to them and also ensure your Kubernetes cluster is configured with default
To do this on Tanzu Kubernetes Grid Service, mount a 60GB volume at
/var/lib to the worker nodes in the
TanzuKubernetesCluster resource that corresponds to your TKGs cluster. I have used below yaml content for mounting volumes while creating Tanzu Kubernetes cluster.
storage: classes: - tanzu01 - tkgontkgs defaultClass: tkgontkgs topology: controlPlane: class: best-effort-medium count: 1 storageClass: tkgontkgs volumes: - capacity: storage: 60Gi mountPath: /var/lib workers: class: best-effort-medium count: 3 storageClass: tkgontkgs volumes: - capacity: storage: 60Gi mountPath: /var/lib
- Ensure you have access to an existing container registry or install one using this guidance, this will be used to install Tanzu Build Service and store the application images that will be created by build process.
- Also on a client VM from where you will connect to your Kubernetes cluster, install “docker cli” as well as install below tools , if you need guidance to install these tools, check Here
- Install kapp, this is a deployment tool that allows users to manage Kubernetes resources in bulk.
- Install ytt, this is a templating tool that understands YAML structure.
# wget -O ytt https://github.com/vmware-tanzu/carvel-ytt/releases/download/ v0.35.1/ytt-linux-amd64 #chmod +x ytt #mv ytt /usr/local/bin/ytt
- Install kbld,this is tool that builds, pushes, and relocates container images.
#wget -O kbld https://github.com/vmware-tanzu/carvel-kbld/releases/downloa d/v0.30.0/kbld-linux-amd64 #mv kbld /usr/local/bin/kbld #chmod +x /usr/local/bin/kbld
- Install kp, it controls the kpack installation on Kubernetes, download the
kpCLI for your operating system from the Tanzu Build Service page on Tanzu Network.
#mv kp-linux-0.3.1 /usr/local/bin/kp #chmod +x /usr/local/bin/kp
- Install imgpkg, it is a tool that relocates container images and pulls the release configuration files.
#wget -O imgpkg https://github.com/vmware-tanzu/carvel-imgpkg/releases/dow nload/v0.17.0/imgpkg-linux-amd64 #mv imgpkg /usr/local/bin/imgpkg #chmod +x /usr/local/bin/imgpkg
- and finally target the Kubernetes Cluster on which you want to install “Tanzu Build Service” using :
#kubectl config use-context <context-name>
Relocate Images to private Registry
First we need to relocate images from the Tanzu Network registry to an internal image registry and for that login to the image registry where you want to store the images by running:
#>docker login harbor.tanzu.zpod.io - <harbor.tanzu.zpod.io> - this is my private registry host name
Now login to the Tanzu Network registry with your Tanzu Network credentials:
#>docker login registry.pivotal.io
Now lets relocate the images to your local registry using “imgpkg” command:
#>imgpkg copy -b "registry.pivotal.io/build-service/bundle:1.2.2" --to-repo harbor.tanzu.zpod.io/tbs/build-service
This completes image relocation process, now lets move to installation.
Tanzu Build Service Installation
Pull the Tanzu Build Service bundle image on your client vm from your internal registry using
#>imgpkg pull -b "harbor.tanzu.zpod.io/library/build-service:1.2.2" -o /tmp/bundle
Use the Carvel tools
kbld, (those we installed in pre-requisite section) to install Build Service and define the required Build Service parameters by running:
#>ytt -f /tmp/bundle/values.yaml -f /tmp/bundle/config/ -f /tmp/ca.crt -v docker_repository='harbor.tanzu.zpod.io/tbs/build-service' -v docker_username='admin' -v docker_password='<password>' -v firstname.lastname@example.org' -v tanzunet_password='<password>'| kbld -f /tmp/bundle/.imgpkg/images.yml -f- | kapp deploy -a tanzu-build-service -f- -y #/tmp/ca.crt:-path to registry CA certificate #docker_repository:-image repository where TBS images exist
/tmp/ca.crt – is my CA certificate of the registry.if all above steps are correct, then you should see the “succeeded” as below.
that means, TBS installation is complete, lets move to next
Import Tanzu Build Service Dependency Resources
The Tanzu Build Service Dependencies like stacks, Buildpacks, Builders, etc. are used to build applications and keep them patched and These must be imported with the
kp cli and the Dependency Descriptor (
descriptor-<version>.yaml) file from the Tanzu Build Service Dependencies page
and now run below command to import all the dependencies
#>kp import -f /tmp/descriptor-100.0.146.yaml --registry-ca-cert-path /tmp/CA.cer
To verify Build Service installation, lets target the Kubernetes Cluster where Tanzu Build Service has been installed on and run “kp” command which we installed as part of pre-req.
List the cluster builders available in your installation using:
#> kp clusterbuilder list
you should see output like below.
Few Additional commands, you can also run
#> kp clusterstack list #> kp clusterstore list
This completes the installation of Tanzu build Service.
Build and Deploy a Sample App
First lets create a “secret” for “gitlab” as i have installed gitlab in to my vSphere Lab environment
#> kp secret create github-creds --git http://10.96.63.48 --git-user demoadmin -n tbs-demo
Lets also create secret for the private registry, in my case my registry is hosted on “harbor.tanzu.zpod.io” in vSphere environment
#> kp secret create my-registry-creds --registry harbor.tanzu.zpod.io --registry-user admin --namespace tbs-demo
With the next command, we are telling Tanzu Build Service where to retrieve the source code. Tanzu Build Service will be configured to watch the master branch by default, but you can configure it to watch your own development branch for whatever feature or bug you happen to be working on. Finally, the tag is where the image will be pushed in your registry. Lets create an image using source code from my git repository by running:
#>kp image create spring-petclinic --tag harbor.tanzu.zpod.io/library/sp ring-petclinic:latest --namespace tbs-demo --git http://10.96.63.48/demoadmin/wwcp.get
it will download its dependencies and start building image
Once completed, Tanzu Build Service will put a copy of the image into Harbor registry, as well as onto your local Kubernetes cluster within the default namespace.
You can check the image status by running below command.
We can now deploy this image either on local or Kubernetes environment or you can setup continuous deployment to deploy build images on any Kubernetes platform. in below example I am installing on my Tanzu Kubernetes cluster from the private registry where build service pushed the container image.
As you can see once image is deployed, i can access it easily from my browser successfully.
This completes the Step-by-Step procedure to install and use Tanzu Build Service. If you would like to dive deeper into VMware Tanzu Build Service, check out the documentation section.