Developing Operators with Kubernetes Operator Pythonic Framework KOPF
如果无法正常显示,请先停止浏览器的去广告插件。
相关话题:
#zalando
1. Developing Operators with
Kubernetes Operator
Pythonic Framework
KOPF
KubeCon San Diego
2019-11-20
SERGEY VASILYEV
@nolar
2. About me
● My name is Sergey Vasilyev
○ https://twitter.com/nolar
● A Python developer from Siberia. Now in Berlin, Germany.
● ~20 years of experience in Software Engineering.
● In love with Python since 2009.
● Sr. Backend Engineer, Zalando SE.
● Running ML apps & infra on Kubernetes
for Zalando Pricing & Forecasting.
3. ABOUT US
4. ZALANDO AT A GLANCE
~ 5.4
billion EUR
> 300
million
revenue 2018
4
~ 14,000 > 80%
employees in
Europe of visits via
mobile devices
as of September 2019
visits
per
month
> 450,000
> 29 product choices
million > 2,000 17
brands countries
active customers
5. WE ARE CONSTANTLY INNOVATING TECHNOLOGY
help our brand to
HOME-BREWED,
CUTTING-EDGE
& SCALABLE
WIN ONLINE
technology solutions
7
international
tech locations
HQs
in Berlin
> 2,000
employees at
5
6. WE DRESS CODE
6
7. “Kubernetes is a container orchestrator”
8. Kubernetes under the hood
9. Extending Kubernetes: Custom Resource Definitions
10. Defining a custom resource
●
●
●
●
●
●
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 crd.yaml
$ kubectl apply -f obj.yaml
11. Extending Kubernetes: Controllers/Operators
12. Common use: an application-specific operator
https://github.com/zalando-incubator/es-operator
13. Common problem: infrastructure code hassle
14. MAKE A FRAMEWORK!
15. WILLKOMMEN, KOPF!
16. The simplest Kubernetes operator
17. The simplest Kubernetes operator
$ kubectl apply -f obj.yaml
$ kubectl describe -f obj.yaml
$ 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
[default/kopf-example-1] Handler create_fn succeeded.
]
[2019-02-25 14:06:54,856] kopf.reactor.handlin [INFO
]
[default/kopf-example-1] All handlers succeeded for creation.
Name:
kopf-example-1
...
Status:
create_fn:
Message: hello world
Events:
Type
Reason
Age From
----
------
---- ----
Normal Success 81s kopf
Message
-------
Handler create_fn succeeded.
18. Resource-watching handlers
●
●
●
●
As often, as the events arrive from K8s API.
Raw data, no interpretation.
Fire-and-forget, errors are ignored.
Similar to `kubectl get --watch`
19. Change-detection handlers
20. Error handling
21. Debugging & breakpoints
22. Other things
●
●
●
●
●
●
●
Python logging → Kubernetes Events.
Custom authentication → @on.login
@on.startup / @on.cleanup
Embeddable.
Testing toolkit.
Resource hierarchies.
And more…
● Other patterns? Create a feature request!
23. Cross-resource relations
24. Cross-resource relations
25. Kubernetes is an orchestrator of everything
26. Kubernetes is an orchestrator of everything
27. Kubernetes is an orchestrator of everything
28. Cross-cluster connectivity
29. Cross-cluster connectivity
30. FUTURE
● More patterns: cross-resource handlers.
● Reconciliation handlers: by time; threads/tasks.
● Admission handlers: validation/mutation.
● SDK: YAML from Python — CRDs, RBAC, Deployments.
● Operator Lifecycle Manager integration.
● More Kopf-based operators.
● Bring Python to Kubernetes, build a community.
● Conquer the world [of Kubernetes operators].
31. SUMMARY
●
●
●
●
●
●
●
●
Kubernetes operators can be easy.
Kubernetes operators can be ad-hoc.
Kubernetes operators can be Pythonic.
Kubernetes is an orchestrator of everything.
Focus on the domain, not on the infrastructure.
Simplicity & human-friendliness as the #1 priority.
Python community as a huge leverage for Kubernetes.
Use Kopf.
32. LINKS
●
●
● Source: https://github.com/zalando-incubator/kopf/
Examples: https://github.com/zalando-incubator/kopf/tree/master/examples
Documentation: https://kopf.readthedocs.io/
● Me (Sergey Vasilyev):
○ Twitter: @nolar
Us (Zalando SE):
○ Twitter: @ZalandoTech & https://jobs.zalando.com/tech/blog/
●
●
●
Other Zalando operators (not Kopf-based):
○ ElasticSearch operator: https://github.com/zalando-incubator/es-operator
○ Postgres operator: https://github.com/zalando/postgres-operator
Worth reading:
○ Kubernetes Failure Stories: https://k8s.af/
33. QUESTIONS?
SERGEY VASILYEV
SENIOR BACKEND ENGINEER
sergey.vasilyev@zalando.de
@nolar
34. Why Python? — Scale x15!