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

@grucloud/k8s-manifest2code

v12.14.1

Published

Generate Grucloud Code from kubernetes YAML manifest

Downloads

14

Readme

K8s Manifest to GruCloud Code

This code generator takes any kubernetes YAML manifests and creates the corresponding resources written with the GruCloud Javascript SDK.

Currently used to create the following kubernetes modules:

k8s-manifest2code supports reading from a single file, recursively from a directory, and from HTTPS.

Tutorial: How to create a Kubernetes Module with k8s-manifest2code

We'll create a web ui dashboard grucloud module and its example with the help of the k8s-manifest2code generator.

Create the module-k8s-dashboard project

mkdir web-ui-dashboard
cd web-ui-dashboard

Let's create a package.json for this module:

  • in the particular case the package name is @grucloud/example-module-k8s-web-ui-dashboard
  • the entry point should be the generated file resources.js
npm init

Install the dependencies:

npm install @grucloud/core @grucloud/provider-k8s @grucloud/k8s-manifest2code

Npm scripts

We'll add 2 npm scripts in the package.json.

  • download-manifest: downloads the manifest locally and name it web-ui-dashboard.yaml.
  • gen-code: generate the GruCloud code resource.js from this manifest with k8s-manifest2code.

We found out the manifest URL from the official documentation 'deploying-the-dashboard-ui'

// package.json
  "scripts": {
    "download-manifest": "curl -L -o web-ui-dashboard.yaml https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml",
    "gen-code": "k8s-manifest2code --input web-ui-dashboard.yaml"
  },

Download the manifest

Download the manifest with:

npm run download-manifest

Check to content of web-ui-dashboard.yaml, you are supposed to find a set of K8s resources such as Namespace, ServiceAccount, Service, Secret, Config Map, Role, RoleBinding, Deployment, etc ....

Generate the code

Generate the GruCloud source code from the k8s manifest:

npm run gen-code

Check the resources.js to find out which resources will be set up.

Create an example project

mkdir example
cd example

Let's create a package.json, in the case the package name is @grucloud/example-module-k8s-web-ui-dashboard:

npm init

Install the dependencies:

npm install @grucloud/core @grucloud/provider-k8s @grucloud/example-module-k8s-web-ui-dashboard

Create the iac.js file

It is now time to create a K8s provider and uses the generated createResources function from package @grucloud/module-k8s-web-ui-dashboard

// iac.js
const { K8sProvider } = require("@grucloud/provider-k8s");
const { createResources } = require("../resources");

exports.createStack = async ({ createProvider }) => {
  const provider = createProvider(K8sProvider, { config: require("./config") });
  const resources = await createResources({ provider });
  return { provider, resources };
};

Deploying

Ensure your cluster is running and execute:

gc apply
┌──────────────────────────────────────────────────────────────────────────────────────────────┐
│ Plan summary for provider k8s                                                                │
├──────────────────────────────────────────────────────────────────────────────────────────────┤
│ DEPLOY RESOURCES                                                                             │
├────────────────────┬─────────────────────────────────────────────────────────────────────────┤
│ ServiceAccount     │ kubernetes-dashboard                                                    │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Service            │ kubernetes-dashboard, dashboard-metrics-scraper                         │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Secret             │ kubernetes-dashboard-certs, kubernetes-dashboard-csrf                   │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ ConfigMap          │ kubernetes-dashboard-settings                                           │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Role               │ kubernetes-dashboard                                                    │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ ClusterRole        │ kubernetes-dashboard                                                    │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ RoleBinding        │ kubernetes-dashboard                                                    │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ ClusterRoleBinding │ kubernetes-dashboard                                                    │
├────────────────────┼─────────────────────────────────────────────────────────────────────────┤
│ Deployment         │ kubernetes-dashboard, dashboard-metrics-scraper                         │
└────────────────────┴─────────────────────────────────────────────────────────────────────────┘
? Are you sure to deploy 12 resources, 9 types on 1 provider? › (y/N)
Deploying resources on 1 provider: k8s
✓ k8s
  ✓ Initialising
  ✓ Deploying
    ✓ ServiceAccount 1/1
    ✓ Service 2/2
    ✓ Secret 2/2
    ✓ ConfigMap 1/1
    ✓ Role 1/1
    ✓ ClusterRole 1/1
    ✓ RoleBinding 1/1
    ✓ ClusterRoleBinding 1/1
    ✓ Deployment 2/2
12 resources deployed of 9 types and 1 provider
Command "gc apply" executed in 52s

The Web Ui Dashboard should be up and running. GruCloud waits for all the resources to up. For instance, a deployment is considered up if one of the container's pod started by the deployment is running.