Warning: call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /home/kalofero/public_html/blog/wp-includes/class-wp-hook.php on line 286
ABX Action to Deploy Kubernetes YAML Document via Cloud Template in Cloud Assembly | Spas Kaloferov's Blog

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.

  1. #--------------------------------------------------------#
  2. #                     Spas Kaloferov                     #
  3. #                   www.kaloferov.com                    #
  4. # bit.ly/The-Twitter      Social     bit.ly/The-LinkedIn #
  5. # bit.ly/The-Gitlab        Git         bit.ly/The-Github #
  6. # bit.ly/The-BSD         License          bit.ly/The-GNU #
  7. #--------------------------------------------------------#
  8. info: |-
  9.   #
  10.   #     VMware Cloud Assembly Blueprint Code Sample    
  11.   #
  12.   # - Creates a K8s Namespace.
  13.   # - Optionally also creates a deployment based on Yaml file.
  14.   # - Do not change or rename any of the inputs.
  15.   #
  16. name: K8S - Create From YAML
  17. version: 1
  18. #-------------------------INPUTS-------------------------#
  19. inputs:
  20.   actionOptionKubeconfig:
  21.     comment: |
  22.      This overrides the actionOptionKubeconfigIn action input
  23.       configured in the ABX action. If you want to use the context
  24.       configured in the action select abs as input.
  25.     type: string
  26.     title: Exec Context
  27.     #format: hidden
  28.     description: |
  29.      Select KubeConfig to use for the run context. You can
  30.       choose between the kubeconfig limited to the namespace
  31.       being created or use an admin kubeconfig. Selecting 'abx'
  32.       will use the context configured in the abx action
  33.     default: namespace
  34.     enum:
  35.      - namespace
  36.       - admin
  37.       - abx
  38.   yaml:
  39.     comment: |
  40.      This overrides the actionOptionKubeconfigIn actin input
  41.       configured in the ABX action. <br>
  42.       NOTE: use ABX-Parameter-K8sNamespace anywhere in the yaml
  43.       where you want to use the name of the namespace which is
  44.       provided by the inputs at request time.
  45.     title: Yaml
  46.     type: string
  47.     format: hidden
  48.     description: |
  49.      Select KubeConfig to use for the run context. You can
  50.       choose between the kubeconfig limited to the namespace
  51.       being created or use an admin kubeconfig.
  52.     default: |
  53.     YAML Document 1
  54.       ---
  55.      YAML Document 2
  56.       ---
  57.      YAML Document 3

 

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.

DISCLAIMER; This is a personal blog. Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated. Any views or opinions are not intended to malign any religion, ethnic group, club, organization, company, or individual.
All content provided on this blog is for informational purposes only. The owner of this blog makes no representations as to the accuracy or completeness of any information on this site or found by following any link on this site. The owner will not be liable for any errors or omissions in this information nor for the availability of this information. The owner will not be liable for any losses, injuries, or damages from the display or use of this information.
Photos
Unless stated, all photos are the work of the blog owner and are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. If used with watermark, no need to credit to the blog owner. For any edit to photos, including cropping, please contact me first.
Recipes
Unless stated, all recipes are the work of the blog owner and are licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License. Please credit all recipes to the blog owner and link back to the original blog post.
Downloadable Files
Any downloadable file, including but not limited to pdfs, docs, jpegs, pngs, is provided at the user’s own risk. The owner will not be liable for any losses, injuries, or damages resulting from a corrupted or damaged file.
Comments
Comments are welcome. However, the blog owner reserves the right to edit or delete any comments submitted to this blog without notice due to
– Comments deemed to be spam or questionable spam
– Comments including profanity
– Comments containing language or concepts that could be deemed offensive
– Comments containing hate speech, credible threats, or direct attacks on an individual or group
The blog owner is not responsible for the content in comments.
This policy is subject to change at anytime.

Leave a Reply

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