Skip to content

Collection of scaffolder actions for interacting with Kubernetes on Backstage, including apply and delete.

License

Notifications You must be signed in to change notification settings

kirederik/backstage-k8s-scaffolder-actions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Backstage Scaffolder Actions for Kubernetes

This is a Kubernetes actions plugin for the scaffolder-backend in Backstage.

It contains a set of actions to create and manage Kubernetes resources.

Getting Started

In the root directory of your Backstage project:

yarn add @devangelista/backstage-scaffolder-kubernetes

Make sure to add a Kubernetes section to your app-config.yaml (check the Backstage docs)

On your package/backend/src/index.ts file, add the following:

backend.add(import("@devangelista/backstage-scaffolder-kubernetes"));

The scaffolder kube actions should now be available to use on your templates. Check the /create/actions endpoint for documentation.

Kubernetes Configuration

This plugin now integrates with Backstage's Kubernetes integration features, allowing you to:

  1. Use multiple Kubernetes clusters configured in your Backstage app-config.yaml
  2. Support various authentication methods (ServiceAccount, Google Cloud, AWS, Azure)
  3. Specify which cluster to use for each action

Configuration Example

Here's an example Kubernetes configuration in app-config.yaml:

kubernetes:
  clusterLocatorMethods:
    - type: config
      clusters:
        - name: development
          url: https://my-dev-cluster.example.com
          authProvider: serviceAccount
          serviceAccountToken: ${K8S_DEV_SA_TOKEN}
          skipTLSVerify: true
        - name: production
          url: https://my-prod-cluster.example.com
          authProvider: serviceAccount
          serviceAccountToken: ${K8S_PROD_SA_TOKEN}
          skipTLSVerify: false
          caData: ${K8S_PROD_CA_DATA}

Usage

You can now use the actions in your templates:

apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  description: Create a Namespace in Kubernetes
  name: create-namespace
  title: Create a Namespace
spec:
  lifecycle: experimental
  owner: user
  type: example
  parameters:
    - properties:
        name:
          description: The namespace name
          title: Name
          type: string
          ui:autofocus: true
      required:
        - name
      title: Namespace Name
    - title: Cluster Name
      properties:
        cluster:
          type: string
          enum:
            - development
            - production
          ui:autocomplete:
            options:
              - development
              - production
  steps:
    - action: kube:apply
      id: k-apply
      name: Create a Resouce
      input:
        namespaced: false
        clusterName: ${{ parameters.cluster }}
        manifest: |
          apiVersion: v1
          kind: Namespace
          metadata:
            name: ${{ parameters.name }}
---
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
  name: delete-namespace
  description: Delete a Namespace in Kubernetes
  title: Delete a Namespace
spec:
  lifecycle: experimental
  owner: user
  type: example
  parameters:
    - properties:
        name:
          title: Name
          description: The name of the namespace to delete
          type: string
          ui:autofocus: true
      title: Namespace Name
      required:
        - name
    - title: Cluster Name
      properties:
        cluster:
          type: string
          enum:
            - development
            - production
          ui:autocomplete:
            options:
              - development
              - production
  steps:
    - action: kube:delete
      id: k-delete
      name: Delete
      input:
        apiVersion: v1
        kind: Namespace
        clusterName: ${{ parameters.cluster }}
        name: ${{ parameters.name }}

Authentication Methods

The plugin currently supports the following authentication methods:

  1. Service Account: Uses a service account token

More methods coming soon!

If no specific cluster is specified, the plugin will use the first cluster defined in the configuration, or fall back to using local kubeconfig.

About

Collection of scaffolder actions for interacting with Kubernetes on Backstage, including apply and delete.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published