Skip to content

Commit

Permalink
Merge pull request #1348 from IanLewis/thirdpartyresource-doc
Browse files Browse the repository at this point in the history
Created new ThirdPartyResource Glossary page.
  • Loading branch information
devin-donnelly authored Oct 5, 2016
2 parents 64239cc + 3965d87 commit bd0243c
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 0 deletions.
2 changes: 2 additions & 0 deletions _data/reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ toc:
path: /docs/user-guide/services/
- title: Service Accounts
path: /docs/user-guide/service-accounts/
- title: Third Party Resources
path: /docs/user-guide/thirdpartyresources/
- title: Volumes
path: /docs/user-guide/volumes/

Expand Down
118 changes: 118 additions & 0 deletions docs/user-guide/thirdpartyresources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
assignees:
- IanLewis

---

* TOC
{:toc}

## What is ThirdPartyResource?

Kubernetes comes with many built-in API objects. However, there are often times when you might need to extend Kubernetes with their own API objects in order to do custom automation.

`ThirdPartyResource` objects are a way to extend the Kubernetes API with a new API object type. The new API object type will be given an API endpoint URL and support CRUD operations, and watch API. You can then create custom objects using this API endpoint. You can think of `ThirdPartyResources` as being much like the schema for a database table. Once you have created the table, you can then start storing rows in the table. Once created, `ThirdPartyResources` can act as the data model behind custom controllers or automation programs.

## Structure of a ThirdPartyResource

Each `ThirdPartyResource` has the following:

* `metadata` - Standard Kubernetes object metadata.
* `kind` - The kind of the resources described by this third party resource.
* `description` - A free text description of the resource.
* `versions` - A list of the versions of the resource.

The `kind` for a `ThirdPartyResource` takes the form `<kind name>.<domain>`. You are expected to provide a unique kind and domain name in order to avoid conflicts with other `ThirdPartyResource` objects. Kind names will be converted to CamelCase when creating instances of the `ThirdPartyResource`. Hypens in the `kind` are assumed to be word breaks. For instance the kind `camel-case` would be converted to `CamelCase` but `camelcase` would be converted to `Camelcase`.

Other fields on the `ThirdPartyResource` are treated as custom data fields. These fields can hold arbitrary JSON data and have any structure.

You can view the full documentation about `ThirdPartyResources` using the `explain` command in kubectl.

```
$ kubectl explain thirdpartyresource
```

## Creating a ThirdPartyResource

When you user create a new `ThirdPartyResource`, the Kubernetes API Server reacts by creating a new, namespaced RESTful resource path. For now, non-namespaced objects are not supported. As with existing built-in objects, deleting a namespace deletes all custom objects in that namespace. `ThirdPartyResources` themselves are non-namespaced and are available to all namespaces.

For example, if a save the following `ThirdPartyResource` to `resource.yaml`:

```yaml
apiVersion: extensions/v1beta1
kind: ThirdPartyResource
metadata:
name: cron-tab.stable.example.com
description: "A specification of a Pod to run on a cron style schedule"
versions:
- name: v1
```
And create it:
```shell
$ kubectl create -f resource.yaml
thirdpartyresource "cron-tab.stable.example.com" created
```

Then a new RESTful API endpoint is created at:

`/apis/stable.example.com/v1/namespaces/<namespace>/crontabs/...`

This endpoint URL can then be used to create and manage custom objects.

## Creating Custom Objects

After the `ThirdPartyResource` object has been created you can create custom objects. Custom objects can contain custom fields. These fields can contain arbitrary JSON.
In the following example, a `cronSpec` and `image` custom fields are set to the custom `CronTab` object. If you save the following YAML to `my-crontab.yaml`:

```yaml
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
name: my-new-cron-object
cronSpec: "* * * * /5"
image: my-awesome-cron-image
```
and create it:
```shell
$ kubectl create -f my-crontab.yaml
crontab "my-new-cron-object" created
```

You can then manage our `CronTab` objects using kubectl. Note that resource names are not case-sensitive when using kubectl:

```shell
$ kubectl get crontab
NAME LABELS DATA
my-new-cron-object <none> {"apiVersion":"stable.example.com/v1","cronSpec":"...
```
You can also view the raw JSON data. Here you can see that it contains the custom `cronSpec` and `image` fields from the yaml you used to create it:
```yaml
$ kubectl get crontab -o json
{
"kind": "List",
"apiVersion": "v1",
"metadata": {},
"items": [
{
"apiVersion": "stable.example.com/v1",
"cronSpec": "* * * * /5",
"image": "my-awesome-cron-image",
"kind": "CronTab",
"metadata": {
"creationTimestamp": "2016-09-29T04:59:00Z",
"name": "my-new-cron-object",
"namespace": "default",
"resourceVersion": "12601503",
"selfLink": "/apis/stable.example.com/v1/namespaces/default/crontabs/my-new-cron-object",
"uid": "6f65e7a3-8601-11e6-a23e-42010af0000c"
}
}
]
}
```

0 comments on commit bd0243c

Please sign in to comment.