Socket
Book a DemoInstallSign in
Socket

@otwld/nestjs-kubernetes

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@otwld/nestjs-kubernetes

![otwld_nestjs_kubernetes_banner](./banner.png)

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
0
Created
Source

NestJS Kubernetes

otwld_nestjs_kubernetes_banner

GitHub License Build Status Discord NPM Downloads

Installation

yarn add @otwld/nestjs-kubernetes @kubernetes/client-node
npm install @otwld/nestjs-kubernetes @kubernetes/client-node

Usage

Register from KubeConfig file

import { Module } from '@nestjs/common';
import { KubernetesModule, LoadFrom } from '@otwld/nestjs-kubernetes';

@Module({
  imports: [KubernetesModule.register({
    servers: [
      {
        name: 'KUBE_CLUSTER',
        loadFrom: LoadFrom.FILE,
        opts: {
          file: '/path/to/kubeconfig',
          context: 'cluster-1'
        }
      }
    ],
    isGlobal: true
  })]
})
export class AppModule {
}

Register in cluster

import { Module } from '@nestjs/common';
import { KubernetesModule, LoadFrom } from '@otwld/nestjs-kubernetes';

@Module({
  imports: [KubernetesModule.register({
    servers: [
      {
        name: 'KUBE_CLUSTER',
        loadFrom: LoadFrom.CLUSTER
      }
    ], 
    isGlobal: true
  })]
})
export class AppModule {
}

Register multi cluster

import { Module } from '@nestjs/common';
import { KubernetesModule, LoadFrom } from '@otwld/nestjs-kubernetes';

@Module({
  imports: [KubernetesModule.register({
    servers: [
      {
        name: 'KUBE_CLUSTER_1',
        loadFrom: LoadFrom.FILE,
        opts: {
          file: '/path/to/kubeconfig',
          context: 'cluster-1'
        }
      },
      {
        name: 'KUBE_CLUSTER_2',
        loadFrom: LoadFrom.FILE,
        opts: {
          file: '/path/to/kubeconfig',
          context: 'cluster-2'
        }
      }
    ], 
    isGlobal: true
  })]
})
export class AppModule {
}

Injecting KubeConfig in scoped providers

// module.ts
import { Module } from "@nestjs/common";
import { KubernetesModule, LoadFrom } from '@otwld/nestjs-kubernetes';
import { Service } from "./service";

@Module({
  imports: [KubernetesModule.register([
    {
      name: 'KUBE_CLUSTER',
      loadFrom: LoadFrom.CLUSTER,
    }
  ])],
  providers: [
    Service,
  ],
})
export class AppModule {}
// service.ts
import { Inject, Injectable } from "@nestjs/common";
import { KubeConfig, CoreV1Api } from "@kubernetes/client-node";

@Injectable()
export class Service {
  private coreV1Api: CoreV1Api;
  
  constructor(@Inject("KUBE_CLUSTER") public kubeConfig: KubeConfig) {
    this.coreV1Api = this.kubeConfig.makeApiClient(CoreV1Api);
  }
}

Support

Keywords

nestjs

FAQs

Package last updated on 10 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts