Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Write Kubernetes CustomController in Go

71c783224e1fccdb1d02ed37d494247f?s=47 moricho
December 04, 2019

Write Kubernetes CustomController in Go

71c783224e1fccdb1d02ed37d494247f?s=128

moricho

December 04, 2019
Tweet

More Decks by moricho

Other Decks in Programming

Transcript

  1. Write Kubernetes CustomController in Go golang.tokyo #28 Dec.4

  2. None
  3. OVERVIEW golang.tokyo #28 Dec.4 ɾk8sͷ༻ޠͷ͓͞Β͍ ɾcontroller-runtimeΛ࢖࣮ͬͨ૷ ɾk8sͷControllerͱ͸ʁ

  4. k8sͷ͓͞Β͍ ɾPod : ϫʔΫϩʔυͷ࠷খ୯Ґ ex. Goίϯςφ(API) + fluentdίϯςφ(logging) ɾReplicaSet :

    ͋ΔPodͷू߹
  5. k8sͷControllerͱ͸ʁ k8s͸Manifest(yaml)Ͱ๬·͍͠ঢ়ଶΛએݴ => ͦͷঢ়ଶΛҡ࣋͠ଓ͚Δ ref) Operator Basic in CNDK2019 -

    speakerdeck
  6. k8sͷControllerͱ͸ʁ

  7. k8sͷControllerͱ͸ʁ

  8. k8sͷControllerͱ͸ʁ

  9. k8sͷControllerͱ͸ʁ k8s͸಺෦Ͱ͜ͷॲཧΛ
 ܁Γฦ͍ͯ͠Δ => ͋Δ΂͖ঢ়ଶͱ
 ɹ ݱࡏͷঢ়ଶΛ߹ΘͤΔ

  10. CustomController controller͸ࣗલͰ࡞Δ͜ͱ΋Ͱ͖Δ => ͦΕ͕CustomController kubernetes-sigs/controller-runtime ͱ͍͏ϥΠϒϥϦ͕ఏڙ͞Ε͍ͯΔ

  11. controller-runtimeΛ ࢖࣮ͬͨ૷ ࠓճͷαϯϓϧɿ ReplicaSet͕࡞੒͞ΕͨΒɺ ͦͷ؅ཧԼͷίϯςφ໊Λදࣔ͢Δ ίϯτϩʔϥʔ

  12. controller-runtimeΛ ࢖࣮ͬͨ૷ (controller.go) ͲͷϦιʔεΛऔಘͯ͠ɺͲ͏͍͏ॲཧΛ࣮ߦ͢Δ͔ ɾ Reconciler ɾ

  13. controller-runtimeΛ ࢖࣮ͬͨ૷ (controller.go) Namespace, Ϧιʔε(ReplicaSet)Λࢦఆͯ͠ɺ Ϧιʔεͷ৘ใΛऔಘɺίϯςφ໊Λग़ྗ ɾ

  14. controller-runtimeΛ ࢖࣮ͬͨ૷ (main.go) ControllerΛੜ੒ ɾ ઌ΄Ͳఆٛͨ͠ReconcilerΛࢦఆ ɾ

  15. controller-runtimeΛ ࢖࣮ͬͨ૷ (main.go) ɾࢦఆͨ͠ϦιʔεΛControllerͰ؂ࢹ ɾ ɾReplicaSetʹߋ৽͕͋ͬͨΒɺઌ΄ͲͷॲཧΛ࣮ߦ

  16. controller-runtimeΛ ࢖࣮ͬͨ૷ ReplicaSetΛ࡞੒ͨ͠Βɺ ͦͷ؅ཧԼͷίϯςφͷ໊લ͕ දࣔ͞Εͨ 70ߦ͘Β͍Ͱ؆୯ʹॻ͚ͨ

  17. ࣮༻తͳControllerΛ࡞͍͖͍ͬͯͨ

  18. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ