agent

by Helm

Helm chartv0.6.4App 3.25.0

Buildkite Agent Chart

About this chart

Running Buildkite agent

The buildkite agent is a small, reliable and cross-platform build runner that makes it easy to run automated builds on your own infrastructure. Its main responsibilities are polling buildkite.com for work, running build jobs, reporting back the status code and output log of the job, and uploading the job's artifacts. It is simple, lightweight hosted Buildkite CI/CD system which only requires to host agents in your Kubernetes cluster.

Introduction

This chart bootstraps a buildkite agent builder on a Kubernetes cluster using the Helm package manager. As it sets service account it can be used to build Docker images and deploy them using kubectl and helm clients in the same cluster where agents run, without any extra setup.

Add Buildkite Helm chart repository:

helm repo add buildkite https://buildkite.github.io/charts/
helm repo update

Installing the Chart

In order for the chart to configure the Buildkite Agent properly during the installation process, you must provide some minimal configuration which can't rely on defaults. This includes at least one element in the agent list token:

To install the chart with the release name bk-agent:

helm install --name bk-agent --namespace buildkite buildkite/agent \
    --set agent.token="BUILDKITE_AGENT_TOKEN"

To install the chart with the release name bk-agent and set Agent tags and git repo SSH key:

helm install --name bk-agent --namespace buildkite buildkite/agent \
  --set agent.token="$(cat buildkite.token)",agent.tags="role=production" \
  --set privateSshKey="$(cat buildkite.key)"  \
  --set registryCreds.gcrServiceAccountKey="$(cat gcr_service_account.key | base64)"

Alternatively, an external secret can be referenced for the agent token and agent SSH key:

helm install --name bk-agent --namespace buildkite buildkite/agent \
  --set agent.externalSecretName="buildkite-agent-secret",agent.tags="role=production" \
  --set agent.externalSecretTokenKey="agent-token",agent.externalSecretSSHKey="agent-ssh"

Note: if your pipeline uses docker for build images or run containers, you must set dind.enabled to true.

Where --set values contain:

agentToken: Buildkite token read from file
agentMeta: tagging agent with - role=production (to add multiple tags, you must separate them with an escaped comma, like this: role=production\,queue=kubernetes)
privateSshKey: private SSH key read from file
registryCreds.gcrServiceAccountKey: base64 encoded gcr_service_account.key json file

Tip: List all releases using helm list

Uninstalling the Chart

To uninstall/delete the bk-agent release:

helm delete bk-agent

The command removes all the Kubernetes components associated with the chart and deletes the release.

Configuration

The following table lists the configurable parameters of the buildkite chart and their default values.

ParameterDescriptionDefault
replicaCountReplicas count1
image.repositoryImage repositorybuildkite/agent
image.tagImage tag``
image.pullPolicyImage pull policyIfNotPresent
agent.externalSecretNameName of a Secret to load the agent token and agent private SSH key from. Takes precedence over .agent.token and .privateSshKeynil
agent.externalSecretTokenKeyName of the Key in the above secret where the agent token is locatedagent-token
agent.externalSecretSSHKeyName of the key in the above secret where the agent private SSH is locatednil
agent.tokenAgent tokenMust be specified unless agent.externalSecretName is set
agent.tagsAgent tagsrole=agent
agent.annotationExtra annotations for the generated Deployment{}
enableHostDockerMount docker sockettrue
podSecurityContextPod security context to set{}
securityContextContainer security context to set{}
extraEnvAgent extra env varsnil
privateSshKeyAgent ssh key for git access. Also see .agent.externalSecretNamenil
registryCreds.gcrServiceAccountKeyGCP Service account json keynil
registryCreds.dockerConfigPrivate registry docker config.jsonnil
entrypointdAdd files to /docker-entrypoint.d/ via a ConfigMap{}
serviceAccount.annotationExtra annotations for the generated ServiceAccount{}
rbac.createWhether to create RBAC resources to be used by the podfalse
rbac.role.rulesList of rules following the role specificationSee values.yaml
volumeMountsExtra volumeMounts configurationnil
volumesExtra volumes configurationnil
resourcesLiveness probe for docker socket{}
livenessProbePod resource requests & limits{}
nodeSelectorNode labels for pod assignment{}
tolerationsNode tolerations for pod assignment{}
affinityNode/pod affinity{}
podAnnotationsExtra annotation to apply to the pod{}
podContainersExtra pod container or sidecar configurationnil
podInitContainersExtra pod init containersnil
dind.enabledEnable preconfigured Docker-in-Docker (DinD) pod configurationfalse
dind.imageImage to use for Docker-in-Docker (DinD) pod containerdocker:19.03-dind
dind.portPort Docker-in-Docker (DinD) daemon listens on as REST request proxy2375
dind.mtuThe MTU used for Docker-inDocker (DinD) daemon. Must be lower than pod networking interface1500
dind.resourcesPod resource requests & limits for dind sidecar (if enabled){}
dind.volumeMountsExtra volumeMounts configurationnil
terminationGracePeriodSecondsDuration in seconds the pod needs to terminate gracefully30
nameOverrideProvide a name to override the default $name template variablenil
fullnameOverrideProvide a name to substitute for the full names of resourcesnil

Specify each parameter using the --set key=value[,key=value] argument to helm install.

Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example:

helm install --name bk-agent --namespace buildkite buildkite/agent -f values.yaml 

Tip: You can use the default values.yaml file

Buildkite pipeline examples

Check for examples of pipeline.yml and build/deploy scripts here.

Adding agent hooks to agent pods

Adding your own hooks (e.g. environment hooks) depends on whether you use DinD or not.

Without Docker-in-Docker

Without using DinD, you can follow the lower part of the guide here

With Docker-in-Docker

As the hooks directory is set to a shared dir, currently the best way to add your own hooks while using DinD consists of two steps.

  1. Follow the guide above for usage without DinD.
  2. Add an entrypoint script to your values.yml that copies the hooks from the image to the shared dir. E.g:
entrypointd: 
  01-copy-hooks: |
    #!/bin/sh
    set -euo pipefail
    mkdir -p /var/buildkite/hooks
    cp /buildkite/hooks/* /var/buildkite/hooks/.

Deploy agent with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has agent on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartagent is pinned at v0.6.4 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply