k8sresources
v0.2.6
Published
A package that exports creators for Kubernetes resources based on the Kubernetes OpenAPI specification
Downloads
25
Maintainers
Readme
k8sresources
This repository contains constructors for common Kubernetes resources.
Usage
Installation for Development
npm install -D k8sresources @types/node;
For appliying with kubectl
To apply the JavaScript-based templates, use the k8sjs
package.
Install it using:
npm install -g k8sjs
And you can generate the template using:
kubectl js template ./path/to/yourfile.js
To apply it directly:
kubectl js template ./path/to/yourfile.js | kubectl apply -f -
To dump the output into a yaml manifest:
kubectl js template ./path/to/yourfile.js > ./path/to/yourfile.yaml
Using
With JavaScript
const {createDeployment} = require('k8sresources');
const deployment = createDeployment('apps/v1', {name: 'test'});
deployment.spec.template.spec.containers.push(
{
image: 'zephinzer/demo-echoserver:latest',
imagePullPolicy: 'IfNotPresent',
name: 'echoserver',
},
);
module.exports = deployment;
// if you'd like to see the output:
// console.info(JSON.stringify(deployment, null, 2));
With TypeScript
import {createDeployment} from 'k8sresources';
const deployment = createDeployment('apps/v1', {name: 'test'});
deployment.spec.template.spec.containers.push(
{
image: 'zephinzer/demo-echoserver:latest',
imagePullPolicy: 'IfNotPresent',
name: 'echoserver',
},
);
export default deployment;
// if you'd like to see the output:
// console.info(JSON.stringify(deployment, null, 2));
Roadmap
Version 1
This package should be able to generate templates for the following Kubernetes resources:
Application
- [x] Deployments (v0.1.3)
- [x] Services (v0.2.6)
- [ ] Ingresses
Configuration
- [ ] ConfigMaps
- [ ] Secrets
Storage
- [ ] PersistentVolume
- [ ] PersistentVolumeClaim
RBAC
- [ ] ServiceAccount
- [ ] Role
- [ ] RoleBinding
- [ ] ClusterRole
- [ ] ClusterRoleBinding
Development Runbook
Development of Code
- Code is located in the
./src
directory - Before testing changes, run
npm run build
- Use the code in
./examples
to test out your changes
Building
- The build process is a little hacky, final build is stored in
./lib
- To trigger the build process, use
npm run build
.
Publishing
- Bump the version in the root
package.json
- Run the build:
npm run build
- Navigate into the
./lib
directory - Publish the NPM package:
npm publish
License
This code is licensed under the MIT license.