Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 79 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,79 @@
# morphlin
Kubernetes Operator SDK
# Getting Start with Operator SDK

## What’s Operator SDK?

## Guide assumptions

## Installation

## Creating a new project

Operator SDK comes with a number of code generators that are designed to facilitate development lifecycle. It helps create the project scaffolding, preprocess custom resource API to generate Kubernetes related code, generate deployment scripts -- just everything that is necessary to build an operator.

Navigate to `$GOPATH/src/github.com/example.com/`.

To start a project, we use the `new` generator to provide the foundation of a fresh operator project. Run the following command:

```
operator-sdk new play-operator
```

This will create the `play-operator` project with scaffolding with dependency code ready. It generates Kubernetes custom resource API of APIGroup `play.example.com` and Kind `PlayService` by default. APIGroups and Kinds can be overridden and added by flags.

Navigate to the project root folder:

```
cd play-operator
```

More details about the structure of the project can be found in [this doc][scaffold_doc].

## Up and running

At this point we are ready to build and deploy a functional operator. First build the binary and container:

```
operator-sdk build $image
docker push $image
```

Kubernetes deployment manifests will be generated in `deploy/play-operator/operator.yaml`. Deploy play-operator:

```
kubectl create -f deploy/play-operator/operator.yaml
```

The play-operator would be up and running:

```
# kubectl get deploy
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE
play-operator 1 1 1 1 1m
```

A `PlayService` CR with the following spec can be created to demonstrate the use of operator:

```
apiVersion: "play.coreos.com/v1"
kind: "PlayService"
metadata:
name: "example"
spec:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe no spec section? since we haven't defined any spec.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since we haven't defined any spec.

Can you make the default spec have a field replica?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk, i'll do that

replica: 1
```

Once the CR is created, a new pod `example-box` will be created:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mentioning ngix pod? if that's we are aiming for. I am fine with the current one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nginx, or busy loop, or just sleep.
Maybe modify this again once we have the implementation?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kk, maybe add a TODO so we don't forget?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is minor detail.
Let's not add a TODO in README.


```
# kubectl get pod
NAME READY STATUS RESTARTS AGE
example-box 2/2 Running 0 1m
```

This is a basic test that verifies everything works correctly. Next we are going to write the business logic and do something more interesting.


## Customizing operator logic


[scaffold_doc]:./doc/project_layout.md
6 changes: 6 additions & 0 deletions doc/project_layout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Project Scaffolding Layout

| File/Folders | Purpose |
| -------------- | --------------------------------- |
| cmd | main.go |
| config | config |