Skip to content
Fastify Kubernetes client plugin
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
.editorconfig
.eslintrc.json
.gitignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
index.js
package-lock.json
package.json

README.md

fastify-kubernetes

npm version Dependencies Status Build Status JavaScript Style Guide

Fastify Kubernetes client plugin.

This plugin uses the official Node.js Kubernetes client under the hood. The current bundled version is v0.8.2.

Install

npm install --save fastify-kubernetes

Usage

Add it to your project with register and you are done!

const fastify = require('fastify')()

fastify.register(require('fastify-kubernetes'), {
  // Optional, defaults to OS default Kubeconfig file location
  file: "/home/app/.kube/config",
  // Context to use
  context: "production"
})

fastify.get('/pods', async function (req, reply) {
  const client = this.kubernetes.api.Core_v1Api
  const result = await client.listNamespacedPod(this.kubernetes.namespace);
  reply.send(result.body.items)
})

fastify.listen(3000, err => {
  if (err) throw err
})

Reference

The plugin will inject six properties under kubernetes decorator.

config

KubeConfig class instance.

context

Current context name.

cluster

Current context's cluster.

user

Current context's user.

namespace

Current context's namespace, defaults to "default".

api

Object containing all possible client instances. You can retrieve a client by its name from the kubernetes client lib.

this.kubernetes.api.Core_v1Api
this.kubernetes.api.Batch_v1Api
this.kubernetes.api.Batch_v1beta1Api
You can’t perform that action at this time.