How to use the @kubernetes/client-node.loadYaml 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 / yaml-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 yamlString = k8s.dumpYaml({
  metadata: {
    name: 'test'
  }
});

const yamlNamespace = k8s.loadYaml(yamlString);

k8sApi.createNamespace(yamlNamespace).then(
  (response) => {
    console.log('Created namespace');
    console.log(response);
    k8sApi.readNamespace(yamlNamespace.metadata.name).then(
      (response) => {
        console.log(response);
        k8sApi.deleteNamespace(
          yamlNamespace.metadata.name, {} /* delete options */);
      });
  },
  (err) => {
    console.log('Error!: ' + err);
  }
);
github NERC-CEH / datalab / code / workspaces / infrastructure-api / src / kubernetes / configMapApi.js View on Github external
async function createNamespacedConfigMap(name, namespace, manifest) {
  const k8sApi = getCoreV1Api();

  try {
    logger.info(`Creating configMap with name ${name} in namespace ${namespace} with manifest:`);
    logger.debug(manifest);
    const configMap = loadYaml(manifest);
    return k8sApi.createNamespacedConfigMap(namespace, configMap);
  } catch (error) {
    logger.error(`Error creating configMap with name ${name} in namespace ${namespace}`, error.response.body);
    throw error;
  }
}