2.0.6 • Published 3 years ago

@thinkdeep/k8s-manifest v2.0.6

Weekly downloads
-
License
AGPL-3.0-only
Repository
github
Last release
3 years ago

@thinkdeep/k8s-manifest

CircleCI Quality Gate Status Security Rating Coverage Status Maintainability Vulnerabilities

Simple interface providing kubernetes javascript client object creation by use of yaml strings or plain javascript objects.

Dependencies

Installation

    npm i @thinkdeep/k8s-manifest

Usage

    import { k8sManifest, stringify } from '@thinkdeep/k8s-manifest';

    const options = {
        name: 'dynamic-cron-job',
        namespace: 'production',
        schedule: '* * * * *',
        image: 'busybox',
        command: 'echo',
        args: ['Hello World']
    };

    // Assuming environment variables have been defined...
    const cronJob = k8sManifest(`
        apiVersion: "batch/v1"
        kind: "CronJob"
        metadata:
            name: "${options.name}"
            namespace: "${options.namespace || "default"}"
        spec:
            schedule: "${options.schedule}"
            jobTemplate:
                spec:
                    template:
                        spec:
                            containers:
                                - name: "${process.env.HELM_RELEASE_NAME}-data-collector"
                                  image: "${options.image}"
                                  command: ["${options.command}"]
                                  args: ${JSON.stringify(options.args)}
                                  envFrom:
                                  - secretRef:
                                      name: "${process.env.HELM_RELEASE_NAME}-deep-microservice-collection-secret"
                                  ${ process.env.PREDECOS_KAFKA_SECRET ? `
                                  - secretRef:
                                      name: "${process.env.PREDECOS_KAFKA_SECRET}"
                                  ` : ``}
                            serviceAccountName: "${process.env.HELM_RELEASE_NAME}-secret-accessor-service-account"
                            restartPolicy: "Never"
                            imagePullSecrets:
                                - name: "docker-secret"
    `);

    const pod = k8sManifest({
        apiVersion: 'v1',
        kind: 'Pod',
        metadata: {
            name: 'sample-pod'
        },
        spec: {
            containers: [{
                name: 'container-name',
                image: 'nginx'
            }],
            dnsPolicy: "ClusterFirst",
            imagePullSecrets: [{
                name: "docker-secret"
            }],
            restartPolicy: "Never",
            schedulerName: "default-scheduler",
            securityContext: {},
            serviceAccount: "service-account",
            serviceAccountName: "service-account-name",
            terminationGracePeriodSeconds: 30
        }
    });

    console.log(`The first new object is: \n${stringify(cronJob)}`);

    console.log(`The second new object is: \n${stringify(pod)}`);
2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.6

3 years ago

2.0.1-beta.2

3 years ago

2.0.1-beta.3

3 years ago

2.0.1-beta.0

3 years ago

2.0.1-beta.1

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.0-beta.3

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.0

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago