I have created a nodejs backend API to access Kubernetes server API using the library @kubernetes/client-node. Basically i have two files in first i am calling the k8s config file to access the API and it looks like:
import k8s from '@kubernetes/client-node';
let kubeAPI = null;
const createKubeAPI = async () => {
const kc = new k8s.KubeConfig();
// kc.loadFromDefault();
const path = './config/k8sConfig.yaml';
console.log(path);
kc.loadFromFile(path);
const k8sApi = kc.makeApiClient(k8s.BatchV1Api);
return k8sApi;
};
export const get = () => kubeAPI;
export const create = async () => {
kubeAPI = await createKubeAPI();
};
and in the second file i have defined the body of the job(its just an example that i found on Google) and it looks like:
import { get } from '../kubeClient.js';
const kubeRoute = async (ctx) => {
const newJob = {
metadata: {
name: 'countdown',
},
spec: {
template: {
metadata: {
name: 'countdown',
},
spec: {
containers: [{
name: 'counter',
image: 'centos:7',
command: ['/bin/bash', '-c', 'for i in 9 8 7 6 5 4 3 2 1 ; do echo $i ; done'],
}],
restartPolicy: 'Never',
},
},
},
};
const kubeClient = get();
kubeClient.createNamespacedJob('default', newJob);
};
export default kubeRoute;
It is working fine but now i need to implement the backend inside of NextJS project so that i dont need to start the backend API on a specific host. Inside the NextJS project, do i need to create a new folder at root and place these code files there or inside the pages/api/ folder? Can someone help me in this?