Ssoon

오퍼레이터 & MySQL 오퍼레이터 (4) - CR & CRD 실습 본문

Database Operator In Kubernetes study

오퍼레이터 & MySQL 오퍼레이터 (4) - CR & CRD 실습

구구달스 2022. 6. 2. 12:32
CloudNet@ 팀의 가시다님이 진행하는 Database Operator In Kubernetes study 스터디 중 CR & CRD 실습 내용에 대해 정리하였습니다.
  • Custom Resource Definition를 사용하면 Kubernetes의 네이티브 컴포넌트처럼 자신의 오브젝트와 애플리케이션을 연결할 수 있습니다.Kubernetes를 기반으로 하는 툴과 서비스를 만드는 데 매우 강력합니다.
  • Kubernetes RBAC를 사용하여 애플리케이션에 보안 및 인증을 제공할 수 있을 뿐만 아니라 애플리케이션용 Custom Resource 를 구축할 수 있습니다.이러한 Custom Resource 는 레플리케이션과 적절한 라이프 사이클 관리를 통해 통합 etcd 저장소에 저장됩니다.또한 Kubernetes와 함께 제공되는 모든 내장 클러스터 관리 기능을 활용합니다.

 

 

  • Custom Resource Definition 생성합니다.
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: crontabs.stable.example.com
spec:
  group: stable.example.com
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                cronSpec:
                  type: string
                image:
                  type: string
                replicas:
                  type: integer
  scope: Namespaced
  names:
    plural: crontabs
    singular: crontab
    kind: CronTab
    shortNames:
    - ct
  • Custom Resource Definition 생성 확인합니다.

  • Custom Resource 생성합니다.
apiVersion: "stable.example.com/v1"
kind: CronTab
metadata:
  name: my-new-cron-object
spec:
  cronSpec: "* * * * */5"
  image: my-awesome-cron-image

 

  • Custom Resource 확인합니다.

  • 현재는 리소스만 생성한 상태 이며, 실제 동작을 위해서는 Custom Controller 가 필요합니다.
  • Operator 패턴? 
    • Custom Resource 와 Custom Controller 로 특정 애플리케이션 or Service 의 생성, 삭제, 관리합니다.
    • Kubernetes 코어 API 에 포함되지 않은 애플리케이션을 마치 Kubernetes Native 리소스처럼 동작합니다.

  • Custom Resource Definition 삭제 후 리소스 정보 조회시 에러가 발생합니다.

 

  • 아래 calico 관련 Custom Resource Definition 중 하나를 조회 한 결과입니다.
    • 위에서 작성한 것과 기본 포맷이 유사한 것 과 BGP 설정에 관한 CRD 인것을 알수 있습니다.
(🍎 |DOIK-Lab:default) root@k8s-m:~/DOIK# kubectl describe crd bgpconfigurations.crd.projectcalico.org
Name:         bgpconfigurations.crd.projectcalico.org
Namespace:    
Labels:       <none>
Annotations:  <none>
API Version:  apiextensions.k8s.io/v1
Kind:         CustomResourceDefinition
Metadata:
  Creation Timestamp:  2022-05-24T05:39:13Z
  Generation:          1
  Managed Fields:
    API Version:  apiextensions.k8s.io/v1
    Fields Type:  FieldsV1
    fieldsV1:
      f:status:
        f:acceptedNames:
          f:kind:
          f:listKind:
          f:plural:
          f:singular:
        f:conditions:
          k:{"type":"Established"}:
            .:
            f:lastTransitionTime:
            f:message:
            f:reason:
            f:status:
            f:type:
          k:{"type":"NamesAccepted"}:
            .:
            f:lastTransitionTime:
            f:message:
            f:reason:
            f:status:
            f:type:
    Manager:      kube-apiserver
    Operation:    Update
    Subresource:  status
    Time:         2022-05-24T05:39:13Z
    API Version:  apiextensions.k8s.io/v1
    Fields Type:  FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .:
          f:kubectl.kubernetes.io/last-applied-configuration:
      f:spec:
        f:conversion:
          .:
          f:strategy:
        f:group:
        f:names:
          f:kind:
          f:listKind:
          f:plural:
          f:singular:
        f:scope:
        f:versions:
    Manager:         kubectl-client-side-apply
    Operation:       Update
    Time:            2022-05-24T05:39:13Z
  Resource Version:  1413
  UID:               c53c7f13-ea88-4b7e-83ab-044467151b9e
Spec:
  Conversion:
    Strategy:  None
  Group:       crd.projectcalico.org
  Names:
    Kind:       BGPConfiguration
    List Kind:  BGPConfigurationList
    Plural:     bgpconfigurations
    Singular:   bgpconfiguration
  Scope:        Cluster
  Versions:
    Name:  v1
    Schema:
      openAPIV3Schema:
        Description:  BGPConfiguration contains the configuration for any BGP routing.
        Properties:
          API Version:
            Description:  APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
            Type:         string
          Kind:
            Description:  Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
            Type:         string
          Metadata:
            Type:  object
          Spec:
            Description:  BGPConfigurationSpec contains the values of the BGP configuration.
            Properties:
              As Number:
                Description:  ASNumber is the default AS number used by a node. [Default: 64512]
                Format:       int32
                Type:         integer
              Communities:
                Description:  Communities is a list of BGP community values and their arbitrary names for tagging routes.
                Items:
                  Description:  Community contains standard or large community value and its name.
                  Properties:
                    Name:
                      Description:  Name given to community value.
                      Type:         string
                    Value:
                      Description:  Value must be of format `aa:nn` or `aa:nn:mm`. For standard community use `aa:nn` format, where `aa` and `nn` are 16 bit number. For large community use `aa:nn:mm` format, where `aa`, `nn` and `mm` are 32 bit number. Where, `aa` is an AS Number, `nn` and `mm` are per-AS identifier.
                      Pattern:      ^(\d+):(\d+)$|^(\d+):(\d+):(\d+)$
                      Type:         string
                  Type:             object
                Type:               array
              Listen Port:
                Description:  ListenPort is the port where BGP protocol should listen. Defaults to 179
                Maximum:      65535
                Minimum:      1
                Type:         integer
              Log Severity Screen:
                Description:  LogSeverityScreen is the log severity above which logs are sent to the stdout. [Default: INFO]
                Type:         string
              Node To Node Mesh Enabled:
                Description:  NodeToNodeMeshEnabled sets whether full node to node BGP mesh is enabled. [Default: true]
                Type:         boolean
              Prefix Advertisements:
                Description:  PrefixAdvertisements contains per-prefix advertisement configuration.
                Items:
                  Description:  PrefixAdvertisement configures advertisement properties for the specified CIDR.
                  Properties:
                    Cidr:
                      Description:  CIDR for which properties should be advertised.
                      Type:         string
                    Communities:
                      Description:  Communities can be list of either community names already defined in `Specs.Communities` or community value of format `aa:nn` or `aa:nn:mm`. For standard community use `aa:nn` format, where `aa` and `nn` are 16 bit number. For large community use `aa:nn:mm` format, where `aa`, `nn` and `mm` are 32 bit number. Where,`aa` is an AS Number, `nn` and `mm` are per-AS identifier.
                      Items:
                        Type:  string
                      Type:    array
                  Type:        object
                Type:          array
              Service Cluster I Ps:
                Description:  ServiceClusterIPs are the CIDR blocks from which service cluster IPs are allocated. If specified, Calico will advertise these blocks, as well as any cluster IPs within them.
                Items:
                  Description:  ServiceClusterIPBlock represents a single allowed ClusterIP CIDR block.
                  Properties:
                    Cidr:
                      Type:  string
                  Type:      object
                Type:        array
              Service External I Ps:
                Description:  ServiceExternalIPs are the CIDR blocks for Kubernetes Service External IPs. Kubernetes Service ExternalIPs will only be advertised if they are within one of these blocks.
                Items:
                  Description:  ServiceExternalIPBlock represents a single allowed External IP CIDR block.
                  Properties:
                    Cidr:
                      Type:  string
                  Type:      object
                Type:        array
              Service Load Balancer I Ps:
                Description:  ServiceLoadBalancerIPs are the CIDR blocks for Kubernetes Service LoadBalancer IPs. Kubernetes Service status.LoadBalancer.Ingress IPs will only be advertised if they are within one of these blocks.
                Items:
                  Description:  ServiceLoadBalancerIPBlock represents a single allowed LoadBalancer IP CIDR block.
                  Properties:
                    Cidr:
                      Type:  string
                  Type:      object
                Type:        array
            Type:            object
        Type:                object
    Served:                  true
    Storage:                 true
Status:
  Accepted Names:
    Kind:       BGPConfiguration
    List Kind:  BGPConfigurationList
    Plural:     bgpconfigurations
    Singular:   bgpconfiguration
  Conditions:
    Last Transition Time:  2022-05-24T05:39:13Z
    Message:               no conflicts found
    Reason:                NoConflicts
    Status:                True
    Type:                  NamesAccepted
    Last Transition Time:  2022-05-24T05:39:13Z
    Message:               the initial names have been accepted
    Reason:                InitialNamesAccepted
    Status:                True
    Type:                  Established
  Stored Versions:
    v1
Events:  <none>

 

 
Comments