ClusterAPI v1alpha1 → v1alpha2 / k8s_meetup_23

C84357a21083c81c5ccd5550422abc8d?s=47 Ryo Takaishi
September 27, 2019

ClusterAPI v1alpha1 → v1alpha2 / k8s_meetup_23

C84357a21083c81c5ccd5550422abc8d?s=128

Ryo Takaishi

September 27, 2019
Tweet

Transcript

  1. ∁ੴྒ(.01FQBCP *OD ,VCFSOFUFT.FFUVQ5PLZP খωλ΋͋ΔΑ $MVTUFS"1*WBMQIB ˠWBMQIB

  2. ∁ੴྒ!S@UBLBJTIJ  (.0ϖύϘגࣜձٕࣾज़ج൫νʔϜ  (P ,VCFSOFUFT  $MPVE/BUJWF.FFUVQ5PLZPPSHBOJ[FS  ࠷ۙͷझຯ͸ͷࣸਅͱಈըΛࡱΔ͜ͱ

  3. ˙ LTΫϥελʔΛߏங͢ΔͨΊͷએݴత"1*Λ࡞ΔϓϩδΣΫτ ˙ $3%ɺ$POUSPMMFSɺ$-*πʔϧͳͲͰߏ੒͞ΕΔ ˙ ࠓ೔͸WBMQIBɺWBMQIBʹ͍ͭͯͱখωλΛ঺հ !3 $MVTUFS"1*

  4. ClusterAPI v1alpha1

  5. ˙ DMVTUFSBQJͱDMVTUFSBQJQSPWJEFSͰߏ੒͞ΕΔ ˙ QSPWJEFS͸֤छΫϥ΢υ΍ϕΞϝλϧɺ%PDLFSͳͲʹରԠ ˙ ֤1SPWJEFSͰ͸ઐ༻ͷΞΫνϡΤʔλʔΛ$MVTUFS"1*$POUSPMMFSʹొ࿥͠ɺ୯Ұ ͷϚωʔδϟʔͰΫϥελʔ؅ཧΛߦ͏ !5 $MVTUFS"1*WBMQIB

  6. !6 ઃఆʹैͬͯ5BSHFU$MVTUFSΛ࡞੒ DMVTUFSDUM #PPUTUSBQ$MVTUFS 5BSHFU$MVTUFS DMVTUFSBQJNBOBHFS ֤छ$POpH.BQ w ֤छϦιʔεΛ࡞੒ w

    $POUSPM1MBOF༻ͷΠϯελϯε w 4FDVSJUZ(SPVQ w ωοτϫʔΫͳͲ w LVCFBENͰΫϥελʔߏங w طଘΫϥελʔΛར༻ w LVCFBEN WJSUVBMCPYͰखݩʹߏங
  7. !7 Ϛωʔδϟʔͱ$POpH.BQΛҠಈ DMVTUFSDUM #PPUTUSBQ$MVTUFS 5BSHFU$MVTUFS DMVTUFSBQJNBOBHFS NBOBHFSɺ$POpH.BQΛϐϘοτ DMVTUFSBQJNBOBHFS ֤छ$POpH.BQ

  8. ClusterAPI v1alpha2

  9. ˙ W͔Β"1*͕WBMQIBʹมߋ ˙ ΞʔΩςΫνϟ͕͔ͳΓมΘͬͨ ˙ ͭͷϚωʔδϟʔʢίϯτϩʔϥʔʣͰߏ੒͞ΕΔ w $PSF $MVTUFS"1* 

    w #PPUTUSBQ LVCFBEN  w *OGSBTUSVDUVSF BXT PQFOTUBDL EPDLFS FUDʜ !9 $MVTUFS"1*WBMQIB WBMQIBͰ͸ϓϩόΠμʔຖʹϚωʔδϟ͕ ͭ͋ΔͷΈͩͬͨ
  10. ˙ $MVTUFS w ίΞ෦෼ ˙ #PPUTUSBQ w LVCFBENΛ࢖͏ίʔυΛݮΒ͢͜ͱ͕໨త w WBMQIBͰ͸શϓϩόΠμʔ͕࣮૷

    w $MPVE*OJUͷσʔλੜ੒ͳͲΛߦ͏ ˙ *OGSBTUSVDUVSF w WBMQIBͰ͍͏ϓϩόΠμʔɻ w Ϋϥ΢υͳͲΠϯϑϥݸผͷϩδοΫΛड͚࣋ͭ !10 ෼ׂͷૂ͍ IUUQTDMVTUFSBQJTJHTLTJPQSPWJEFSTWBMQIBUPWBMQIBIUNM
  11. ˙ DMVTUFSBQJ w $MVTUFS3FDPODJMFS w .BDIJOF3FDPODJMFS w .BDIJOF4FU3FDPODJMFS w .BDIJOF%FQMPZNFOU3FDPODJMFS

    ˙ DMVTUFSBQJCPPUTUSBQQSPWJEFSLVCFBEN w ,VCFBEN$POpH3FDPODJMFS ˙ DMVTUFSBQJQSPWJEFSBXT w "84$MVTUFS3FDPODJMFS w "84.BDIJOF3FDPODJMFS !11 ͦΕͧΕ͕࣋ͭ3FDPODJMFS
  12. !12 ֤ϓϩόΠμʔͷରԠঢ়گ "84 WҎ߱ͰରԠ "[VSF 7YҎ߱ͰରԠ ($1 NBTUFSΛݟΔͱWBMQIBʹରԠ͍ͯͨ͠ 0QFO4UBDL ݱࡏରԠதͬΆ͍

  13. ˙ ϖύϘͷLTΤϯδϯͰ͋Δ/,&ʹ͓͍ͯɺϊʔυͷ؅ཧʹ$MVTUFS"1*Λར༻ ˙ OLFOPEFDPOUSPMMFS w .BDIJOF$POUSPMMFS.BDIJOF4FU$POUSPMMFS.BDIJOF%FQMPZFNOU$POUSPMMFS͸DMVTUFSBQJͷ΋ͷΛར༻ w 0QFO4UBDLʹରԠ͢ΔͨΊͷ3FDPODJMFSΛ࣮૷ʢ/ZBI.BDIJOF3FDPODJMFSʣ !13 ར༻ࣄྫ

  14. !14 --- apiVersion: cluster.x-k8s.io/v1alpha2 kind: Cluster metadata: name: ${CLUSTER_NAME} spec:

    clusterNetwork: pods: cidrBlocks: ["192.168.0.0/16"] infrastructureRef: apiVersion: infrastructure.cluster.x-k8s.io/ v1alpha2 kind: AWSCluster name: ${CLUSTER_NAME} Cluster / AWSClusterΛݟͯΈΔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJQSPWJEFSBXTCMPCWFYBNQMFTDMVTUFSDMVTUFSZBNM --- apiVersion: infrastructure.cluster.x- k8s.io/v1alpha2 kind: AWSCluster metadata: name: ${CLUSTER_NAME} spec: region: ${AWS_REGION} sshKeyName: ${SSH_KEY_NAME} LJOE$MVTUFS LJOE"84$MVTUFS ࡞੒͢ΔΫϥελͷ *OGSBTUSVDUVSF৘ใΛࢀর
  15. !15 // ClusterSpec defines the desired state of Cluster type

    ClusterSpec struct { // Cluster network configuration // +optional ClusterNetwork *ClusterNetwork `json:"clusterNetwork,omitempty"` // InfrastructureRef is a reference to a provider-specific resource that holds the details // for provisioning infrastructure for a cluster in said provider. // +optional InfrastructureRef *corev1.ObjectReference `json:"infrastructureRef,omitempty"` InfrastructureRefͱ͸Կͳͷ͔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWBQJWBMQIBDMVTUFS@UZQFTHP
  16. !16 type ObjectReference struct { Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"` Namespace

    string `json:"namespace,omitempty" protobuf:"bytes,2,opt,name=namespace"` Name string `json:"name,omitempty" protobuf:"bytes,3,opt,name=name"` UID types.UID `json:"uid,omitempty" protobuf:"bytes,4,opt,name=uid,casttype=k8s.io/ apimachinery/pkg/types.UID"` APIVersion string `json:"apiVersion,omitempty" protobuf:"bytes,5,opt,name=apiVersion"` ResourceVersion string `json:"resourceVersion,omitempty" protobuf:"bytes, 6,opt,name=resourceVersion"` FieldPath string `json:"fieldPath,omitempty" protobuf:”bytes,7,opt,name=fieldPath"` } corev1.ObjectReference IUUQTHJUIVCDPNLVCFSOFUFTBQJCMPCLVCFSOFUFTDPSFWUZQFTHP
  17. !17 // reconcileInfrastructure reconciles the Spec.InfrastructureRef object on a Cluster.

    func (r *ClusterReconciler) reconcileInfrastructure(ctx context.Context, cluster *v1alpha2.Cluster) error { if cluster.Spec.InfrastructureRef == nil { return nil } // Call generic external reconciler. infraConfig, err := r.reconcileExternal(ctx, cluster, cluster.Spec.InfrastructureRef) Ͳ͏࢖ΘΕ͍ͯΔͷ͔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWDPOUSPMMFSTDMVTUFS@DPOUSPMMFS@QIBTFTHP // reconcileExternal handles generic unstructured objects referenced by a Cluster. func (r *ClusterReconciler) reconcileExternal(ctx context.Context, cluster *v1alpha2.Cluster, ref *corev1.ObjectReference) (*unstructured.Unstructured, error) { obj, err := external.Get(r.Client, ref, cluster.Namespace) if err != nil { if apierrors.IsNotFound(err) { return nil, errors.Wrapf(&capierrors.RequeueAfterError{RequeueAfter: 30 * time.Second}, "could not find %v %q for Cluster %q in namespace %q, requeuing",
  18. !18 // Get uses the client and reference to get

    an external, unstructured object. func Get(c client.Client, ref *corev1.ObjectReference, namespace string) (*unstructured.Unstructured, error) { obj := new(unstructured.Unstructured) obj.SetAPIVersion(ref.APIVersion) obj.SetKind(ref.Kind) obj.SetName(ref.Name) key := client.ObjectKey{Name: obj.GetName(), Namespace: namespace} if err := c.Get(context.Background(), key, obj); err != nil { return nil, err } return obj, nil } corev1.ObjectReference IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWDPOUSPMMFSTFYUFSOBMVUJMHP
  19. !19 // Event is a report of an event somewhere

    in the cluster. type Event struct { metav1.TypeMeta `json:",inline"` // Standard object's metadata. // More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata metav1.ObjectMeta `json:"metadata" protobuf:"bytes,1,opt,name=metadata"` // The object that this event is about. InvolvedObject ObjectReference `json:"involvedObject" protobuf:"bytes,2,opt,name=involvedObject"` ࢀߟɿObjectReference͸EventϦιʔεͰ΋࢖ΘΕ͍ͯΔ IUUQTHJUIVCDPNLVCFSOFUFTTJHTDMVTUFSBQJCMPCWDPOUSPMMFSTFYUFSOBMVUJMHP
  20. ศརʂ

  21. ˙ $MVTUFS"1*WBMQIB͔ΒWBMQIBͰେ͖͘มΘͬͨ w ίϯτϩʔϥʢϚωʔδϟʣ͕෼ׂ͞Εͨ w ϓϩόΠμʔʹΑͬͯରԠঢ়گ͸͕ࠩ͋Δ ˙ ผͷϦιʔε΁ͷࢀর͸DPSFW0CKFDU3FGFSFODFΛ࢖͓͏ !21 ·ͱΊ