|
| 1 | +# Quick Start |
| 2 | + |
| 3 | +This Quick Start guide will cover. |
| 4 | + |
| 5 | +- Create a project |
| 6 | +- Create an API |
| 7 | +- Run the API |
| 8 | + |
| 9 | +## Installation |
| 10 | +{% method %} |
| 11 | + |
| 12 | +- Install [dep](https://github.com/golang/dep) |
| 13 | +- Download the latest release from the [releases page](https://github.com/kubernetes-sigs/kubebuilder/releases) |
| 14 | +- Extract the tar and move+rename the extracted directory to `/usr/local/kubebuilder` |
| 15 | +- Add `/usr/local/kubebuilder/bin` to your `PATH` |
| 16 | + |
| 17 | +{% sample lang="bash" %} |
| 18 | +```bash |
| 19 | +curl -L -O https://github.com/kubernetes-sigs/kubebuilder/releases/download/v0.1.X/kubebuilder_0.1.X_<darwin|linux>_amd64.tar.gz |
| 20 | + |
| 21 | +tar -zxvf kubebuilder_0.1.X_<darwin|linux>_amd64.tar.gz |
| 22 | +sudo mv kubebuilder_0.1.X_<darwin|linux>_amd64 /usr/local/kubebuilder |
| 23 | + |
| 24 | +export PATH=$PATH:/usr/local/kubebuilder/bin |
| 25 | +``` |
| 26 | +{% endmethod %} |
| 27 | + |
| 28 | +## Create a new API |
| 29 | + |
| 30 | +{% method %} |
| 31 | + |
| 32 | +#### Project Creation |
| 33 | + |
| 34 | +Initialize the project directory with the canonical project structure and go dependencies. |
| 35 | + |
| 36 | +{% sample lang="bash" %} |
| 37 | +```bash |
| 38 | +kubebuilder init --domain k8s.io |
| 39 | +``` |
| 40 | +{% endmethod %} |
| 41 | + |
| 42 | +{% method %} |
| 43 | + |
| 44 | +#### API Creation |
| 45 | + |
| 46 | +Create a new API called *Sloop*. The will create files for you to edit under `pkg/apis/<group>/<version>` and under |
| 47 | +`pkg/controller/<kind>`. |
| 48 | + |
| 49 | +**Optional:** Edit the schema or reconcile business logic in the `pkg/apis` and `pkg/controller` respectively, |
| 50 | +**then run** `kubebuilder generate`. For more on this see [What is a Controller](basics/what_is_a_controller.md) |
| 51 | +and [What is a Resource](basics/what_is_a_resource.md) |
| 52 | + |
| 53 | +{% sample lang="bash" %} |
| 54 | +```bash |
| 55 | +kubebuilder create resource --group ships --version v1beta1 --kind Sloop |
| 56 | +``` |
| 57 | +{% endmethod %} |
| 58 | + |
| 59 | +{% method %} |
| 60 | + |
| 61 | +#### Locally Running An API |
| 62 | + |
| 63 | +**Optional:** Create a new [minikube](https://github.com/kubernetes/minikube) cluster for development. |
| 64 | + |
| 65 | +Build and run your API by installing the CRD into the cluster and starting the controller as a local |
| 66 | +process on your dev machine. |
| 67 | + |
| 68 | +Create a new instance of your API and look at the controller-manager output. |
| 69 | + |
| 70 | +{% sample lang="bash" %} |
| 71 | +```bash |
| 72 | +GOBIN=${PWD}/bin go install ${PWD#$GOPATH/src/}/cmd/controller-manager |
| 73 | +bin/controller-manager --kubeconfig ~/.kube/config |
| 74 | +``` |
| 75 | + |
| 76 | +> In a new terminal create an instance of your API |
| 77 | +
|
| 78 | +```bash |
| 79 | +kubectl apply -f hack/sample/sloop.yaml |
| 80 | +``` |
| 81 | +{% endmethod %} |
| 82 | + |
| 83 | +{% method %} |
| 84 | + |
| 85 | +#### Adding Schema and Business Logic |
| 86 | + |
| 87 | +Further your API schema and resource, then run `kubebuilder generate`. |
| 88 | + |
| 89 | +{% sample lang="bash" %} |
| 90 | +```bash |
| 91 | +nano -w pkg/apis/ship/v1beta1/sloop_types.go |
| 92 | +... |
| 93 | +nano -w pkg/controller/sloop/controller.go |
| 94 | +... |
| 95 | +kubebuilder generate |
| 96 | +``` |
| 97 | +{% endmethod %} |
| 98 | + |
| 99 | +## Publishing |
| 100 | + |
| 101 | +{% method %} |
| 102 | + |
| 103 | +#### Integration Testing |
| 104 | + |
| 105 | +Run the generated integration tests for your APIS. |
| 106 | + |
| 107 | +{% sample lang="bash" %} |
| 108 | +```bash |
| 109 | +go test ./pkg/... |
| 110 | +``` |
| 111 | +{% endmethod %} |
| 112 | + |
| 113 | +{% method %} |
| 114 | + |
| 115 | +#### Controller-Manager Container and Installation YAML |
| 116 | + |
| 117 | +- Build and push a container image. |
| 118 | +- Create installation config for your API |
| 119 | +- Install with kubectl apply |
| 120 | + |
| 121 | +{% sample lang="bash" %} |
| 122 | + |
| 123 | +```bash |
| 124 | +docker build . -f Dockerfile.controller -t gcr.io/kubeships/controller-manager:v1 |
| 125 | +kubebuilder create config --controller-image gcr.io/kubeships/controller-manager:v1 --name kubeships |
| 126 | +``` |
| 127 | + |
| 128 | +```bash |
| 129 | +gcloud auth configure-docker |
| 130 | +docker push gcr.io/kubeships/controller-manager:v1 |
| 131 | +``` |
| 132 | + |
| 133 | +```bash |
| 134 | +kubectl apply -f hack/install.yaml |
| 135 | +``` |
| 136 | +{% endmethod %} |
| 137 | + |
| 138 | +{% method %} |
| 139 | + |
| 140 | +#### API Documentation |
| 141 | + |
| 142 | +Generate documentation: |
| 143 | + |
| 144 | +- Create an example of your API |
| 145 | +- Generate the docs |
| 146 | +- View the generated docs at `docs/reference/build/index.html` |
| 147 | + |
| 148 | +{% sample lang="bash" %} |
| 149 | +```bash |
| 150 | +kubebuilder create example --version v1beta1 --group ships.k8s.io --kind Sloop |
| 151 | +nano -w docs/reference/examples/sloop/sloop.yaml |
| 152 | +... |
| 153 | +``` |
| 154 | + |
| 155 | +```bash |
| 156 | +kubebuilder docs |
| 157 | +``` |
| 158 | +{% endmethod %} |
0 commit comments