DEV Community

Cover image for Create Custom Templates in Monokle
Hitesh Kowdiki
Hitesh Kowdiki

Posted on

Create Custom Templates in Monokle

What is Kubernetes? ☸

πŸ‘‰πŸ» Kubernetes, often abbreviated as K8s, is a popular open-source tool for modern infrastructure automation. It is used to deploy, scale, and manage containerized applications in an distributed system.

For More info: https://kubernetes.io/docs/home/

What is Monokle? πŸ’¬

πŸ‘‰πŸ» Monokle helps you to:

  • Quickly get a high-level view of your manifests, their contained resources and relationships.
  • Easily edit resources without having to learn or look up yaml syntax.
  • Refactor resources with maintained integrity of names and references.
  • Preview and debug resources generated with Kustomize or Helm.
  • Diff resources against your cluster and apply changes immediately.
  • Visualize and navigate resources in your clusters.

For More Info: https://kubeshop.github.io/monokle/

πŸŒ€ Let's explore how we can use Monokle for writing templates for a Kubernetes Service

What are Monokle Templates? πŸ’¬

πŸ‘‰πŸ» A Monokle Template is a mechanism for creating visual forms and interpolating the data from those forms into one or multiple manifests.

For each form, we must define the JSON schema of the data to use as an input and a UI-schema for customizing the visuals of the forms (for example, specifying which widgets should be used).

For More info: https://kubeshop.github.io/monokle/templates/

Prerequisites:

  • Any Code Editor (I am using VSCode)
  • Monokle : Download

πŸŒ€ Let's Start

πŸ‘‰πŸ» Step 1: Create a package.json file

{
    "name": "Templates plugin",
    "description": "Custom templates plugin",
    "version": "1.0.0",
    "author": "Hitesh Kowdiki",
    "repository": "https://github.com/kkhitesh/monokle-templates-plugin",
    "monoklePlugin": {
        "id": "com.github.kkhitesh.plugin.templates",
        "helpUrl": "https://github.com/kkhitesh/monokle-templates-plugin",
        "modules": [{
            "type": "template",
            "path": "basic-pod-template"
        }]
    }
}
Enter fullscreen mode Exit fullscreen mode

πŸŒ€ In this path specifies where we have the template, basic-pod-template

πŸ‘‰πŸ» *Step 2: * Create a folder name basic-pod-template and add following content:

1. Create monokle-template.json and add the following:

{
  "name": "Basic Kubernetes Pod",
  "id": "com.github.kkhitesh.plugin.templates.basic-pod-template",
  "author": "Hitesh Kowdiki",
  "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/kkhitesh/monokle-templates-plugin"
}
Enter fullscreen mode Exit fullscreen mode

2. Create form-schema.json and add the following:

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

3. Create form-ui-schema.json and add the following:

{
  "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"
  }
}
Enter fullscreen mode Exit fullscreen mode

4. Create template.yaml and add the following:

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: {}
Enter fullscreen mode Exit fullscreen mode

πŸŒ€ Push the code to GitHub: https://github.com/kkhitesh/monokle-templates-plugin

Time to use our custom-template

πŸ‘‰πŸ» Step 1: Run Monokle
Image description

πŸ‘‰πŸ» Step 2: Install Plugin
There is a plugin button at top right corner
Image description
Image description

πŸŒ€ Click Install a Plugin and add GitHub URL

Image description

πŸ‘‰πŸ» Step 3: From Dashboard Create a Project

Image description

πŸŒ€ Select a Template

Image description

πŸŒ€ Create Project

Image description

Image description

Image description

Image description

We have Successfully created our Custom Template πŸ₯³πŸ₯³

Thanks For Reading πŸ™ŒπŸ»πŸ™ŒπŸ»

πŸš€ Connect With Me:

Top comments (0)