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

Operator 101

1cf2de2da02f94ad87a7a31038721e6c?s=47 capsmalt
December 20, 2019

Operator 101

Operator 101 〜Operatorに手足をつっこんでみようか。レッツエンジョイ〜
@capsmalt (Kazufumi Saito), Red Hat K.K.

2019/12/20
OpenShift.Run

11/28CNDKの資料を少しアップデートした内容です。あくまで101ではありますが,誰かしらのお役に立てると嬉しいです。

1cf2de2da02f94ad87a7a31038721e6c?s=128

capsmalt

December 20, 2019
Tweet

Transcript

  1. 1 0 @     1

  2.      2

  3. Copyright 2019 Red Hat K.K. . ( ) . !

    3
  4. Copyright 2019 Red Hat K.K. ! 4

  5. Copyright 2019 Red Hat K.K.     !

    5
  6. l eo T i T @ N T aI F

    I 1 4 3 2 d N # NF T C I I T M F F 66 777 60 4. 6 2 6 46 / 1 7 60/ 66 777 60 4. 6 2 6 46 / 1 7 60/ 66 777 60 4. 6 2 6 46 / 1 7 60/ 66 777 60 4. 6 2 6 46 / 1 7 60/ 6
  7. Copyright 2019 Red Hat K.K.   7

  8. Copyright 2019 Red Hat K.K.   8

  9. Copyright 2019 Red Hat K.K. ) ( ) https://qiita.com/capsmalt/items/496942c823f5cf0f307d 9

  10.    10

  11.    11

  12.  12

  13. 8 / / ) (/ . / @ K L

    I / 13
  14. Cloud Native Meetup Tokyo Cloud Native Developer JP ) ()

    ) 14
  15. https://openshift.connpass.com/ OpenShift UserGroup 15

  16. 1 0 @     16

  17. Copyright 2019 Red Hat K.K.  17

  18. Copyright 2019 Red Hat K.K. 8 K 8= C +

    ) + (+ +  /    18
  19. Copyright 2019 Red Hat K.K. 19

  20. Copyright 2019 Red Hat K.K. ? 20

  21. Today’s Agenda 1 2 3 Kubernetes Core Why / What

    Operator How to get Operator 21
  22. Copyright 2019 Red Hat K.K. 22

  23. Copyright 2019 Red Hat K.K. ( ) ) ) )

    ) ) ) ) K ( ! %$       &# ("'   23
  24. Copyright 2019 Red Hat K.K. N M N P3 N

    1 P 2 a a 24
  25. Copyright 2019 Red Hat K.K.   25

  26. Copyright 2019 Red Hat K.K. . 3 : ) )

    ) ( ( : N 3 26
  27. Copyright 2019 Red Hat K.K. 3 N ( ( :

    N ( 2 3 2 . ) ( ) ) ) 3 c e` c K ad b : i 3 27
  28. Copyright 2019 Red Hat K.K.     

        28
  29. Copyright 2019 Red Hat K.K.     

           29
  30. Copyright 2019 Red Hat K.K. )( ( ) ) )

    (          30
  31. Copyright 2019 Red Hat K.K. ( ( ) ( -

    ( ( - ) ( ) ( 31
  32. Copyright 2019 Red Hat K.K. o .- . - •

    • . - • .- • • . • 32
  33. Copyright 2019 Red Hat K.K. " -  . -

    - - -   33
  34. Copyright 2019 Red Hat K.K.     

    34
  35. Copyright 2019 Red Hat K.K. Cloud Infrastructure Resources Hardware, Virtualization,

    Cloud and Service Provider Certifications CI/CD Workload Serverless Workload Machine Learning Workload IoT Workload Workload Abstraction Any Applications Resource Abstraction Any Resources Company Core Value? (*Not Kubernetes) 8 C 8 => K ) ( ) 35
  36. Copyright 2019 Red Hat K.K. 36

  37. Copyright 2019 Red Hat K.K. 37

  38. Copyright 2019 Red Hat K.K. https://www.cncf.io/projects/ 38

  39. Copyright 2019 Red Hat K.K. + + 39

  40. Copyright 2019 Red Hat K.K. M DCAN I G FB

    40
  41. Copyright 2019 Red Hat K.K. ! 41

  42. Copyright 2019 Red Hat K.K. 2 7 00 - ,2

    , 0 : , 7, S 7 IE LC A S EC LCH S LMI S LCLP M CLP KK S II 1H CLH C A E LK S LH A KCKL S ,A KK A KK L A LCH S -HKL H L C A K S MCE IEHP 1 LBH HEHAP S E L H 1H CLH C A E LK S 1 L C A B A D S E L H M CLP - C A S A - C A S M CLP LC C LCH K S 2 LOH D HEC P S CK KL HN P S KHM A L LCH S IA L B S E L H IA L B S A IA L B S II IA L B S M CLP L B K S H LC MHMK M CLP C A S 1MELC NC H L HEEHML S , L I CK H L C ACKL P S EMKL II ,E KLC CLP S 1H CLH E L C L S 0HA AA A LCH c R RV g eb kl i faVh T dUYT HM 7B 2 O L D 7B L L H LB /M L K , HKPKL MAMKL & % 42
  43. Copyright 2019 Red Hat K.K.    / b

    gpim : a K a lc nhe od b k     - . - // / / / - . / - - 43
  44. Copyright 2019 Red Hat K.K. Cloud Infrastructure Resources Hardware, Virtualization,

    Cloud and Service Provider Certifications CI/CD Workload Serverless Workload Machine Learning Workload IoT Workload Workload Abstraction Any Applications Resource Abstraction Any Resources Company Core Value? (*Not Kubernetes) C V 8 => K ) ( ) 8 K C 8 44
  45. Copyright 2019 Red Hat K.K.  45

  46. Copyright 2019 Red Hat K.K.  46

  47. Copyright 2019 Red Hat K.K.  47

  48. Copyright 2019 Red Hat K.K. 8 K 8= C +

    ) + (+ +  /    48
  49. Copyright 2019 Red Hat K.K.     o

    ) ) o o o J P ( o         or  49
  50. Copyright 2019 Red Hat K.K. . 4 1 o o

    o O o o o . o S o o o 50
  51. Copyright 2019 Red Hat K.K. •  •  

    •    51
  52. Copyright 2019 Red Hat K.K. ) • N ) (

    P • N ) ( P • R ) ( O • ) ) ) O ) ) / 52
  53. Copyright 2019 Red Hat K.K. • ()P • ()P •

    P () • C ( () RNO ( ) ) / 53
  54. Copyright 2019 Red Hat K.K. 54

  55.   55

  56. Copyright 2019 Red Hat K.K. . . / - /

    - - . --. / -. / -/ 56
  57. Copyright 2019 Red Hat K.K. /66 5 . 7 4.

    6/ 1 6-15 . 7 4. 57
  58. Copyright 2019 Red Hat K.K. :  . - /

    1-81 - . 1 1.. / 58
  59. Copyright 2019 Red Hat K.K. G s : / -

    - - . : / .B/ G HP G Sb km .B/ HPon dg l pr KO - a iu . Ct efD hc . / . . A . 59
  60. - . - / .  / 60

  61. / - / - . ./ . . / .

    . . ./ . 61
  62. Copyright 2019 Red Hat K.K. o P L o C

    L o ( R o ) / / L A o I O 62
  63. Copyright 2019 Red Hat K.K.   2.3 413 D

    C D 1 431 .3 C 2.3 413 1 5 C5 63
  64. Copyright 2019 Red Hat K.K. $ operator-sdk new memcached-operator (

    ) ( . 1 64
  65. Copyright 2019 Red Hat K.K. $ operator-sdk add api --api-

    version=cache.example.com/v1alpha1 --kind=Memcached (pkg/apis/cache/v1alpha1/memcached_types.g D A . C 2 type MemcachedSpec struct { // Size is the size of the memcached deployment Size int32 `json:"size"` } type MemcachedStatus struct { // Nodes are the names of the memcached pods // +listType=set Nodes []string `json:"nodes"` } 65
  66. Copyright 2019 Red Hat K.K. ) D . $ operator-sdk

    generate k8s $ operator-sdk generate openapi 2 ( 2AC 66
  67. Copyright 2019 Red Hat K.K. $ operator-sdk add controller --api-

    version=cache.example.com/v1alpha1 --kind=Memcached err := c.Watch( &source.Kind{Type: &cachev1alpha1.Memcached{}}, &handler.EnqueueRequestForObject{}, ) (pkg/controller/memcached/memcached_controlle A C . I 3 err := c.Watch( &source.Kind{Type: &appsv1.Deployment{}}, &handler.EnqueueRequestForOwner{ IsController: true, OwnerType: &cachev1alpha1.Memcached{}}, ) https://github.com/operator-framework/operato sdk/blob/master/example/memcached- operator/memcached_controller.go.tmpl 67
  68. Copyright 2019 Red Hat K.K. func (r *ReconcileMemcached) Reconcile(request reconcile.Request)

    (reconcile.Result, error) { // Lookup the Memcached instance for this reconcile request memcached := &cachev1alpha1.Memcached{} err := r.client.Get(context.TODO(),request.NamespacedName, memcached) ... } )) . ()( ( 3 68
  69. Copyright 2019 Red Hat K.K. $ operator-sdk build quay.io/capsmalt/memcached-operator:v0.0.1 )4

    - C D $ docker push quay.io/capsmalt/memcached-operator:v0.0.1 serviceAccountName: memcached-operator containers: - name: memcached-operator # Replace this with the built image name image: quay.io/capsmalt/memcached-operator:v0.0.1 command: - memcached-operator imagePullPolicy: Always (deploy/operator.yaml) $ kubectl create -f deploy/crds/cache.example.com_memcacheds_crd.yaml & ( .-. 4 - C D I A 69
  70. Copyright 2019 Red Hat K.K. $ kubectl create -f deploy/operator.yaml

    ( 4 ) BDA C $ kubectl create -f deploy/service_account.yaml $ kubectl create -f deploy/role.yaml $ kubectl create -f deploy/role_binding.yaml & C ( 4 ) . 4 C $ kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE memcached-operator 1 1 1 1 1m $ kubectl get pod NAME READY STATUS RESTARTS AGE memcached-operator-7d76948766-nrcp7 1/1 Running 0 1m 70
  71. Copyright 2019 Red Hat K.K. apiVersion: "cache.example.com/v1alpha1" kind: "Memcached" metadata:

    name: "example-memcached" spec: size: 3 (deploy/crds/cache.example.com_v1alpha1_Memcached_cr.yaml) $ kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml 71
  72. Copyright 2019 Red Hat K.K. D .)() 5 1 .

    C $ kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE memcached-operator 1 1 1 1 2m example-memcached 3 3 3 3 1m $ kubectl get pods NAME READY STATUS RESTARTS AGE example-memcached-5cc7c78d6-g6h6d 1/1 Running 0 2m example-memcached-5cc7c78d6-g5k7v 1/1 Running 0 2m example-memcached-5cc7c78d6-m7vn7 1/1 Running 0 2m memcached-operator-7gd6csgfd6-vvjqk 1/1 Running 0 3m 72
  73. Copyright 2019 Red Hat K.K. ( 53- 2 . (

    ) apiVersion: "cache.example.com/v1alpha1" kind: "Memcached" metadata: name: "example-memcached" spec: size: 5 $ kubectl apply -f deploy/crds/cache.example.com_v1alpha1_memcached_cr.yaml $ kubectl get deployment NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE example-memcached 5 5 5 5 10m 73
  74. Copyright 2019 Red Hat K.K. $ operator-sdk new memcached-operator \

    --api-version=cache.example.com/v1alpha1 \ --kind=Memcached --type=ansible Creates: • Ansible Role • Mapping File (watches.yaml) • Custom Resource Definition • Deploy manifest for the new Operator # watches.yaml --- - version: v1alpha1 group: cache.example.com kind: Memcached playbook: /path/to/playbook 74
  75. Copyright 2019 Red Hat K.K. / .- ./ . -

    . ./ . -/ - . - - ./ . 75
  76. 1 - ) ( -- - . / . 76

  77. /- / / . /. . -   77

  78. - ) ( . 78

  79. Copyright 2019 Red Hat K.K. / . ./ - .

    - ./ . / 79
  80. ) (. 80

  81. Copyright 2019 Red Hat K.K. . . , , -

    . . . - h yb , O fc HGu d sp t glrn 4 . . K A m w e AW RM i S a W AW o 81
  82. Copyright 2019 Red Hat K.K.     

      / / / / / / 82
  83. Copyright 2019 Red Hat K.K. 83

  84. Copyright 2019 Red Hat K.K. . ./ 84

  85. Copyright 2019 Red Hat K.K. 85

  86. Copyright 2019 Red Hat K.K. A L H I ,

    ( , (( , ((( , (/ , / ( A BA A A B A A , A B B A B ) A B B ( A A A D BA , A F A A BA AB A A B AB 41 $+) /$.'/ 5092 "=3 & !)/ $ -=3 % !$ 41+ !+ - ;: < $+ )/*# , % '+* ./  %  41 , ,$ ( />86 7(+/ % 86
  87. Copyright 2019 Red Hat K.K. 87

  88. Copyright 2019 Red Hat K.K. + 88

  89. Copyright 2019 Red Hat K.K. ( ) + = “create

    new operator”   Kubernetes Operator Operator SDK DEV Deployment Role ClusterRole RoleBinding ClusterRoleBinding ServiceAccount CustomResourceDefinition 89
  90. Copyright 2019 Red Hat K.K. ( ) + = “create

    new operator”         + Kubernetes Operator Operator SDK DEV 90
  91. Copyright 2019 Red Hat K.K. ) ( ( ) (

    ( 91
  92. - . - / .  / 92

  93. Copyright 2019 Red Hat K.K. . E = D /

    + + D 93
  94. Copyright 2019 Red Hat K.K.     

                   ( )           94
  95. Copyright 2019 Red Hat K.K. < - - + .

    + . - - - $ :- - : - - .+ . . . + R A NEI M ID E += ./ = A N - - - - - $ - - - - + +/. > - - 95
  96. Copyright 2019 Red Hat K.K. A . / . =

    = . / = / A/ = = U RS DI E M N = D I A = / / = + 96
  97. Copyright 2019 Red Hat K.K. ) ( -( C E

    C : A ) A DDD C E I S C E C : A ) Q N TM - ) ( -( c ye / A hl / A ye e g P : Aa / A ye Q / A ye Q s c / A ye Qu i V O / A w Poe / A ye t l ud g . p / A Q i r e ng g , C . : C . : s m . J Q LO M s m C E :A CA . C ( :A / A 97
  98. Copyright 2019 Red Hat K.K. 2 3 13 2 3

    13 2 3 13 2 3 13 2 3 13 3.2 .10         2 3 13 . 0 3 98
  99. Copyright 2019 Red Hat K.K. Automated Dependency Resolution My Operator

    v1.1.2 require s requires Jaeger Operator jaeger.jaegertracing.io /v1 CockroachDB Operator cockroachdb.charts.helm.k8s.io/v1alpha 1 resolves to resolves to Operator Framework  installed by installed by         99
  100. Copyright 2019 Red Hat K.K.  100

  101. Copyright 2019 Red Hat K.K. 8 K 8= C +

    ) + (+ +  /    101
  102. Copyright 2019 Red Hat K.K. ) ( ) ) )

    ). 102
  103. Copyright 2019 Red Hat K.K. 103

  104. Copyright 2019 Red Hat K.K.  104

  105.      105

  106.  106