KOPF
如果无法正常显示,请先停止浏览器的去广告插件。
相关话题:
#zalando
1. KOPF
Kubernetes
Operator
Pythonic
Framework
SERGEY VASILYEV
Twitter: @nolar
(Zalando SE)
Python Pizza Berlin, 23.08.2019
2. Kopf,
a Kubernetes Operator Pythonic Framework
Sergey Vasilyev
Twitter: @nolar
Zalando SE
Python Pizza Berlin, 23.08.2019
3. About me
● My name is Sergey Vasilyev
○ https://twitter.com/nolar
● Sr. Backend Engineer in Zalando SE.
● Running ML apps & infra on Kubernetes
for Zalando Pricing & Forecasting.
4. “Kubernetes is a container orchestrator”
5. Kubernetes under the hood
6. Extending Kubernetes: Custom Resource Definitions
7. Declaring a CRD
●
●
●
●
●
●
Required: “group/version”.
Required: kind/plural/singular names.
Required: scope (“Namespaced”).
Optional: short names (aliases).
Optional: list formatting and columns.
Optional: categories.
$ kubectl apply -f examples/crd.yaml
$ kubectl apply -f examples/obj.yaml
8. Extending Kubernetes: Controllers/Operators
9. Common use: an application-specific operator
https://github.com/zalando-incubator/es-operator
10. Problem: infrastructure code hassle
11. MAKE A FRAMEWORK!
12. Kopf: simple spy-handlers
●
●
●
As often, as the events arrive from K8s API.
Raw payload, no interpretation.
Fire-and-forget, ignore errors.
13. Kopf: convenient cause- & diff-handlers
14. Kopf: running from the development environment
$ kopf run scripts.py [--verbose]
And here we are! Creating: {'duration': '1m', 'field': 'value',
'items': ['item1', 'item2']}
[2019-02-25 14:06:54,742] kopf.reactor.handlin [INFO
]
[asf-preprocessing/kopf-example-1] Handler create_fn succeeded.
[2019-02-25 14:06:54,856] kopf.reactor.handlin [INFO
]
[asf-preprocessing/kopf-example-1] All handlers succeeded for
creation.
$ kubectl apply -f ../obj.yaml
$ kubectl describe -f ../obj.yaml
Name:
kopf-example-1
...
Status:
create_fn:
Message: hello world
Events:
Type
Reason
Age From
----
------
---- ----
Normal Success 81s kopf
Message
-------
Handler create_fn succeeded.
15. Features
●
●
●
●
Custom & built-in resources supported (crds, pods, services, etc).
Agnostic to API clients: kubernetes-client, pykube-ng, raw HTTP, etc.
Immediate reaction to changes and events.
Predefined behavioural patterns:
○
○
○
●
Operator resilience:
○
●
Simple spy-handlers for event watching.
Advanced cause & diff detection for actual change tracking.
Retry-until-success approach to handlers.
Restores its state on restarts.
Operator testing toolkit (minimally sufficient).
16. Roadmap
●
●
● Cross-handler communication and state management.
Cross-object interactions & relations (e.g. children pods of a parent resource).
Per-object thread/task orchestration handlers.
●
● Code generation (CRDs/RBAC/Dockerfile/etc), verification, packaging.
Integration with Operator Lifecycle Manager.
● Your suggestions? ;-)
17. Links
●
●
●
●
●
Kopf sources:
○ https://github.com/zalando-incubator/kopf
Kopf documentation:
○ https://kopf.readthedocs.io/
Kopf examples:
○ https://github.com/zalando-incubator/kopf/tree/master/examples
Other Zalando operators:
○ https://github.com/zalando-incubator/es-operator
○ https://github.com/zalando/postgres-operator
Me (Sergey Vasilyev):
○ https://twitter.com/nolar
○ https://www.linkedin.com/in/sergeyvasilyev/
18. THE END
(questions — later)