Chapter 9. Kubernetes custom actions in Red Hat Developer Hub
You can create and manage Kubernetes resources by using custom scaffolder actions in Red Hat Developer Hub templates. The Kubernetes custom actions plugin is preinstalled in a disabled state.
9.1. Enable Kubernetes custom actions plugin in Red Hat Developer Hub Copy linkLink copied to clipboard!
Enable the preinstalled Kubernetes custom actions plugin by updating the dynamic plugins configuration.
In Red Hat Developer Hub, the Kubernetes custom actions are provided as a preinstalled plugin, which is disabled by default. You can enable the Kubernetes custom actions plugin by updating the disabled key value in your dynamic-plugins.yaml file.
Procedure
Add a
packagewith the Kubernetes custom action plugin name and update thedisabledfield in yourdynamic-plugins.yamlfile to enable the plugin. For example:plugins: - package: oci://ghcr.io/redhat-developer/rhdh-plugin-export-overlays/backstage-community-plugin-scaffolder-backend-module-kubernetes:<tag> disabled: falsewhere:
<tag>Enter your RHDH version of Backstage and the plugin version, in the format
bs_<backstage-version>__<plugin-version>(note the double underscore delimiter). To find these versions, complete the following steps:- Find your Backstage version in the RHDH release notes preface.
Locate the plugin version in the Dynamic Plugins Reference guide. For example, for RHDH 1.10 based on Backstage 1.49.4, use the format
bs_1.49.4__<plugin-version>.TipTo ensure environment stability, use a SHA256 digest instead of a version tag. See Determining SHA256 Digests.
NoteThe default configuration for a plugin is extracted from the
dynamic-plugins.default.yamlfile, however, you can use apluginConfigentry to override the default configuration.
9.2. Use Kubernetes custom actions plugin in Red Hat Developer Hub Copy linkLink copied to clipboard!
Add Kubernetes actions to your custom templates to create namespaces and manage cluster resources.
In Red Hat Developer Hub, the Kubernetes custom actions enable you to run template actions for Kubernetes.
Procedure
To use a Kubernetes custom action in your custom template, add the following Kubernetes actions to your template:
action: kubernetes:create-namespace id: create-kubernetes-namespace name: Create kubernetes namespace input: namespace: my-rhdh-project clusterRef: bar token: TOKEN skipTLSVerify: false caData: Zm9v labels: app.io/type=ns; app.io/managed-by=org;
9.3. Create a template using Kubernetes custom actions in Red Hat Developer Hub Copy linkLink copied to clipboard!
Define a Template object with Kubernetes actions to automate namespace creation and resource management.
Procedure
To create a template, define a
Templateobject as a YAML file.The
Templateobject describes the template and its metadata. It also contains required input variables and a list of actions that are executed by the scaffolding service.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 }
9.4. Supported Kubernetes custom actions in Red Hat Developer Hub Copy linkLink copied to clipboard!
Access parameter specifications and requirements for the kubernetes:create-namespace scaffolder action.
In Red Hat Developer Hub, you can use custom Kubernetes actions in Scaffolder templates.
- Action:
kubernetes:create-namespace - Creates a namespace for the Kubernetes cluster in the Developer Hub.
| Parameter name | Type | Requirement | Description | Example |
|---|---|---|---|---|
|
|
| Required | Name of the Kubernetes namespace |
|
|
|
|
Required only if | Cluster resource entity reference from the catalog |
|
|
|
|
Required only if | API url of the Kubernetes cluster |
|
|
|
| Required | Kubernetes API bearer token used for authentication | |
|
|
| Optional | If true, certificate verification is skipped | false |
|
|
| Optional | Base64 encoded certificate data | |
|
|
| Optional | Labels applied to the namespace | app.io/type=ns; app.io/managed-by=org; |