Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
In which folder of NextJS project should i place the code to access k8s server api

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!