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

@pulumi/kubernetesx

v0.1.6

Published

Pulumi Kubernetes Extensions

Downloads

26,284

Readme

Note: This library is under active development and subject to change. Not yet recommended for production workloads.

Pulumi Kubernetes Extensions

Kubernetes for Everyone

Using the Kubernetes API today often feels heavy and repetitive. Many of the API fields are deeply nested and require users to specify the same values over and over across different resources. While this input is necessary for Kubernetes to operate, it’s not very friendly to the people writing it.

The Kubernetes Extensions (kx) library for Pulumi is designed to simplify the declaration of Kubernetes resources, and make the API easier for everyone to use.

  1. Sane Defaults - Less boilerplate and easier to use. Common configurations require minimal code.
  2. Improved Authorship Experience - Simplified syntax for declaring and composing Kubernetes resources. Reference objects rather than juggling string references across resources.
  3. Idiomatic Kubernetes - We don't reinvent the wheel; no new API resources to learn. We make the existing APIs easier to use while still providing the full API for production use cases.

The kx library takes full advantage of being defined in TypeScript, not in YAML. This enables the use of functions, overloading, type-checking, and many other richer API design tools than are available using YAML or Helm.

If you are just getting started with Pulumi and Kubernetes, the Pulumi Kubernetes introduction is a good place to start.

| kx | raw provider | | :------------------------------------: | :-----------------------------------------------: | | kx example | raw provider example |

kx-up

Installation

This package is available in JavaScript/TypeScript for use with Node.js. Install it using either npm:

$ npm install @pulumi/kubernetesx

or yarn:

$ yarn add @pulumi/kubernetesx

Usage Examples

Define a Pod

Use the PodBuilder class to define a PodSpec that can be used by other kx classes that include a PodSpec (Pod, Deployment, StatefulSet, DaemonSet, ReplicaSet).

const pb = new kx.PodBuilder({
    containers: [{
        // name is not required. If not provided, it is inferred from the image.
        image: "nginx",
        ports: {http: 80}, // Simplified ports syntax.
    }]
});

Note that a PodBuilder does not create a k8s resource; it is a convenience class for defining a PodSpec that can be easily composed with other kx resources.

// Define the PodSpec.
const pb = new kx.PodBuilder({
    containers: [{image: "nginx"}]
});
// Create a Pod resource using the PodBuilder.
new kx.Pod("nginx", {
    spec: pb
});

Create a Deployment

Using a PodBuilder class to define the workload Pod, create a Deployment resource. Instantiating the kx.Deployment class will cause Pulumi to create a matching Deployment resource in your Kubernetes cluster on the next pulumi up.

const pb = new kx.PodBuilder(...);
const deployment = new kx.Deployment("app", {
    // asDeploymentSpec() takes parameters corresponding 
    // to a DeploymentSpec (e.g., replicas).
    spec: pb.asDeploymentSpec({ replicas: 3 }) 
});

Note that you can still define the DeploymentSpec explicitly, but would be responsible for defining required fields (labels/selectors, etc.) as usual. This still benefits from the enhanced kx syntax for env, ports, volumeMounts, and resource composability.

const deployment = new kx.Deployment("app", {
    spec: {
        selector: {
            matchLabels: {
                app: "my-app",
            }
        },
        replicas: 3,
        template: {
            metadata: {
                labels: {
                    app: "my-app",
                }
            },
            spec: {
                containers: [{
                    image: "nginx",
                    ports: {http: 80},
                }]
            }
        }
    }
});

Create a ClusterIP Service from the Deployment

Easily create a Service from a workload using the createService verb.

const deployment = new kx.Deployment(...);
const service = deployment.createService();

Add a PersistentVolumeClaim to a Pod

Use the mount verb on a PersistentVolumeClaim to add it to a Pod under the volumeMounts field. The PodBuilder automatically creates the corresponding volume and naming boilerplate.

const pvc = new kx.PersistentVolumeClaim("data", {
    spec: {
        accessModes: [ "ReadWriteOnce" ],
        resources: { requests: { storage: "1Gi" } }
    }
});
const pb = new kx.PodBuilder({
    containers: [{
        image: "nginx",
        ports: {http: 80},
        volumeMounts: [ pvc.mount("/data") ],
    }]
});

Create Environment Variables from a ConfigMap and Secret

Use the asEnvValue verb on ConfigMap and Secret resources to add them to the Pod under the env field. The PodBuilder automatically creates the relevant boilerplate depending on the resource type.

const cm = new kx.ConfigMap("cm", {
    data: { "config": "very important data" }
});
const secret = new kx.Secret("secret", {
    stringData: { "password": new random.RandomPassword("password", { length: 12 }).result }
});
const pb = new kx.PodBuilder({
    containers: [{
        env: {
            DATA: cm.asEnvValue("config"),
            PASSWORD: secret.asEnvValue("password"),
        },
        image: "nginx",
        ports: {http: 80},
    }]
});

Learn more about Pulumi

Intro to Pulumi

Get Started with Kubernetes

Crosswalk for Kubernetes

Pulumi: A Better Way to Kubernetes

Pulumi's YouTube Channel