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

kube-cookbook

v5.0.0

Published

Utility to generate kubernetes configuration for basic app types

Downloads

85

Readme

kube-cookbook

A utility to generate the minimal necessary config files for a web app running on kubernetes.

Prerequisites

  • node@8

Usage

Install from npm:

npm install -g kube-cookbook

Then in the project you want to create deployment files for:

kube-cookbook [config.yaml]

If a path to a config file is defined, it should be yaml, json, or a javascript file exporting an object.

If no file is specified .kube.yaml is loaded by default.

Options

All options can be defined either in a configuration file, or as command line flags.

  • recipe - the set of templates to generate, depending on the type of app being created - default 'webapp'
  • out - the directory in which to create generated files - default .
  • prefix - prefixes the name of the files generated - default ''
  • force - overwrite existing files - default false
  • dry-run - will output the generated config to stdout without generating any files
  • config - files to load additional configuration parameters from

Additional options for a recipe are documented for that recipe.

config parameters

If using the --config flag to load additional parameters, these can be json or yaml files.

Any data found in those files can be referenced in service templates as {{config.<filename>.<parameter>}}.

For example, if I have a versions.yaml as follows:

web: 1.0
api: 2.0

Then in my service configuration if I run with --config versions.yaml, then {{config.versions.web}} will be replaced with 1.0 and {{config.versions.api}} will be replaced with 2.0 in the generated service config.

Environment variables

Environment variables can be most simply defined as key:value pairs.

To load an environment variable from a secret, define in your configuration file as follows:

{
  "env": {
    "MY_SECRET_USERNAME": {
      "secret": true,
      "name": "my-secret",
      "key": "username"
    },
    "MY_SECRET_PASSWORD": {
      "secret": true,
      "name": "my-secret",
      "key": "password"
    }
  }
}

Or as yaml:

env:
  MY_SECRET_USERNAME:
    secret: true
    name: my-secret
    key: username
  MY_SECRET_PASSWORD:
    secret: true
    name: my-secret
    key: password

Recipes

The following recipes are available by default:

  • webapp - default
  • redis
  • internal-service
  • worker

In addition to these, you can pass a path to a custom recipe, or an npm module name.

To use a recipe in a local directory:

kube-cookbook --recipe ./kube

To use a recipe from a locall installed npm module:

kube-cookbook --recipe myrecipe

This will attempt to read the module kube-recipe-myrecipe from the local node_modules directory.

If a scoped module name is provided - eg. @scope/myrecipe then it is required as-is, and not prefixed with kube-recipe-.

Webapp Options

The following minimal options must be defined:

  • name - the name for your deployment
  • image - the location of the docker image for your app
  • url - the url on which your app will run

Additional options:

  • replicas - the number of instances of your app to run - default: 1
  • memory - the memory limit assigned to your app - default: '512Mi'
  • maxBodySize - the maximum body size allowed by ingress in megabytes - default: 2
  • env - a map of environment variables defined on your app
  • nginx - a map of environment variables defined on your nginx proxy

Internal Service Options

Internal services work in the same way as public facing web apps, with the exception that they are not accessible from the internet, and can only be accessed from other services in the namespace.

As such, the options are the same except the url option is no longer required, and a clients option is required.

  • clients - defines the name of the pods which will be granted network access to the service

Redis Options

The following minimal options must be defined:

  • name - the name for your deployment
  • clients - defines the name of the pods which will be granted network access to the redis instance
  • passwordName - the secret name for the redis password secret
  • passwordKey - the secret key for the redis password secret

Additional options:

  • replicas - the number of instances of your app to run - default: 1
  • prefix - prefixes the file names of the generated files - default 'redis-'

Worker Options

A worker is a service which does not need to be accessed by any other service.

The following minimal options must be defined:

  • name - the name for your deployment
  • image - the location of the docker image for your app

Additional options:

  • replicas - the number of instances of your app to run - default: 1
  • memory - the memory limit assigned to your app - default: '512Mi'
  • env - a map of environment variables defined on your app

Using multiple recipes

You can define multiple recipes in a single config file by defining each as an entry in an array.

Example:

---
- name: my-webapp
  recipe: webapp
  image: ...
  url: my-webapp.example.com
  env:
    REDIS_HOST: sessionstore
    REDIS_PASSWORD:
      secret: true
      name: redis-password
      key: password

- name: sessionstore
  recipe: redis
  clients: my-webapp
  passwordName: redis-password
  passwordkey: password

This will generate all the files required for both the webapp, and an accompanying redis sessionstore with the password loaded from a secret in the namespace.

Recipe Definition

Recipes should be defined as a javascript object, and one or more template yaml files.

The exported javascript should have the following format:

module.exports = {
  files: [
    // list of file templates to compile
  ],
  requires: {
    // required parameters and types
  },
  options: {
    // optional parameters and default values
  }
}

See the recipes included for examples - webapp | redis

Properties defined in the requires and options configuration can then be used in templates as mustache placeholders: e.g. {{{name}}}