10.3. 使用 Red Hat Developer Hub 中的 Kubernetes 自定义操作创建模板


流程

  • 要创建模板,请将 Template 对象定义为 YAML 文件。

    Template 对象描述了模板及其元数据。它还包含所需的输入变量,以及构建服务所执行的操作列表。

    apiVersion: scaffolder.backstage.io/v1beta3
    kind: Template
    metadata:
      name: create-kubernetes-namespace
      title: Create a kubernetes namespace
      description: Create a kubernetes namespace
    spec:
      type: service
      parameters:
        - title: Information
          required: [namespace, token]
          properties:
            namespace:
              title: Namespace name
              type: string
              description: Name of the namespace to be created
            clusterRef:
              title: Cluster reference
              type: string
              description: Cluster resource entity reference from the catalog
              ui:field: EntityPicker
              ui:options:
                catalogFilter:
                  kind: Resource
            url:
              title: Url
              type: string
              description: Url of the kubernetes API, will be used if clusterRef is not provided
            token:
              title: Token
              type: string
              ui:field: Secret
              description: Bearer token to authenticate with
            skipTLSVerify:
              title: Skip TLS verification
              type: boolean
              description: Skip TLS certificate verification, not recommended to use in production environment, default to false
            caData:
              title: CA data
              type: string
              ui:field: Secret
              description: Certificate Authority base64 encoded certificate
            labels:
              title: Labels
              type: string
              description: Labels to be applied to the namespace
              ui:widget: textarea
              ui:options:
                rows: 3
              ui:help: 'Hint: Separate multiple labels with a semicolon!'
              ui:placeholder: 'kubernetes.io/type=namespace; app.io/managed-by=org'
      steps:
        - id: create-kubernetes-namespace
          name: Create kubernetes namespace
          action: kubernetes:create-namespace
          input:
            namespace: ${{ parameters.namespace }}
            clusterRef: ${{ parameters.clusterRef }}
            url: ${{ parameters.url }}
            token: ${{ secrets.token }}
            skipTLSVerify: ${{ parameters.skipTLSVerify }}
            caData: ${{ secrets.caData }}
            labels: ${{ parameters.labels }}
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat