How to use the @kubernetes/client-node.CoreV1Api function in @kubernetes/client-node

To help you get started, we’ve selected a few @kubernetes/client-node examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kubernetes-client / javascript / examples / namespace.js View on Github external
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

var namespace = {
  metadata: {
    name: 'test'
  }
};

k8sApi.createNamespace(namespace).then(
  (response) => {
    console.log('Created namespace');
    console.log(response);
    k8sApi.readNamespace(namespace.metadata.name).then(
      (response) => {
        console.log(response);
	k8sApi.deleteNamespace(
          namespace.metadata.name, {} /* delete options */);
github replicatedhq / kots / kotsadm / api / src / kurl / resolvers / kurl_queries.ts View on Github external
async kurl(root: any, args: any, context: Context): Promise {
      context.requireSingleTenantSession();

      // this isn't stored in the database, it's read in realtime
      // from the cluster

      try {
        const kc = new k8s.KubeConfig();
        kc.loadFromDefault();
        const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

        const res = await k8sApi.listNode();
        const nodes = _.map(res.body.items, async (item) => {
          let usageStats = {
            availableCPUs: -1,
            availableMemory: -1,
            availablePods: -1
          };
          const address = _.find(item.status!.addresses || [], { type: "InternalIP" });
          if (address) {
            try {
              const nodeIP = address.address;
              let uri = `http://${nodeIP}:10255/stats/summary`;
              const options: RequestPromiseOptions = {
                method: "GET",
              };
github atomist / sdm-core / lib / goal / container / k8s.ts View on Github external
async function containerStarted(container: K8sContainer, attempts: number = 240): Promise {
    let core: k8s.CoreV1Api;
    try {
        core = container.config.makeApiClient(k8s.CoreV1Api);
    } catch (e) {
        e.message = `Failed to create Kubernetes core API client: ${e.message}`;
        container.log.write(e.message);
        throw e;
    }

    const sleepTime = 500; // ms
    for (let i = 0; i < attempts; i++) {
        await sleep(500);
        const pod = (await core.readNamespacedPod(container.pod, container.ns)).body;
        const containerStatus = pod.status.containerStatuses.find(c => c.name === container.name);
        if (containerStatus && (!!_.get(containerStatus, "state.running.startedAt") || !!_.get(containerStatus, "state.terminated"))) {
            const message = `Container '${container.name}' started`;
            container.log.write(message);
            return;
        }
github learnk8s / templating-kubernetes / javascript / kubectl.js View on Github external
const { Pod, Container } = require('kubernetes-models/v1')
const k8s = require('@kubernetes/client-node')
const kc = new k8s.KubeConfig()

// Using the default credentials for kubectl
kc.loadFromDefault()
const k8sApi = kc.makeApiClient(k8s.CoreV1Api)

function createPod(environment = 'production') {
  return new Pod({
    metadata: {
      name: 'test-pod',
    },
    spec: {
      containers: [
        new Container({
          name: 'test-container',
          image: 'nginx',
          env: [{ name: 'ENV', value: environment }],
        }),
      ],
    },
  })
github stanford-oval / almond-cloud / tests / unit / test_k8s_api.js View on Github external
contexts: [
        {
            cluster: 'cluster',
            user: 'user',
        }
    ],
    users: [
        {
            name: 'user',
        }
    ],
};
const kc = new k8s.KubeConfig();
Object.assign(kc, fakeConfig);
const k8sApi = kc.makeApiClient(k8s.BatchV1Api);
const k8sCore = kc.makeApiClient(k8s.CoreV1Api);

function testDeleteNamespacedJob() {
    const args = getArgs(k8sApi.deleteNamespacedJob);
    assert.strictEqual(args[0], 'name');
    assert.strictEqual(args[1], 'namespace');
    assert.strictEqual(args[6], 'propagationPolicy');
}

function testListEndpointsForAllNamespaces() {
    const args = getArgs(k8sCore.listEndpointsForAllNamespaces)
    assert.strictEqual(args[2], 'fieldSelector');
}

function main() {
    testDeleteNamespacedJob();
    testListEndpointsForAllNamespaces();
github DanWahlin / DockerAndKubernetesCourseCode / samples / blue-green / dashboard / dist / dashboard.js View on Github external
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const k8s = require("@kubernetes/client-node");
const Table = require("easy-table");
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const appsV1Api = kc.makeApiClient(k8s.AppsV1Api);
const coreV1Api = kc.makeApiClient(k8s.CoreV1Api);
const roles = ['blue', 'green'];
getDeployments().catch(console.error.bind(console));
function getDeployments() {
    return __awaiter(this, void 0, void 0, function* () {
        const deploymentsRes = yield appsV1Api.listNamespacedDeployment('default');
        let deployments = [];
        for (const deployment of deploymentsRes.body.items) {
            let role = deployment.spec.template.metadata.labels.role;
            if (role && roles.includes(role)) {
                deployments.push({
                    name: deployment.metadata.name,
                    role,
                    status: deployment.status.conditions[0].status,
                    image: deployment.spec.template.spec.containers[0].image,
                    ports: [],
                    services: []
github kubernetes-client / javascript / examples / cache-example.js View on Github external
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

const path = '/api/v1/namespaces/default/pods';
const watch = new k8s.Watch(kc);
const listFn = (fn) => {
    k8sApi.listNamespacedPod('default')
        .then((res) => {
            fn(res.body.items);
        })
        .catch((err) => {
            console.log(err);
        });
}
const cache = new k8s.ListWatch(path, watch, listFn);

const looper = () => {
    const list = cache.list('default');
github qlik-oss / mira / src / orchestration / KubernetesClient.js View on Github external
constructor() {
    const kc = new k8s.KubeConfig();
    kc.loadFromCluster();
    this.k8sAppsApi = kc.makeApiClient(k8s.AppsV1Api);
    this.k8sCoreApi = kc.makeApiClient(k8s.CoreV1Api);
  }
github pixel-point / kube-forwarder / src / renderer / store / modules / Connections.js View on Github external
async function loadService(kubeConfig, namespace, serviceName) {
  const coreApi = kubeConfig.makeApiClient(k8s.CoreV1Api)

  try {
    return (await coreApi.readNamespacedService(serviceName, namespace)).body
  } catch (error) {
    throw k8nApiPrettyError(error, { _object: `Service "${serviceName}"` })
  }
}
github oslabs-beta / KuberOptic / src / main / local / local.ts View on Github external
const k8s = require('@kubernetes/client-node');
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

//const k8sApi2 = kc.makeApiClient(k8s.ExtensionsV1beta1Api);

let data = {};

async function fetchLocal(data={}){
    await k8sApi.listNamespacedPod('default').then((res) => {


   const metaDat = {};
   for(let meta in res.body.items[0].metadata){
      if(res.body.items[0].metadata[meta]){
         metaDat[meta] = res.body.items[0].metadata[meta]
      }
   }