• Crossplane-云基础架构管理平台


    背景

    Crossplane(跨平面,意思是可以跨越多个 公有云平台) 是一个开源的 Kubernetes 插件,它允许平台团队组装来自多个供应商的基础设施,并向应用程序团队公开更高级别的自助服务 api,而不需要编写任何代码。

    Crossplane 扩展您的 Kubernetes 集群,为您提供任何基础设施或托管服务的 crd。将这些细粒度资源组合成更高级别的抽象,这些抽象可以使用您喜欢的工具,也可以和已经集成到集群中的现有流程进行版本管理、管理、部署和使用。

    同类产品:Terraform

    Composition

    一个composition组织一个或多个自定义资源,以响应由 ApplicationDefinition 或 InfrastructureDefinition 定义的自定义资源的创建或修改:

    • 可以定义怎样组合应用和基础设施

    • 可以定义多个资源,包括组合资源

    • 可以定义应用资源间的依赖关系

    1. apiVersion: apiextensions.crossplane.io/v1alpha1
    2. kind: Composition
    3. metadata:
    4.   name: private-mysql-server
    5.   labels:
    6.     connectivity: private
    7. spec:
    8.   # This composition declares that its input values will be read 'from' a
    9.   # resource of the specified kind, which must be defined by an
    10.   # InfrastructureDefinition. The field name denotes the relationship with the
    11.   # 'fromFieldPath' notation below.
    12.   from:
    13.     apiVersion: database.example.org/v1alpha1
    14.     kind: MySQLInstance
    15.   # This composition declares that its input values will be written 'to' the
    16.   # below resources. The field name denotes the relationship with the
    17.   # 'toFieldPath' notation below.
    18.   to:
    19.   - base:
    20.       apiVersion: azure.crossplane.io/v1alpha3
    21.       kind: ResourceGroup
    22.       spec:
    23.         location: West US
    24.         providerConfigRef:
    25.           name: example
    26.         reclaimPolicy: Delete
    27.     patches:
    28.     - fromFieldPath: "spec.region"
    29.       toFieldPath: "spec.forProvider.location"
    30.       transforms:
    31.       - type: map
    32.         map:
    33.           us-west: "West US"
    34.           us-east: "East US"
    35.   - base:
    36.       apiVersion: database.azure.crossplane.io/v1beta1
    37.       kind: MySQLServer
    38.       spec:
    39.         forProvider:
    40.           administratorLogin: myadmin
    41.           resourceGroupNameSelector:
    42.             matchComposite: true
    43.           location: West US
    44.           sslEnforcement: Disabled
    45.           version: "5.6"
    46.           sku:
    47.             tier: Basic
    48.             capacity: 1
    49.             family: Gen5
    50.           storageProfile:
    51.             storageMB: 20480
    52.         writeConnectionSecretToRef:
    53.           namespace: crossplane-system
    54.         providerConfigRef:
    55.           name: example
    56.         reclaimPolicy: Delete
    57.     patches:
    58.     - fromFieldPath: "metadata.uid"
    59.       toFieldPath: "spec.writeConnectionSecretToRef.name"
    60.     - fromFieldPath: "spec.engineVersion"
    61.       toFieldPath: "spec.forProvider.version"
    62.     - fromFieldPath: "spec.storageGB"
    63.       toFieldPath: "spec.forProvider.storageMB"
    64.       transforms:
    65.       - type: math
    66.         math:
    67.           multiply: 1024
    68.     - fromFieldPath: "spec.region"
    69.       toFieldPath: "spec.forProvider.location"
    70.       transforms:
    71.       - type: map
    72.         map:
    73.           us-west: "West US"
    74.           us-east: "East US"
    75.     # Specifies the (potentially sensitive) connection details that this 'to'
    76.     # resource should expose to the 'from' resource. Names are unique across all
    77.     # 'to' resources within this composition. Ignored by application resources.
    78.     connectionDetails:
    79.     - name: username
    80.       fromConnectionSecretKey: username
    81.     - name: password
    82.       fromConnectionSecretKey: password
    83.     - name: endpoint
    84.       fromConnectionSecretKey: endpoint
    85.   - base:
    86.       apiVersion: database.azure.crossplane.io/v1alpha3
    87.       kind: MySQLServerVirtualNetworkRule
    88.       spec:
    89.         serverNameSelector:
    90.           matchComposite: true
    91.         resourceGroupNameSelector:
    92.           matchComposite: true
    93.         properties:
    94.           virtualNetworkSubnetIdRef:
    95.             name: sample-subnet
    96.         reclaimPolicy: Delete
    97.         providerConfigRef:
    98.           name: azure-provider

    InfrastructureDefinition

    一个表示基础设施的自定义CRD资源,由基础设施提供商实现。基础设施资源是集群范围的,并且只能组成其他集群范围的基础设施资源。基础设施资源包括由基础设施提供商实施的“原始”基础设施资源以及其他组合基础设施资源。

    1. apiVersion: apiextensions.crossplane.io/v1alpha1
    2. kind: InfrastructureDefinition
    3. metadata:
    4.   # InfrastructureDefinition names are subject to the constraints of Kubernetes
    5.   # CustomResourceDefinition names. They must be of the form ..
    6.   name: mysqlinstances.database.example.org
    7. spec:
    8.   # Any composition that intends to satisfy an infrastructure resource must
    9.   # expose each of the named connection details exactly once in any of its
    10.   # connectionDetails objects. The connection secret published by the defined
    11.   # infrastructure resource will include only these connection details.
    12.   connectionDetails:
    13.   - username
    14.   - password
    15.   - endpoint
    16.   # Defines the structural schema and GroupVersionKind of this infrastructure.
    17.   # Only a single API version of the application may exist. Additional fields
    18.   # will be injected to support composition machinery.
    19.   crdSpecTemplate:
    20.     group: database.example.org
    21.     version: v1alpha1
    22.     names:
    23.       kind: MySQLInstance
    24.       listKind: MySQLInstanceList
    25.       plural: mysqlinstances
    26.       singular: mysqlinstance
    27.     validation:
    28.       openAPIV3Schema:
    29.         properties:
    30.           engineVersion:
    31.             type: string
    32.           region:
    33.             type: string
    34.           storageGB:
    35.             type: int
    36.         type: object
    37.   # An optional service account that will be used to reconcile MySQLInstance
    38.   # resources. This allows the use of RBAC to restrict which resources a
    39.   # MySQLInstance may be composed of. The specified service account must have
    40.   # full access to MySQLInstance resources, and 'get' access to Component
    41.   # resources.
    42.   #
    43.   # If the service account is omitted Crossplane will use its pod service
    44.   # account to manage MySQLInstance resources. This implies that anyone with
    45.   # sufficient RBAC permissions to create a Composition and to create a
    46.   # MySQLInstance will be able to compose their MySQLInstance of any
    47.   # infrastructure resource that Crossplane is able to create.
    48.   serviceAccountRef:
    49.     namespace: crossplane-system
    50.     name: mysqlinstances.database.example.org
    51.   # An optional default composition that will be set automatically for any
    52.   # MySQLInstance custom resources that omit both their compositeSelector and
    53.   # their compositeRef.
    54.   defaultCompositionRef:
    55.     name: cheap-rds
    56.   # An optional forced composition that will be set automatically for any
    57.   # MySQLInstance custom resource, overriding their compositeSelector and their
    58.   # compositeRef. If defaultComposition and forceComposition are both set, the
    59.   # forced composition wins.
    60.   enforcedCompositionRef:
    61.     name: mysqlinstances.database.example.org

    ApplicationDefinition

    ApplicationDefinition 定义了一种代表应用程序的新型自定义资源

    1. apiVersion: apiextensions.crossplane.io/v1alpha1
    2. kind: ApplicationDefinition
    3. metadata:
    4.   # ApplicationDefinition names are subject to the constraints of Kubernetes
    5.   # CustomResourceDefinition names. They must be of the form ..
    6.   name: wordpresses.apps.example.org
    7. spec:
    8.   # Defines the structural schema and GroupVersionKind of this application. Only
    9.   # a single API version of the application may exist. Additional fields will be
    10.   # injected to support composition machinery.
    11.   crdSpecTemplate:
    12.     group: apps.example.org
    13.     version: v1alpha1
    14.     names:
    15.       kind: Wordpress
    16.       listKind: WordpressList
    17.       plural: wordpresses
    18.       singular: wordpress
    19.     validation:
    20.       openAPIV3Schema:
    21.         properties:
    22.           administratorLogin:
    23.             type: string
    24.           storageSize:
    25.             type: int
    26.           storageType:
    27.             type: string
    28.         type: object
    29.   # An optional service account that will be used to reconcile Wordpress
    30.   # resources. This allows the use of RBAC to restrict which resources a
    31.   # Wordpress application may be composed of. The specified service account must
    32.   # have full access to Wordpress resources, and 'get' access to Component
    33.   # resources.
    34.   #
    35.   # If the service account is omitted Crossplane will use its pod service
    36.   # account to manage Wordpress resources. This implies that anyone with
    37.   # sufficient RBAC permissions to create a Composition and to create a
    38.   # Wordpress resource in a particular namespace will be able to compose their
    39.   # Wordpress of any resource Crossplane is able to create. Crossplane will
    40.   # refuse to create resources at the cluster scope or outside of the namespace
    41.   # in which the Wordpress was created.
    42.   serviceAccountRef:
    43.     namespace: crossplane-system
    44.     name: wordpresses.apps.example.org
    45.   # An optional default composition that will be set automatically for any
    46.   # Wordpress custom resources that omit both their compositeSelector and their
    47.   # compositeRef.
    48.   defaultCompositionRef:
    49.     name: local-wordpress
    50.   # An optional forced composition that will be set automatically for any
    51.   # Wordpress custom resource, overriding their compositeSelector and their
    52.   # compositeRef. If defaultComposition and forceComposition are both set, the
    53.   # forced composition wins.
    54.   enforcedCompositionRef:
    55.     name: wordpresses.apps.example.org

    通过执行A上面的pplicationdefinition,crossplane将自动创建一个CRD,这将允许用户使用上面自定义的应用资源:Wordpress

    1. apiVersion: example.org/v1alpha1
    2. kind: Wordpress
    3. metadata:
    4.   namespace: default
    5.   name: coolblog
    6. spec:
    7.   # The schema for the following three fields is defined by the above
    8.   # ApplicationDefinition.
    9.   administratorLogin: admin
    10.   storageSize: 2
    11.   storageType: SSD
    12.   # The below schema is automatically injected into the CustomResourceDefinition
    13.   # that is created by the ApplicationDefinition that defines the Wordpress
    14.   # resource.
    15.   # Multiple compositions may potentially satisfy a particular kind of
    16.   # application. Each application instance may influence which composition is
    17.   # used via label selectors. This could be used, for example, to determine
    18.   # whether a Wordpress application renders to a KubernetesApplication or to a
    19.   # plain old Kubernetes Deployment.
    20.   compositionSelector:
    21.     matchLabels:
    22.       compute: kubernetes
    23.       database: mysql
    24.   # The Wordpress author may explicitly select which composition should be used
    25.   # by setting the compositionRef. In the majority of cases the author will
    26.   # ignore this field and it will be set by a controller, similar to the
    27.   # contemporary classRef field.
    28.   compositionRef:
    29.   - name: wordpress-kubernetes-mysql
    30.   # Each application maintains an array of the resources they compose.
    31.   # Composed resources are always in the same namespace as the application
    32.   # resource. Any namespaced resource may be composed; composed resources
    33.   # model their relationship with the application resource via their
    34.   # controller reference. The application must maintain this array because
    35.   # there is currently no user friendly, performant way to discover which
    36.   # resources (of arbitrary kinds) are controlled by a particular resource per
    37.   # https://github.com/kubernetes/kubernetes/issues/54498
    38.   resourceRefs:
    39.   - apiVersion: database.example.org/v1alpha1
    40.     kind: MySQLInstanceRequirement
    41.     name: coolblog-3jmdf
    42.   - apiVersion: workload.crossplane.io/v1alpha1
    43.     kind: KubernetesApplication
    44.     name: coolblog-3mdm2

    Provider

    基础设施资源提供者,它是一组k8s 的CRD和controllers的组合,用于一对一的定义各个provider 提供的资源。官方提供的provider 有:

    • AWS provider

    • GCP provider

    • Azure

    • Alibaba

    • ......
      provider 主要有两种资源组成,Provider 和 ProviderConfig

    与Terraform集成

    因为crossplane想做平台,如果所有的底层设施provider全部由自己来实现,那比较耗时。但是第三方基础设施肯定也不想给crossplane做嫁衣,因此现在crossplane面临的窘境就是provider太少了。

    基于此,推出了Terrajet 的项目,该项目将让提供商开发人员生成 CRD 并使用封装 Terraform CLI 操作的通用运行时。这样我们就可以在几分钟内添加对资源的支持。

  • 相关阅读:
    c# xml 参数读取读取的简单使用
    Ajax系列之文件上传进度展示
    liunx配置ssh免密登录
    (8个方法)解决windows11/10/8/7卡在准备就绪一直转圈
    盘点一个pandas.merge的问题
    零基础Linux_16(基础IO_文件)笔试选择题:文件描述符+ionde和动静态库
    learning项目总结
    Assimp库模型导入结构
    又火了!GitHub标星百万的并发编程手册(彩图版)竟是从阿里流出
    声明式 GUI 工具包:响应式、跨平台、多语言 | 开源日报 No.230
  • 原文地址:https://blog.csdn.net/m0_47495420/article/details/133004021