Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Meetup - Principles of the kube api and how to extend it
1. Principles of the Kube API
and how to extend it
Dr. Stefan Schimanski
sttts@redhat.com
@the1stein
Cloud Native Computing Meetup Berlin, April 25 2017
27. ThirdPartyResources are limited
• no version conversion
• no defaulting
• no validation
• no subresources (scale, status)
• no admission
• alpha ⇒ API might change, beta proposal is in discussion
• demand is high, expect improvements in 1.7+
• Today‘s users of TPRs:
https://gist.github.com/philips/a97a143546c87b86b870a82a753db14c
30. $ kubectl get namespaces --watch --no-headers |
while read NS STATUS TIME ; do
# do whatever you like here, e.g. change the namespace
echo "$NS changed“
done
⟲
$ curl -f 'http://127.0.0.1:8080/api/v1/namespaces?watch=true&resourceVersion=4711‘
{"type":"ADDED","object":{"kind":"Namespace","apiVersion":"v1","metadata":{"name ...
{"type":“MODIFIED","object":{"kind":"Namespace","apiVersion":"v1","metadata":{"name ...
{"type":“DELETED","object":{"kind":"Namespace","apiVersion":"v1","metadata":{"name ...
32. Why
• ThirdPartyResources are limited
• no version conversion
• no defaulting
• no validation
• no subresources (scale, status)
• no admission
• Some things need full power of Go
• Service catalog
• OpenShift PaaS
• other powerful APIs
≫ Goal: allow powerful extensions without modifying Kubernetes itself
33. Alpha in v1.6: k8s.io/apiserver
• generic apiserver library in Go
• today used inside
• kube-apiserver
• federation apiserver
• service catalog
• allows creation of custom apiservers in a couple hundred lines of code
• each custom apiserver is its own process, communicating via HTTPS
• delegates authentication/authorization to kube-apiserver
• uses etcd storage (possibly shared with kube)
46. Status
• is part of Kubernetes 1.6 as an alpha
• https://github.com/kubernetes/sample-apiserver
• kube-aggregator integrated into kube-apiserver in 1.7
53. Restful
http API
mux
pkg/apis/batch
type Jobs struct
pkg/apis/batch/v2alp
ha1
type Jobs struct
api.Sche
me api.Scheme.Convert(&job, &v1job)
POST
/apis/batch/v2alpha1/jobs
k8s.io/apiserver
pkg/endpoints/handlers.CreateNamedResource
binary
JSON
payload
Go struct
v2alpha1.Job
HTTP
Request
Go struct
internal.Job
Store
k8s.io/apiserver
pkg/registry/generic
Storage
k8s.io/apiserver
pkg/storage/etcd3
ProtoBuf
Job
Go struct
v2alpha1.Job
etcd
54. type Scheme struct
• AddKnownTypes(gv, obj Object)
• Default(src Object)
• Copy(src Object) Object
• Convert(in, out interface{})
• New(gvk) Object
ApiGroup
pkg/apis/batch
pkg/apis/batch/v1
pkg/apis/batch/v2alpha1
pkg/apis/batch/register.go
pgk/apis/batch/install
Group
Version
Kind
Resource
type Object interface
• GetObjectKind() string
client-go/pkg/api.Scheme
client-go/pkg/api.Codecs
Discovery
type APIGroupList struct
type APIVersions struct
type APIResourceList struct
GroupVersionKind „gvk“
GroupVersionResource
Unversioned types
Unstructured
List
Registry / Storage
type Storage interface
type Lister interface
type Updater interface
type Getter interface
type Deleter interface
....
deepcopy-gen
conversion-gen
defaulting-gen
Code Generation
type OwnerReference struct
type ObjectReference struct
type TypeMeta struct
type ObjectMeta struct
Meta
api.Scheme
api.Codecs
api.Registry
api.GroupFactoryRegistry
Globals