How to use the kubernetes-client.Client function in kubernetes-client

To help you get started, we’ve selected a few kubernetes-client 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 godaddy / kubernetes-client / examples / basic-auth.js View on Github external
async function main () {
  try {
    const client = new Client({
      config: {
        url: process.env.K8S_CLUSTER_HOST,
        auth: {
          user: process.env.K8S_USER,
          pass: process.env.K8S_PASSWORD
        },
        insecureSkipTlsVerify: true
      },
      version: process.env.K8S_CLUSTER_VERSION
    })

    //
    // Fetch all the pods
    const pods = await client.api.v1.pods.get()
    pods.body.items.forEach((item) => {
      console.log(item.metadata)
github godaddy / kubernetes-client / examples / canary-controller.js View on Github external
//
// You can create a Deployment and Service to experiment with using the
// coalmine example:
//
//   $ kubectl apply -f examples/coalmine-deploy.json
//   $ kubectl expose deployment coalmine --type=NodePort --selector='app=coalmine,state=stable'
//   $ minikube service coalmine --url
//
const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config
const JSONStream = require('json-stream')

const namespace = 'default'
const deployment = 'coalmine'

const client = new Client({ config: config.fromKubeconfig(), version: '1.9' })

function watchPod (pod) {
  const podClient = client.api.v1.namespaces(namespace).pods(pod)
  const stream = podClient.log.getStream({ qs: { follow: true } })
  const jsonStream = new JSONStream()
  stream.pipe(jsonStream)

  jsonStream.on('data', async object => {
    console.log('Log event:', JSON.stringify(object, null, 2))
    if (object.level === 'error') {
      console.warn(`Error in ${pod}`)
      await podClient.patch({
        body: {
          metadata: {
            labels: {
              state: 'failed'
github godaddy / kubernetes-client / examples / basic.js View on Github external
async function main () {
  try {
    const client = new Client({ version: '1.9' })

    //
    // Get all the Namespaces.
    //
    const namespaces = await client.api.v1.namespaces.get()
    console.log('Namespaces: ', namespaces)

    //
    // Create a new Deployment.
    //
    const create = await client.apis.apps.v1.namespaces('default').deployments.post({ body: deploymentManifest })
    console.log('Create: ', create)

    //
    // Fetch the Deployment we just created.
    //
github godaddy / kubernetes-client / examples / vpa / index.js View on Github external
async function main () {
  try {
    const client = new Client({
      config: config.fromKubeconfig(),
      version: '1.12'
    })

    //
    // Add endpoints to our client
    //
    client.addCustomResourceDefinition(vpa)

    //
    // List all the resources of the new type
    //
    const all = await client.apis['autoscaling.k8s.io'].v1beta2.namespaces('default').verticalpodautoscalers.get()
    console.log('All VPAs: ', all)

    //
github godaddy / kubernetes-client / examples / deployment-create-patch-rollback.js View on Github external
async function main () {
  try {
    const client = new Client({ config: config.fromKubeconfig(), version: '1.10' })

    // Create a deployment
    const create = await client.apis.apps.v1.ns('default').deploy.post({ body: deploymentManifest })
    console.log('Create: ', create)

    // Update the deployment
    // Change the image from nginx:1.7.9 to nginx:1.9.1
    const updateImage = await client.apis.apps.v1.ns('default').deploy('nginx-deployment').patch({
      body: {
        spec: {
          template: {
            spec: {
              containers: [{
                name: 'nginx',
                image: 'nginx:1.9.1'
              }]
github godaddy / kubernetes-client / examples / client-from-apiserver-swagger.js View on Github external
async function main () {
  try {
    const client = new Client({ config: config.fromKubeconfig() })
    //
    // Load the /swagger.json from the kube-apiserver specified in config.fromKubeconfig()
    //
    await client.loadSpec()

    const create = await client.apis.apps.v1.namespaces('default').deployments.post({ body: deploymentManifest })
    console.log('Result: ', create)
  } catch (err) {
    console.error('Error: ', err)
  }
}
github microsoft / pai / src / synchronizer / src / core / k8s.js View on Github external
async init () {
    const backend = new Request(this.apiServerConfig)
    const client = new Client({ backend })
    await client.loadSpec()
    // If "frameworkcontroller.microsoft.com" is not found, try to load it from crd.
    if (client.apis['frameworkcontroller.microsoft.com'] === undefined) {
      const frameworkDef = await client.apis['apiextensions.k8s.io'].v1beta1.customresourcedefinitions('frameworks.frameworkcontroller.microsoft.com').get()
      client.addCustomResourceDefinition(frameworkDef.body)
    }
    this.client = client
  }
github eclipse / codewind / src / pfe / portal / server.js View on Github external
global.codewind = {
    RUNNING_IN_K8S: false,
    MULTI_USER: (process.env.MULTI_USER == 'true') || false,
    EXTENSIONS: (process.env.EXTENSIONS == 'true') || false,
    // Workspace location *inside* the our container.
    // Volume is mounted from WORKSPACE_DIRECTORY in docker-compose.yaml.
    CODEWIND_WORKSPACE: '/codewind-workspace/',
    CODEWIND_TEMP_WORKSPACE: '/cw-temp/',
    // temporary mounted workspace directory retained for projects that still require it
    MOUNTED_WORKSPACE: '/mounted-workspace'
  };

  // find if running in kubernetes and build up a whitelist of allowed origins

  try {
    k8Client = new K8Client({ config: k8config.getInCluster(), version: '1.9' });
  }
  catch (err) {
    log.info('Codewind does not appear to be running in k8s')
    global.codewind.RUNNING_IN_K8S = false;
  }

  const originsWhitelist = []
  try {
    if (k8Client) {
      log.info('Codewind is running in k8s');
      global.codewind.RUNNING_IN_K8S = true;
      global.codewind.k8Client = k8Client;

      // get current ingress path - it is passed in an env var
      // https://github.com/eclipse/codewind-che-plugin/blob/master/codewind-che-sidecar/scripts/kube/codewind_template.yaml#L135
      const INGRESS_HOST_ENVVAR = 'CHE_INGRESS_HOST';
github eclipse / codewind / src / pfe / file-watcher / server / src / utils / kubeutil.ts View on Github external
import { Operation } from "../projects/operation";
const execAsync = promisify(exec);
import * as path from "path";
import * as logger from "./logger";
import { ContainerStates } from "../projects/constants";
import * as processManager from "./processManager";
import { ProcessResult } from "./processManager";
import { ProjectInfo } from "../projects/Project";
import * as projectExtensions from "../extensions/projectExtensions";

const Client = require("kubernetes-client").Client; // tslint:disable-line:no-require-imports
const config = require("kubernetes-client").config; // tslint:disable-line:no-require-imports
let k8sClient: any = undefined;

if (process.env.IN_K8) {
    k8sClient = new Client({ config: config.getInCluster(), version: "1.9"});
}

const KUBE_NAMESPACE = process.env.KUBE_NAMESPACE || "default";

export interface PodInfo {
    podName: string;
    ip: string;
    serviceName: string;
    exposedPort: string;
    internalPort: string;
    podPorts: string[];
  }

  /**
   * @function
   * @description Get kube pod info.
github nodeshift / openshift-rest-client / lib / openshift-rest-client.js View on Github external
// Check to see if we are passing in a username/password
        const accessToken = await getTokenFromBasicAuth({ insecureSkipTlsVerify: kubeconfig.insecureSkipTlsVerify, url: kubeconfig.url, user: kubeconfig.auth.username || kubeconfig.auth.user, password: kubeconfig.auth.password || kubeconfig.auth.pass });

        kubeconfig = {
          url: kubeconfig.url,
          auth: {
            bearer: accessToken
          },
          insecureSkipTlsVerify: 'insecureSkipTlsVerify' in kubeconfig ? Boolean(kubeconfig.insecureSkipTlsVerify) : false
        };
      }
    }
  }

  const kbconfig = new KubeConfig();
  const client = new Client({ backend: kubeconfig || kbconfig.loadFromDefault(), spec, getNames: getNames });

  // CRD with the service instance stuff, but only to this client, not the cluster
  client.addCustomResourceDefinition(serviceCatalogCRD);
  return client;
}

kubernetes-client

Simplified Kubernetes API client.

MIT
Latest version published 4 years ago

Package Health Score

56 / 100
Full package analysis

Popular kubernetes-client functions