@pubgcorp/kubectl
v1.2.1
Published
Kubernetes node client wrapper
Downloads
24
Keywords
Readme
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; }
for custom resource// clusterName is key of dictionary<name, K8sCluster> const result: KubectlResponse = await kubectl.targetCluster(clusterName).get(namespace, kind, name);
// 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);