ABX Action to Deploy Kubernetes YAML Document via Cloud Template in Cloud Assembly (SKKB1058)

In this blog post we are going to look at an ABX action that allows us deploy a Kubernetes YAML document, or multiple thereof , from a Cloud Template (previously known as Blueprint) in VMware Cloud Assembly.

 

Update Log:

Introduction

Cloud Assembly has native integration with Kubernetes and allows us to create Kubernetes Clusters , namespaces and Supervisor Namespaces. These all are available to be consumed as resources objects in the Cloud Template Editor.

Cloud Assembly does not offer us through a way to run a Kubernetes YAML documents , or multiple thereof , from a Cloud Template. We can do this from Code Stream Cloud , which has Kubernetes integration as well and offers a Kubernetes task that can run yaml document(s). Code Stream does not give us LiveCycle management on the deployment through.

To fill in the gab I’ve created a ABX action that will utilize the Namespace creation from Cloud Assembly , and therefore the LiveCycle of the deployment, it will allow us to run a Kubernetes yaml in that namespace to create a deployment.

Thinks of the ABX action as the equivalent of a kubectl create -f FILENAME command .

The action can be found on the following Gitlab Repo bit.ly/The-Gitlab.  Action name is k8sCreateFromYaml

Special Thanks to Lazarin Lazarov and Teodor Raykov (https://www.linkedin.com/in/tedraykov/) for their work in the product and for providing me the skeleton and idea for this action

Let’s dig in into the action to see what it does.

 

Using the ABX Inputs

Let’s examine the ABX Action inputs and what they do:

  • cspRefreshTokenIn (String): VMware Cloud Service Portal (CSP) Token
  • actionOptionKubeconfigIn: (String): Select the kubeconfig to be used for the action
    • admin: This uses an admin kubeconfig to authenticate to the Kubernetes cluster and run the YAML document.
    • namespace: This uses an namespace kubeconfig to authenticate to the Kubernetes cluster and run the YAML document. This kubeconfig is limited to the scope of the namespace that was created as part of the blueprint deployment.

The ABX action need to be subscribed to the Kubernetes namespace post provision (kubernetes.namespace.provision.post ) Event Topic.

Among the self-explaining inputs the Cloud Template that we are going to use also has the following important inputs :

  • yaml (String): This provides the yaml document , or documents to be run by the ABX Action. The Cloud Template also creates a namespace. If we want that namespace to be used in the yaml we need to place ABX-Parameter-K8sNamespace anywhere in the yaml documents where we want to reference the namespace name. The ABX action will substitute this with the appropriate namespace name.
  • – actionOptionKubeconfig: (String): Select the kubeconfig to be used for the action.
    • admin: This uses an admin kubeconfig to authenticate to the Kubernetes cluster and run the YAML document.
    • namespace: This uses an namespace kubeconfig to authenticate to the Kubernetes cluster and run the YAML document. This kubeconfig is limited to the scope of the namespace that was created as part of the blueprint deployment.
    • abx: This uses the kubeconfig specified in the actionOptionKubeconfigIn input property in the ABX Action. This allows the Cloud Template Editor to let the ABX Extensibility Editor to choose the kubeconfig file.

[sourcecode language=”yaml”]

#——————————————————–#
# Spas Kaloferov #
# www.kaloferov.com #
# bit.ly/The-Twitter Social bit.ly/The-LinkedIn #
# bit.ly/The-Gitlab Git bit.ly/The-Github #
# bit.ly/The-BSD License bit.ly/The-GNU #
#——————————————————–#
info: |-
#
# VMware Cloud Assembly Blueprint Code Sample
#
# – Creates a K8s Namespace.
# – Optionally also creates a deployment based on Yaml file.
# – Do not change or rename any of the inputs.
#
name: K8S – Create From YAML
version: 1
#————————-INPUTS————————-#
inputs:

actionOptionKubeconfig:
comment: |
This overrides the actionOptionKubeconfigIn action input
configured in the ABX action. If you want to use the context
configured in the action select abs as input.
type: string
title: Exec Context
#format: hidden
description: |
Select KubeConfig to use for the run context. You can
choose between the kubeconfig limited to the namespace
being created or use an admin kubeconfig. Selecting ‘abx’
will use the context configured in the abx action
default: namespace
enum:
– namespace
– admin
– abx
yaml:
comment: |
This overrides the actionOptionKubeconfigIn actin input
configured in the ABX action.
NOTE: use ABX-Parameter-K8sNamespace anywhere in the yaml
where you want to use the name of the namespace which is
provided by the inputs at request time.
title: Yaml
type: string
format: hidden
description: |
Select KubeConfig to use for the run context. You can
choose between the kubeconfig limited to the namespace
being created or use an admin kubeconfig.
default: |
YAML Document 1

YAML Document 2

YAML Document 3

[/sourcecode]

 

Now in this example the yaml is hardcoded in the blueprint. But we can remove the format: hidden property, and by thus exposing it as user input. We can then build a custom form to frontend it so that the user can supply the yaml document at request time. Custom form is also included with the action.

 

Exploring the Cloud Template Deployment

One the Cloud Template has been provisioned and the ABX Action has completed. The deployment Name and Description will be auto-updates with a status of all the deployment pods and a link to the deployment load balancer , if such is deployed.

 

Final Step

If all went well, go grab a beer.

Leave a Reply

Your email address will not be published. Required fields are marked *