Skip to content

Instantly share code, notes, and snippets.

@kooba
Last active February 1, 2019 12:08
Show Gist options
  • Save kooba/c0a2fef8bcdef6ec40cf3dba579ec135 to your computer and use it in GitHub Desktop.
Save kooba/c0a2fef8bcdef6ec40cf3dba579ec135 to your computer and use it in GitHub Desktop.
Development in the Cloud
const kubernetes = require('@kubernetes/client-node');
const k8sClient = kubernetes.Config.defaultClient();
const createNamespace = async (namespaceName) => {
const existingNamespace = await k8sClient.listNamespace(
true, '', `metadata.name=${namespaceName}`,
);
if (existingNamespace.body.items.length) {
console.log(`Namespace "${namespaceName}" already exists`);
return;
}
const namespace = new kubernetes.V1Namespace();
namespace.metadata = new kubernetes.V1ObjectMeta();
namespace.metadata.name = namespaceName;
await k8sClient.createNamespace(namespace);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment