How to Build Your First Plugin
Building plugins for k3ai is very simple. This guide will walk you through the steps required to build a plugin and contribute to the project.
The first step is to learn the structure of the plugins repository: https://github.com/kf5i/k3ai-plugins****
The repo is structured in a very simple way.
    core
      groups
      plugins
    common
    community
Coreis the root folder it includes plugins and groups
Plugins are the actual application to be deployed, for each plugin folder there is a plugin.yaml file.
Groups are a combination of various plugins to be installed altogether
Under common you'll find all the manifests or files needed by more than one plugin. Those are sort of reusable components (i.e.: treafik ingress definitions for plugins).
k3ai supports custom repositories for plugins and groups so this means you may have your own instead of using our public ones.
Let's create a local repo and deploy a "hello-world" plugin.
First, we have to create the basic structure. So let's create anywhere on your laptop a structure like this:
    demo
      core
        groups
        plugins
          demo-plugin
            plugin.yaml
      common
        demo-plugin
          deployment.yaml
Now let's open the plugin.yaml file and copy the below content in it.
1
plugin-name: demo-plugin
2
plugin-description: Demo of a custom local plugin
3
namespace: "default"
4
yaml:
5
- url: "./commons/demo-plugin/deployment.yaml"
6
type: "file"
Copied!
Save the file and open the deployment.yaml. Copy&Paste the following content.
1
apiVersion: v1
2
kind: Pod
3
metadata:
4
name: shell-demo
5
spec:
6
volumes:
7
- name: shared-data
8
emptyDir: {}
9
containers:
10
- name: nginx
11
image: nginx
12
volumeMounts:
13
- name: shared-data
14
mountPath: /usr/share/nginx/html
15
hostNetwork: true
16
dnsPolicy: Default
Copied!
We are ready let's check the plugin list with
1
k3ai list --repo "<absolute path to root folder>/"
2
3
#k3ai list --repo "home/user/core/"
Copied!
You should get something like this
1
k3ai list --repo "<absolute path to root folder>/"
2
3
Name Description
4
demo-plugin A simple demo of a local plugin
Copied!
Great! Now let's apply the plugin to our environment
1
k3ai apply --repo "<absolute path to root folder>/"
Copied!
Now let's check if the pod is running with
1
kubectl get pod shell-demo
2
3
#Output
4
NAME READY STATUS RESTARTS AGE
5
shell-demo 1/1 Running 0 3m9s
Copied!
We are ready so let's execute a command inside our plugin. Copy and Paste the below command into your terminal.
1
kubectl exec --stdin --tty shell-demo -- /bin/bash -c "apt-get update > /dev/null && apt-get -y install boxes > /dev/null && echo 'Hey, this is K3ai! Thanks for use this.' | boxes -d peek"
Copied!
If everything goes right you should see something like this
1
/* _\|/_
2
(o o)
3
+----oOO-{_}-OOo------------------------+
4
|Hey, this is K3ai! Thanks for use this.|
5
+--------------------------------------*/
Copied!
Congratulation you created your first plugin. Now to delete it simply execute
1
k3ai delete --repo "<absolute path to root folder>/"
Copied!
Last modified 10mo ago
Export as PDF
Copy link