Tanzu Build Service (TBS) Setup

Complete guide for installing and configuring Tanzu Build Service for cloud-native buildpacks.

Table of Contents

Overview

Tanzu Build Service (TBS) uses Cloud Native Buildpacks to transform source code into container images. This guide covers:

  • Installing Kpack (open source foundation)
  • Installing TBS (commercial version)
  • Configuring builders and stores
  • Creating and managing image builds

Prerequisites

Software Requirements

  • Kubernetes 1.19+
  • kubectl CLI
  • kp CLI (TBS CLI)
  • Docker CLI

Registry Requirements

  • Harbor or other container registry
  • Registry credentials configured

Environment Variables

  • HARBOR_ADMIN_PASSWORD: Harbor admin password
  • DOCKER_HUB_USERNAME: Docker Hub username (for dependencies)

Kpack Installation

Install Kpack

Deploy Kpack to your cluster:

kubectl apply -f https://github.com/pivotal/kpack/releases/download/v0.5.3/release-0.5.3.yaml

Verify installation:

kubectl get pods -n kpack
kubectl api-resources | grep kpack

TBS Installation

Download TBS

Download TBS from Tanzu Network and extract:

tar -xvf build-service-1.4.0.tar
cd build-service-1.4.0

Configure Registry Secret

Create a secret for your registry:

kubectl create secret docker-registry registry-credentials \
  --docker-server=harbor.tkg.markalston.net \
  --docker-username=admin \
  --docker-password="${HARBOR_ADMIN_PASSWORD}" \
  --namespace build-service

Install TBS

Install TBS with your registry:

kp import -f descriptor-100.0.158.yaml \
  --registry harbor.tkg.markalston.net/tbs

Configuration

Create a Builder

Configure a builder with buildpacks:

apiVersion: kpack.io/v1alpha2
kind: Builder
metadata:
  name: my-builder
  namespace: default
spec:
  serviceAccountName: tbs-service-account
  tag: harbor.tkg.markalston.net/tbs/builder
  stack:
    name: base
    kind: ClusterStack
  store:
    name: default
    kind: ClusterStore
  order:
  - group:
    - id: tanzu-buildpacks/java
  - group:
    - id: tanzu-buildpacks/nodejs
  - group:
    - id: tanzu-buildpacks/go

Configure Service Account

Create a service account with registry access:

apiVersion: v1
kind: ServiceAccount
metadata:
  name: tbs-service-account
  namespace: default
secrets:
- name: registry-credentials
imagePullSecrets:
- name: registry-credentials

Usage

Create an Image Build

Define an image resource:

apiVersion: kpack.io/v1alpha2
kind: Image
metadata:
  name: my-app-image
  namespace: default
spec:
  tag: harbor.tkg.markalston.net/apps/my-app
  serviceAccountName: tbs-service-account
  builder:
    name: my-builder
    kind: Builder
  source:
    git:
      url: https://github.com/example/my-app
      revision: main

Monitor Build Progress

# Watch build logs
kp build logs my-app-image -n default

# Check build status
kp image status my-app-image -n default

# List all images
kp image list -n default

Update Dependencies

Update buildpacks and stacks:

# Update cluster store
kp clusterstore save default \
  --buildpackage harbor.tkg.markalston.net/tbs/java-buildpack

# Update cluster stack  
kp clusterstack update base \
  --build-image harbor.tkg.markalston.net/tbs/build:latest \
  --run-image harbor.tkg.markalston.net/tbs/run:latest

Advanced Configuration

Source Code from Registry

Use OCI registry for source:

spec:
  source:
    registry:
      image: harbor.tkg.markalston.net/source/my-app-source

Custom Environment Variables

Add build-time environment variables:

spec:
  build:
    env:
    - name: BP_JAVA_VERSION
      value: "11"
    - name: BP_MAVEN_BUILD_ARGUMENTS
      value: "-Dmaven.test.skip=true package"

Troubleshooting

Common Issues

Issue: Build fails with registry error

Verify registry credentials:

kubectl get secret registry-credentials -o yaml

Issue: Buildpack not found

Check available buildpacks:

kp clusterstore status default

Debug Commands

# Check build pods
kubectl get pods -n default | grep build

# View build logs
kubectl logs -n default <build-pod-name> -c completion

# Inspect image status
kubectl describe image my-app-image

Best Practices

  1. Use semantic versioning for image tags
  2. Configure resource limits for builds
  3. Regularly update buildpacks and stacks
  4. Use separate namespaces for different environments
  5. Implement image scanning policies

Integration Examples

With Tekton Pipelines

apiVersion: tekton.dev/v1beta1
kind: Task
metadata:
  name: buildpacks-build
spec:
  params:
  - name: source-url
  steps:
  - name: build
    image: gcr.io/paketo-buildpacks/builder:base
    command: ["/cnb/lifecycle/creator"]

With Knative Serving

apiVersion: serving.knative.dev/v1
kind: Service
metadata:
  name: my-knative-app
spec:
  template:
    spec:
      containers:
      - image: harbor.tkg.markalston.net/apps/my-app:latest

References


Last Updated: 2024 Part of the Homelab Documentation Series


This project is for educational and home lab purposes.