Getting started with Kubernetes Manifests with Monokle

Getting started with Kubernetes Manifests with Monokle

A well-written guide to creating pods with the Monokle template system

ยท

5 min read

Note: The motivation behind writing this blog post is Kunal. He simplifies the concepts of DSA and DevOps via his youtube channel. This blog is written in order to participate in the ongoing giveaway.

Dear Reader, You can too participate in his giveaway. Watch the below video for more information: KCNA Course Giveaway Worth $299 ๐ŸŽ‰ YAML Manifest Templates in Monokle

Getting started with Monokle:

What is Monokle?

I know that this question arises in your mind.

Well, Monokle is a GUI (Graphical User Interface) Tool to create and visualize manifest files in Kubernetes. So, you can manage and debug manifest files easily using Monokle.

There are two ways to work with Monokle. You can create a pod using a pre-defined template in Monokle or you can create your own template plugin and you can use that inside Monokle to create a pod.

Before starting with the installation of Monokle, you should install Helm.

What is Helm?

Helm is a package manager for Kubernetes. You can compare this with npm for Node.js

You can install Helm from their GitHub repo: Install Helm

Alright, let's start with the installation of Monokle.

You can install Monokle from their GitHub repo: Install Monokle

Awesome! First, we take look that how to create a pod using the pre-defined template in Monokle.

Creating a pod with a pre-defined Template:

Follow the steps given below,

  1. Open Monokle
  2. Click on Start from a template
  3. Soon, it prompts you to enter the project name and location of the project.
  4. After finishing up the necessary fields, click on Next: Select a template
  5. Select Basic Pod as the template for your project. Click on Use Template
  6. Now, click on start
  7. Fill fields for the pod settings (Name, Namespace, Image)
  8. For Image you can type any image you want. For eg. ubuntu, nginx, etc.
  9. Perfect, You successfully created your first pod
  10. The next step is to deploy the pod to the cluster. That is Minikube.
  11. Click on Deploy. You are prompted to select the namespace.
  12. Select use existing namespace and leave namespace as default and click on Ok.

That's it. Your pod is deployed on the cluster.

Now, it's time to create our own pod by writing our own plugin without using any pre-defined template from Monokle.

Writing your own Template plugin:

So, a vanilla template consists of,

  1. Monokle template config,
  2. Form config and
  3. YAML config

These are Monokle specific. You can learn more about Monokle templates here:

Monokle is a GUI tool. It needs some information to render the form inputs and get data from the user. So, we need to set up these fields in our plugin.

Our GitHub repo will act as a plugin in this case. So, create a repo in your Github account and clone that repo in your local machine

So, It's time to follow the steps given below.

  • As said above, clone the created GitHub repo by using the terminal
  • Open VS Code. Head towards your project folder.
  • Create a package.json file and paste the below code
{
  "name": "templates-plugin",
  "description": "Custom templates plugin",
  "version": "1.0.0",
  "author": "Roopesh Saravanan",
  "repository": "https://github.com/roopeshsn/monokle-templates-plugin",
  "monoklePlugin": {
    "id": "com.github.roopeshsn.plugin.templates",
    "helpUrl": "https://github.com/roopeshsn/monokle-templates-plugin",
    "modules": [
      {
        "type": "template",
        "path": "basic-pod-template"
      }
    ]
  }
}

Edit the GitHub links and you're good to go.

  • Create a folder "basic-pod-template". This should be the same as the path in the package.json file
  • Create a file named "monokle-template.json" and paste the below code there,
{
  "name": "Basic Kubernetes Pod",
  "id": "com.github.roopeshsn.plugin.templates.basic-pod-template",
  "author": "Roopesh Saravanan",
  "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/roopeshsn/monokle-templates-plugin"
}

Edit the GitHub links and username

  • Create a file named "form-schema.json" and paste the below code there,
{
  "type": "object",
  "required": ["name", "image"],
  "properties": {
    "name": {
      "type": "string",
      "default": "my-pod"
    },
    "namespace": {
      "type": "string"
    },
    "image": {
      "type": "string"
    }
  }
}
  • Create a file named "form-ui.json" and paste the below code there,
{
  "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"
  }
}
  • Now it's time to create the YAML file. Create a file named "template.yaml" and paste the below code there,
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: {}

An important point to note here. The data collected from the user from the form should be filled up in the YAML file. That's why the name and image property of the YAML file is an array. It is defined with the form data of index 0. Because we rendered only one form.

  • Hooray! You've successfully written the template yourself. It's time to push the code to Github.

How to use this custom-written template inside Monokle?

Just follow the steps below,

  1. Open Monokle and click on Open plugins manager and select Install
  2. It prompts for the plugin URL. Copy your repo URL and paste it into the input.
  3. Click on Download and Install a plugin
  4. Now your plugin will be installed. You can view the template by clicking on View Templates
  5. Select your custom-written template by clicking on use Template. Click on start
  6. Fill fields for the pod settings (Name, Namespace, Image)
  7. For Image you can type any image you want. For eg. ubuntu, nginx, etc.
  8. Perfect, You successfully created your pod using your custom-written template.
  9. The next step is to deploy the pod to the cluster. That is Minikube.
  10. Click on Deploy. You are prompted to select the namespace.
  11. Select use existing namespace and leave namespace as default and click on Ok.

Here is my custom-written template: My GitHub repo link

Conclusion:

In my opinion, Monokle's way of creating pods from a template is super useful. What are you waiting for? Go ahead and create your own pod.

Thanks for reading! Have a great day :)

Did you find this article valuable?

Support Roopesh Saravanan by becoming a sponsor. Any amount is appreciated!

ย