@pubgcorp/kubectl
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

How to Use

1. Implement IKubeConfigFactory

class KubeconfigFactory implements IKubeconfigFactory {
    public async getKubeconfigs(): Promise<{ [name: string]: IKubeconfig }> {
        // TODO: Implement method making Dictionary<name, IKubeconfig> 
    }
}

2. Create Kubectl Instance

  • General Version
    const kubectl = new Kubectl(new KubeconfigFactory());
  • Using tsyringe Version
    // entrypoint of application
    container.register<Kubectl>(Kubectl, { useFactory: (c) => new Kubectl(c.resolve(KubeconfigFactory)) });

3. Examples

  • Get Resource
    export interface KubectlResponse {
        status: string;
        message: string;
        obj?: any;
    }
    // clusterName is key of dictionary<name, K8sCluster>
    const result: KubectlResponse = await kubectl.targetCluster(clusterName).get(namespace, kind, name);
    for custom resource
    // apiVersion means like kubernetes-client.io/v1
    const result: KubectlResponse = await kubectl.targetCluster(clusterName).get(namespace, kind, name, apiVersion);
  • Apply Resource
    const K8sObjects = [{
        kind: 'Namespace',
        apiVersion: 'v1',
        metadata: {
            name: 'abcdefg',
            labels: {},
            annotations: {},
        }
    }]
    const result = await kubectl.targetCluster(clusterName).apply(k8sObjects);
  • Patch Resource
    if useJsonPatch is true, use object as json patch object, otherwise get target and merge with object.
    const result = await kubectl.targetCluster(clusterName).patch(namespace, target, targetName, object, useJsonPatch);

Readme

Keywords

none

Package Sidebar

Install

npm i @pubgcorp/kubectl

Weekly Downloads

17

Version

1.2.1

License

Apache-2.0

Unpacked Size

49.6 kB

Total Files

24

Last publish

Collaborators

  • feelyoung-jay
  • pubg-suchanpark
  • dalpark
  • dirty49374
  • mnthe
  • bitofsky
  • pril
  • talkwithraon
  • byeonggukgong