Library to help you interact with Docker or Kubernetes cluster in Node-based environments.
Install with npm
npm install @theinternetfolks/kubernetes
Install with yarn
yarn add @theinternetfolks/kubernetes
You initialize Kubernetes with your configuration, and then you can use any resources available.
import { Kubernetes } from "@theinternetfolks/kubernetes";
const perform = async () => {
const k8s = new Kubernetes(); // will load from default
return k8s.Ingress.getAll();
};
import { Kubernetes } from "@theinternetfolks/kubernetes";
const perform = async () => {
const k8s = new Kubernetes("config", "file"); // will load from a `config` file
return k8s.Ingress.getAll();
};
import { Kubernetes } from "@theinternetfolks/kubernetes";
const perform = async () => {
const config = await fs.readFile("config", "utf-8");
const k8s = new Kubernetes(config, "string"); // will load from a `config` string
return k8s.Ingress.getAll();
};
Kubernetes / Client
constructor(config: any, method: KubernetesBootstrapMethod)
public kc: k8s.KubeConfig
disconnect(): void
Kubernetes / Pod
async getAll(namespace: string = "default"): Promise<V1PodList>
async get(name: string, namespace: string = "default"): Promise<V1Pod>
async remove(name: string, namespace: string = "default", gracePeriodSeconds: number = 0): Promise<V1Pod>
Kubernetes / Deployment
async getAll(namespace: string = "default"): Promise<V1DeploymentList>
async get(name: string, namespace: string = "default"): Promise<V1Deployment>
async remove(name: string, namespace: string = "default"): Promise<V1Status>
async apply(specString: string): Promise<k8s.KubernetesObject[]>
Kubernetes / Ingress
async getAll(namespace: string = "default"): Promise<V1IngressList>
async get(name: string, namespace: string = "default"): Promise<V1Ingress>
async remove(name: string, namespace: string = "default"): Promise<V1Status>
async apply(specString: string | V1Ingress, namespace: string = "default"): Promise<V1Ingress>
Kubernetes / StatefulSet
async getAll(namespace: string = "default"): Promise<V1StatefulSetList>
async get(name: string, namespace: string = "default"): Promise<V1StatefulSet>
async remove(name: string, namespace: string = "default"): Promise<V1Status>
static async build(tag: string, options: BuildOptions = {})
returns Promise<{ status: boolean; message: string; }>
static async pull(tag: string, options: PullOptions = {})
returns Promise<{ status: boolean; message: string; }>
static async push(tag: string, options: Dockerode.ImagePushOptions = {})
returns Promise<{ status: boolean; message: string; }>
To run tests, run the following command
yarn test
- Used Mocha with Chai as Unit Tests
- Private Repo and Tokens were used to carry out some pull and push tests in Docker