1 min • For Kubernetes developers: • The Golang programming patterns of Kubernetes (Controller, codegen etc) • Write your own Controller • gPRC based interface design in Kubernetes (CRI as example) • For Kubernetes users: • Effective pattern of programming based on Kubernetes • ⼴广告(Don’t worry, it’s not that kind of AD) • What I will not talk? • Kubernetes usage and under the hood • Internal systems or commercial software
Google • Successor of Google Borg/Omega system • One of the most popular open source projects in this world • Written by, and heavily depends on Golang
story: • https://github.com/google/lmctfy • Now think about a C/C++ based Kubernetes? • And, well designed programming patterns with powerful extensibility
co-scheduling I have many Pod replicas Service I want to proxy my Pod replicas Ingress I want to expose my Services DaemonSet I run as daemon StatefulSet I am stateful Job I only run for once CronJob I run periodically ConfigMap I read configure file Secret I need confidential data HPA I need auto-scaling
cluster state based on the changes to the API objects for { desired := getDesiredState() current := getCurrentState() makeChanges(desired, current) } • Write your own controller!
many Pod replicas Service I want to proxy my Pod replicas Ingress I want to expose my Services DaemonSet I run as daemon StatefulSet I am stateful Job I only run for once CronJob I run periodically ConfigMap I read configure file Secret I need confidential data HPA I need auto-scaling My Awesome Object I have my own special case
into k8s API • I want a controller to handle add/update/delete of all Asta Xie instances $ kubectl get astaxie NAME KIND astaxie1 AstaXie.v1.cr.client-go.k8s.io
Network object into k8s API • I want a controller to handle add/update/delete of all Network instances • onAdd: create Neutron network • onDelete: delete Neutron network • onUpdate: update Network object status • https://github.com/openstack/stackube/blob/master/pkg/network- controller/network_controller.go
client for type • client.Pod.Get().Resource(…).Do() • conversion-gen: seamless upgrades between API versions • apiVersion: k8s.io/v1alpha1 -> apiVersion: k8s.io/v1beta1 • deepcopy-gen: deepcopy • go get k8s.io/kubernetes/vendor/k8s.io/kube-gen/cmd/deepcopy-gen • deepcopy-gen -i ./pkg/apis/v1 • defaulter-gen: set default values for fields • go-to-protobuf: generate protobuf messages for your types • informer-gen: generate informers that can be used to watch for updates to your types • openapi-gen: generate openapi compatible API documentation
about design pattern in container world • decoupling containers • re-use images • well-designed architecture for your container workloads • “How can I build distributed micro-services with container?”
how it works (1 mins) 2.The heart of Kubernetes orchestration: Controller 3.Write your own Controller with CRD 4.code gen for deep copy, API conversion, API doc, encoding/decoding etc 5.gRPC based interface (e.g. CRI) 2.How we can do better to use Kubernetes? 1.Programming Patterns in Kubernetes 1.this is the main difference of Kubernetes with others 2.think about why everyone loves Borg