Quick Start

This Quick Start guide will cover:

Installation

Install kubebuilder:

  1. os=$(go env GOOS)
  2. arch=$(go env GOARCH)
  3. # download kubebuilder and extract it to tmp
  4. curl -sL https://go.kubebuilder.io/dl/2.0.0-beta.0/${os}/${arch} | tar -xz -C /tmp/
  5. # move to a long-term location and put it on your path
  6. # (you'll need to set the KUBEBUILDER_ASSETS env var if you put it somewhere else)
  7. sudo mv /tmp/kubebuilder_2.0.0-beta.0_${os}_${arch} /usr/local/kubebuilder
  8. export PATH=$PATH:/usr/local/kubebuilder/bin

You can also install a KubeBuilder master snapshot fromhttps://go.kubebuilder.io/dl/latest/${os}/${arch}.

Install kustomize v3.0.1+

Create a Project

Initialize a new project and Go module for your controllers:

  1. kubebuilder init --domain my.domain

If you’re not in GOPATH, you’ll need to run go mod init <modulename>in order to tell kubebuilder and Go the base import path of your module.

Create an API

Create a new API group-version called webapp/v1, and a kind Guestbookin that API group-version:

  1. kubebuilder create api --group webapp --version v1 --kind Guestbook

This will create the files api/v1/guestbook_types.go andcontroller/guestbook_controller.go for you to edit.

Optional: Edit the API definition or the reconciliation businesslogic. For more on this see What’s ina Controller and Designing anAPI.

Test It Out Locally

You’ll need a Kubernetes cluster to run against. You can useKIND to get a local cluster for testing, orrun against a remote cluster.

Your controller will automatically use the current context in yourkubeconfig file (i.e. whatever cluster kubectl cluster-info shows).

Install the CRDs into the cluster:

  1. make install

Run your controller (this will run in the foreground, so switch to a newterminal if you want to leave it running):

  1. make run

Install Samples

Create your samples (make sure to edit them first if you’ve changed theAPI definition):

  1. kubectl apply -f config/samples/

Run It On the Cluster

Build and push your image to the location specified by IMG:

  1. make docker-build docker-push IMG=<some-registry>/controller

Deploy the controller to the cluster:

  1. make deploy

If you encounter RBAC errors, you may need to grant yourself cluster-adminprivileges: