Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda