|
| 1 | +# Operator SDK |
| 2 | + |
| 3 | +### Project Status: pre-alpha |
| 4 | + |
| 5 | +The project is currently pre-alpha and it is expected that breaking changes to the API will be made in the upcoming releases. |
| 6 | + |
| 7 | +See the [design docs][design_docs] for planned work on upcoming milestones. |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +[Operators][operator_link] make it easy to manage complex stateful applications on top of Kubernetes. However writing an operator today can be difficult because of challenges such as using low level APIs, writing boilerplate, and a lack of modularity which leads to duplication. |
| 12 | + |
| 13 | +The Operator SDK is a framework designed to make writing operators easier by providing: |
| 14 | +- High level APIs and abstractions to write the operational logic more intuitively |
| 15 | +- Tools for scaffolding and code generation to bootstrap a new project fast |
| 16 | +- Modular functionality to improve reusability |
| 17 | + |
| 18 | +## Workflow |
| 19 | + |
| 20 | +The SDK provides the following workflow to develop a new operator: |
| 21 | +1. Create a new operator project using the SDK Command Line Interface(CLI) |
| 22 | +2. Define new resource APIs by adding Custom Resource Definitions(CRD) |
| 23 | +3. Specify resources to watch using the SDK API |
| 24 | +4. Define the operator reconciling logic in a designated handler and use the SDK API to interact with resources |
| 25 | +5. Use the SDK CLI to build and generate the operator deployment manifests |
| 26 | + |
| 27 | +At a high level an operator using the SDK processes events for watched resources in a user defined handler and takes actions to reconcile the state of the application. |
| 28 | + |
| 29 | +## Quick Start |
| 30 | + |
| 31 | +First, checkout and install the operator-sdk CLI: |
| 32 | + |
| 33 | +``` |
| 34 | +$ git checkout tags/v0.0.2 |
| 35 | +$ go install github.com/coreos/operator-sdk/commands/operator-sdk |
| 36 | +``` |
| 37 | + |
| 38 | +Create and deploy an app-operator using the SDK CLI: |
| 39 | + |
| 40 | +``` |
| 41 | +# Create an app-operator project that defines the App CR. |
| 42 | +$ cd $GOPATH/src/github.com/example-inc/ |
| 43 | +$ operator-sdk new app-operator --api-version=app.example.com/v1alpha1 --kind=App |
| 44 | +
|
| 45 | +# Build and push the app-operator image to a public registry such as quay.io |
| 46 | +$ operator-sdk build quay.io/example/app-operator |
| 47 | +$ docker push quay.io/example/app-operator |
| 48 | +
|
| 49 | +# Deploy the app-operator |
| 50 | +$ kubectl create -f deploy/rbac.yaml |
| 51 | +$ kubectl create -f deploy/operator.yaml |
| 52 | +
|
| 53 | +# By default, creating a custom resource (App) triggers the app-operator to deploy a busybox pod |
| 54 | +$ kubectl create -f deploy/cr.yaml |
| 55 | +
|
| 56 | +# Verify that the busybox pod is created |
| 57 | +$ kubectl get pod -l app=busy-box |
| 58 | +NAME READY STATUS RESTARTS AGE |
| 59 | +busy-box 1/1 Running 0 50s |
| 60 | +
|
| 61 | +# Cleanup |
| 62 | +$ kubectl delete -f deploy/cr.yaml |
| 63 | +$ kubectl delete -f deploy/operator.yaml |
| 64 | +$ kubectl delete -f deploy/rbac.yaml |
| 65 | +``` |
| 66 | + |
| 67 | +To learn more about the operator-sdk, see the [user guide][guide]. |
| 68 | + |
| 69 | + |
| 70 | +[operator_link]:https://coreos.com/operators/ |
| 71 | +[design_docs]:../design |
| 72 | +[guide]:./user_guide.md |
0 commit comments