npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@leverage/kubernetes

v1.1.2

Published

Manage Kubernetes manifests with Leverage.

Downloads

1

Readme

NOTE: This library is quite new and things are still being fleshed out. It should work, but be prepared for a few quirks!

Installation

First, install the package with your preferred package manager.

npm install @leverage/kubernetes

Then, add the kubernetes plugin to your Leverage manager.

import { add } from "@leverage/core";
import { kubernetes } from "@leverage/kubernetes";

add(kubernetes);

Usage

Kubernetes Resources

You can use this plugin in combination with Senchou to generate and manage Kubernetes resources. First, use Senchou to generate a module with Kubernetes API Object definitions.

npx @senchou/cli k8s

Then, create a KubernetesComponent for your resource.

// my-pod.ts
import { Pod } from "./senchou/k8s.ts";
import { useKubernetes } from "@leverage/kubernetes";

export const init = () => {
    useKubernetes({
        name: "my-pod",
    });
};

export const render = () => {
    return Pod({
        metadata: {
            name: "my-pod",
            labels: {
                "x-generated-by": "leverage",
            },
        },
        spec: {
            containers: [{ image: "my-image" }],
        },
    });
};

And finally add that unit to your manager instance and render.

import { add } from "@leverage/core";
import { kubernetes, render } from "@leverage/kubernetes";
import myPod from "./my-pod";

add(kubernetes, myPod);

const output = await render();

Helm Resources

You can use existing helm charts by creating a HelmComponent.

// my-helm-component.ts
import { useHelm } from "@leverage/kubernetes";

export const init = () => {
    useHelm({
        name: "my-traefik-release",
        chart: "traefik/traefik",
        repository: {
            name: "traefik",
            url: "https://helm.traefik.io/traefik",
        },
    });
};

export const values = () => {
    return {
        mySetting: true,
    };
};

Then add the component and plugin to Leverage in order to render the chart.

import { add } from "@leverage/core";
import { kubernetes, render } from "@leverage/kubernetes";
import myHelmComponent from "./my-helm-component";

add(kubernetes, myHelmComponent);

const output = await render();

Custom Helm Charts

You can use this plugin with @senchou/helm to create your own charts.

Start by creating a ChartComponent.

// my-chart.ts
import { useChart } from "@leverage/kubernetes";

export const init = () => {
    useChart({
        name: "my-chart",
        meta: {
            version: "0.0.0",
        },
        values: {
            http: {
                enable: true,
                port: 80,
            },
        },
    });
};

Then, create a ChartTemplateComponent to add a resource to the chart.

// my-pod-template.ts
import { useChartTemplate } from "@leverage/kubernetes";
import { template } from "@senchou/helm";
import { Pod, ContainerPort } from "./senchou/k8s";

export const init = () => {
    useChartTemplate({
        name: "my-pod",
    });
};

export const render = () => {
    return template(Pod, {
        metadata: {
            name: "my-pod",
        },
        spec: {
            containers: [
                {
                    name: "my-container",
                    image: "my-image",
                    ports: [
                        template.if<ContainerPort>({
                            type: Object,
                            condition: ".Values.http.enable",
                            body: {
                                name: "http",
                                containerPort: template.string(
                                    ".Values.http.port"
                                ),
                            },
                            else: [],
                        }),
                    ],
                },
            ],
        },
    });
};

Finally, add this plugin and all of your units to your Leverage Manager and call render.

import { add } from "@leverage/core";
import { kubernetes, render } from "@leverage/kubernetes";
import myChart from "./my-chart";
import myPodTemplate from "./my-pod-template";

add(kubernetes, myChart, myPodTemplate);

const output = await render();

Patch Resources

You can apply patches to Kubernetes resources by creating a PatchComponent.

// my-patch.ts
import { usePatch } from "@leverage/kubernetes";
import { isPod } from "./senchou/k8s";

export const init = () => {
    usePatch({
        name: "my-patch",
    });
};

export const patch = (resource: object) => {
    // This patch will be responsible for patching Pod resources.
    if (isPod(resource)) {
        resource.metadata.labels = {
            ...resource.metadata.labels,
            "x-patched-by": "leverage",
        };
    }
};

Then add your patch along with all of your other components. When rendered, patches will be applied before the final output is returned.

import { add } from "@leverage/core";
import { kubernetes, render } from "@leverage/kubernetes";
import myPod from "./my-pod";
import myPatch from "./my-patch";

add(kubernetes, myPod, myPatch);

const output = await render();