⌨️Tutorial

An example GitOps recipe

This repository contains a PySpark example job (how did you guess it was word count?) that we are going to operationalize using Helm and databricks-kube-operator. You can follow along with a local minikube cluster, or use in an environment with ArgoCD or Fleet.

Create a Helm umbrella chart

Begin by creating a Helm umbrella chart. The Helm starter chart has unneeded example resources and values that we remove:

helm create example-job
rm example-job/templates/NOTES.txt
rm -rf example-job/templates/*.yaml
rm -rf example-job/templates/tests
echo > example-job/values.yaml

Your directory structure should look like this:

example-job
β”œβ”€β”€ Chart.yaml
β”œβ”€β”€ charts
β”œβ”€β”€ templates
β”‚   β”œβ”€β”€ NOTES.txt
β”‚   └── _helpers.tpl
└── values.yaml

In Chart.yaml, add a dependency to the operator chart:

dependencies:
  - name: databricks-kube-operator
    repository: https://mach-kernel.github.io/databricks-kube-operator
    version: 0.5.0

Populating Databricks resources

We are now going to create our resources in the templates/ directory.

1. Operator configmap and Databricks access token

Begin by creating a Databricks service principal, and use the according API call to create an access token. If your new service principal is unable to issue a token, enable token permissions for it by following the instructions from this KB.

In a production environment, the Databricks API URL and access token can be sourced via External Secrets Operator in combination with (e.g. AWS Secrets Manager).

Create a secret containing your Databricks API URL and a valid access token. The snippet below is for your convenience, to run against the cluster for this example. Do not create a template and check in your token.

Create the file below. The operator configmap expects a secret name from which to pull its REST configuration.

2. Git Credentials

Public repositories do not require Git credentials. The tutorial deploys the job from this public repository. You can skip this step, unless you are following along with your own job and a private repo.

Here is another "quick snippet" for making the required secret if deploying your own job from a private repo. As previously mentioned, do not check this in as a template.

Create the file below. According to the API documentation, the following VCS providers are available:

The available Git providers are awsCodeCommit, azureDevOpsServices, bitbucketCloud, bitbucketServer, gitHub, gitHubEnterprise, gitLab, and gitLabEnterpriseEdition.

3. DatabricksJob

Create the file below to create a job. There are two possible strategies for running jobs via Git sources. For more possible configuration, see the API SDK docs.

Does your job use an instance profile? You will have to give your new service principal access to the instance profile or your job will fail to launch.

Using the Git provider

If your credentials are configured, Databricks job definitions now support directly referencing a Git source. Whenever the job is triggered, it will use the latest version from source control without needing to poll the repo for updates.

Using the repos / workspace integration

Follow the optional Git Repo instructions before proceeding.

This is for use with the Repo API, which clones a repository to your workspace. Tasks are then launched from WORKSPACE paths. You can reuse the CRD from above removing git_source and changing the task definition to match the example below:

4. All together now

Awesome! We have templates for our shiny new job. Let's make sure the chart works as expected. Inspect the resulting templates for errors:

If everything looks good, it's time to install. Unfortunately this requires discussion of the dreaded "install CRDs first" problem. Here are suggestions for different readers:

  • Local/minikube: Comment out the dependency key and continue with installation

  • ArgoCD: Use sync waves

  • Fleet/others: Use one chart for your operator deployment, and another for the Databricks resources. On first deploy, the operator chart will sync successfully and example-job will do so on retry.

If successful, you should see the following Helm deployments, as well as your job in Databricks:

Bump the chart version for your Databricks definitions as they change, and let databricks-kube-operator reconcile them when they are merged to your main branch.

Optional: Git Repo

We recommend using the Git source for your job definitions, as databricks-kube-operator does not poll Databricks to update the workspace repository clone. PRs are accepted.

Create the file below to create a repo. Ensure that the /Test directory exists within Repos (docs) on your Databricks instance, or else the create request will 400:

Last updated