Create a YAML Manifest Template in Monokle.

A walkthrough to create Custom Templates.

What is a Manifest file?

A manifest file - also known as manifest.yml - defines the configuration of your application’s components.📁 It allows you to completely customise the composition of your application and control settings.

eg: A manifest specifies the desired state of an object that Kubernetes will maintain when you apply the manifest.

Manifest files are YAML formatted.

Why Monokle ?

Monokle is an Open Source desktop tool to help you with things related to Kubernetes Manifests. It makes it easy to manage and debug your manifests - before you deploy them to your cluster! Monokle allows you to create manifests both from scratch and from templates. We will be using the default template and also making our own Custom template for a Basic Kubernetes Pod(pod: smallest scheduling unit in K8)

Let's get started ⚡

Prerequisites:

  1. Install Monokle's latest version depending on your OS- For Windows download the latest .exe file, .dmg for macOS and .appImage/.deb for Linux here. After successful installation, this is what you'll see. welcome.png In Windows. to use Monokle do "run away"

  2. A text editor, my personal preference is VS Code. Install the necessary extensions of YAML and JSON if you haven't already.

🚀🚀 Great! Now you're all set to move further.

Creating a manifest file using the default template

  • Click on Start a template> Provide the suitable Project name and the path > Next: Select a template as shown below, choose the Basic pod template to follow along with this article and then click Create Project. template.PNG
  • Provide the required information like Pod name, Image type (here: Nginx)

  • You'll finally see your Result as a manifest file for a basic pod configuration ready to use. Note: The default name is my-pod.

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
spec:
  containers:
    - image: nginx
      name: my-pod
      resources: {}

Creating our Custom Templates

A Monokle Template is a mechanism for creating visual forms and interpolating the data from those forms into one or multiple manifests. Any folder that contains a monokle-template.json file can be a template. Templates can be installed via Plugins and used in Monokle.

What is a Plugin?🔌

Simply, any GitHub repository that contains a package.json file (the plugin entry file) can be installed as a plugin if the entry file follows the structure of a Monokle plugin.

Here’s an example of a package.json for a Monokle plugin:

{
    "name": "monokle-templates-plugin",
    "description": "Custom templates plugin",
    "version": "1.0.0",
    "author": "Ruhika",
    "repository": "https://github.com/Ruhika1417/monokle-templates-plugin",
    "monoklePlugin": {
        "id": "com.github.Ruhika1417.plugin.templates",
        "helpUrl": "https://github.com/Ruhika1417/monokle-templates-plugin",

        "modules": [
            {
            "type": "template",
            "path": "basic-pod-template"
        }
       ]
    }
}

We'll create our template in 3 different parts, each part having separate files.

  • A Monokle template configuration

  • A Form configuration

  • A Kubernetes YAML manifest with placeholders

Part 1 ⚡

Monkle-template.json

Create a new template directory as mkdir monokle-templates-plugin and cd monokle-templates-plugin. Create a new file monokle-template.json. This file should have the following content as shown below.

The name, id, author, version, description, type and forms properties are required. All types of templates have these properties.

Monokle 1.5.0 introduced vanilla templates and referenced Helm Chart templates. Here, we're using the "vanilla" type. In vanilla templates, we provide the manifests that will be generated as an output

❗❗ Don't forget to replace author and helpUrl properties with your own.

{
    "name": "Basic Kubernetes Pod",
    "id": "com.Ruhika1417.plugin.templates.basic-pod-template",
    "author": "Ruhika",
    "version": "1.0.0",
    "description": "Creates a Pod for a specified Image",
    "repository": "",
    "type": "vanilla",
    "forms": [
      {
        "name": "Pod Settings",
        "description": "Specify the settings for your Pod",
        "schema": "form-schema.json",
        "uiSchema": "form-ui-schema.json"
      }
    ],
    "manifests": [
      {
        "filePath": "template.yaml"
      }
    ],
    "resultMessage": "Pod resource created successfully!",
    "helpUrl": "https://github.com/Ruhika1417/monokle-templates-plugin"
  }

Part 2 ⚡

What does a form schema look like?

The format of form schemas is JSON schema. This defines which data that will be sent to the template manifests.

{
    "type": "object",
    "required": [
      "name",
      "image"
    ],
    "properties": {
      "name": {
        "type": "string",
        "default": "my-pod"
      },
      "namespace": {
        "type": "string"
      },
      "image": {
        "type": "string"
      }
    }
  }

What does a UI form schema look like ?

Create a file named form-ui-schema.json. This file should have the contents as shown below. This will basically describe how the form is going to appear.

You may also check out different Custom Form Widgets here

{
    "name": {
      "ui:title": "Name",
      "ui:help": "The name of the Pod"
    },
    "namespace": {
      "ui:title": "Namespace",
      "ui:help": "The target namespace for the Pod",
      "ui:widget": "namespaceSelection"
    },
    "image": {
      "ui:title": "Image",
      "ui:help": "The image name to use for the Pod, for example nginx-ingress:latest"
    }
  }

Part 3 ⚡

Template. yaml: This is going to the pod template. Whatever a user inputs for the properties, while using the custom templates, the values of that would be replaced in the actual Manifest file. eg: name.

apiVersion: v1
kind: Pod
metadata:
  name: [[ forms[0].name ]] 
[[ forms[0].namespace ?  " namespace: " + forms[0].namespace + "\n" : ""]]
spec:
  containers:
    - image: [[forms[0].image]]
      name: [[forms[0].name]]
      resources: {}

Uploading your Project to Github 📁

After completing the creation of necessary files upload the package.json file and template folder to Github.

eg: github.com/Ruhika1417/monokle-templates-plu..

Importing the template in Monokle ⭐

Step 1: Open Monokle, At the rightmost top corner, next to notifications there is a Plugin icon. Click on that.

plugins.PNG

Step 2: Click on the "Install" option then enter the Valid Github URL of the repository used and press " Download and Install Plugin". plugin_installation.PNG 👏 Kudos. You have successfully installed the plugin if you're able to see it in "Plugins Manager"!

Step 3: To use your Custom Template check the left- lowermost " Templates" icons. The template name with the Author that you provided would appear. Click on Use template. Start> Enter the required fields and Hurrah!!! You made it through.

basic_k8 podsPNG.PNG


If you liked the blog don't forget to like, share and Follow.

Also, feel free to connect with me on Twitter

Thank you for your patient reading <3

Did you find this article valuable?

Support RuhikaBulani by becoming a sponsor. Any amount is appreciated!