{"id":14975841,"url":"https://github.com/greguz/fastify-kubernetes","last_synced_at":"2025-10-27T14:31:17.230Z","repository":{"id":46245033,"uuid":"179458238","full_name":"greguz/fastify-kubernetes","owner":"greguz","description":"Fastify Kubernetes client plugin.","archived":false,"fork":false,"pushed_at":"2025-01-13T12:56:59.000Z","size":205,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-03T03:28:49.950Z","etag":null,"topics":["fastify","k8s","kubernetes"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greguz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-04-04T08:45:07.000Z","updated_at":"2025-01-13T12:57:03.000Z","dependencies_parsed_at":"2024-09-23T18:30:40.423Z","dependency_job_id":"945f81ed-88c2-4539-bb1e-bde9c6bf2336","html_url":"https://github.com/greguz/fastify-kubernetes","commit_stats":{"total_commits":92,"total_committers":1,"mean_commits":92.0,"dds":0.0,"last_synced_commit":"54cb35f6504dadecd4920fc579c43304bef020f6"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Ffastify-kubernetes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Ffastify-kubernetes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Ffastify-kubernetes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greguz%2Ffastify-kubernetes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greguz","download_url":"https://codeload.github.com/greguz/fastify-kubernetes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238508845,"owners_count":19484214,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["fastify","k8s","kubernetes"],"created_at":"2024-09-24T13:52:45.152Z","updated_at":"2025-10-27T14:31:15.740Z","avatar_url":"https://github.com/greguz.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# fastify-kubernetes\n\n[![npm version](https://badge.fury.io/js/fastify-kubernetes.svg)](https://badge.fury.io/js/fastify-kubernetes)\n[![Dependencies Status](https://david-dm.org/greguz/fastify-kubernetes.svg)](https://david-dm.org/greguz/fastify-kubernetes.svg)\n![ci](https://github.com/greguz/fastify-kubernetes/workflows/ci/badge.svg)\n[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\nFastify Kubernetes client plugin.\n\nThis plugin uses the [official Node.js Kubernetes client](https://www.npmjs.com/package/@kubernetes/client-node) under the hood.\n\n## Compatibility\n\nThe installed version of `@kubernetes/client-node` is the `v1.x.x`.\nThe targeted Kubernetes version is from the `v1.28` to `v1.30`.\n\nFor more info about supported Kubernetes version see [here](https://github.com/kubernetes-client/javascript#compatibility).\n\n\u003e Generally speaking newer clients will work with older Kubernetes, but compatability isn't 100% guaranteed.\n\n## Install\n\n```\nnpm install --save fastify-kubernetes\n```\n\n## Usage\n\nAdd it to your project with `register` and you are done!\n\n```javascript\nconst fastify = require('fastify')()\n\nfastify.register(require('fastify-kubernetes'), {\n  // Optional, defaults to OS default Kubeconfig file location\n  file: '/home/app/.kube/config',\n  // Context to use\n  context: 'production'\n})\n\nfastify.get('/pods', async function (req, reply) {\n  const client = this.kubernetes.api.CoreV1Api\n  const result = await client.listNamespacedPod(this.kubernetes.namespace)\n  reply.send(result.body.items)\n})\n\nfastify.listen(3000, err =\u003e {\n  if (err) throw err\n})\n```\n\n### ESM - CommonJS Interoperability\n\nThis module is now pure [ESM](https://nodejs.org/api/esm.html). This is to use the same module system of the `@kubernetes/client-node` (as from v1.0.0).\n\nThis shouldn't be a problem with Node.js v22.13.0 or newer.\n\nIf you are seeing an error like this one:\n\n```\nError [ERR_REQUIRE_ESM]: require() of ES Module node_modules/fastify-kubernetes/fastify-kubernetes.js from my_script.js not supported.\nInstead change the require of fastify-kubernetes.js in my_script.js to a dynamic import() which is available in all CommonJS modules.\n    at Object.\u003canonymous\u003e (my_script.js:2:20) {\n  code: 'ERR_REQUIRE_ESM'\n}\n```\n\nYou have multimple options to solve the problem:\n\n- Upgrade you Node.js version to \u003e=22.13.0\n- Use `await import('fastify-kubernetes')` instead of `require('fastify-kubernetes')`\n- Convert your project to use ESM instead of CommonJS\n\n## Options\n\nAll properties are optional.\n\n- `kubeconfig`: Kubernetes config file loading mode. Default is `\"auto\"`.\n  - `KubeConfig`: Load custom `KubeConfig` instance (see `@kubernetes/client-node` docs).\n  - `\"auto\"`: Choose the first available mode in this order: Choose the first available config mode in this order: `\"file\"`, `\"yaml\"`, `\"in-cluster\"`, and `\"default\"`.\n  - `\"file\"`: Load config file from `file` option.\n  - `\"yaml\"`: Load config from `yaml` option.\n  - `\"in-cluster\"`: Load in-cluster kubeconfig file.\n  - `\"default\"`: Load config file the default OS location.\n- `file`: `kubeconfig` (YAML format) file path.\n- `yaml`: Raw `kubeconfig` yaml data (string of Node.js `Buffer`).\n- `context`: Loads Context by name.\n- `cluster`: Loads Context by Curster's name.\n- `user`: Loads Context by User's name.\n- `namespace`: Loads Context by Namespace.\n- `name`: Nested (Fastify) decorator name (will inject `fastify.kubernetes[key]`).\n\n```javascript\nimport Fastify from 'fastify'\n\nconst fastify = Fastify()\n\nfastify\n  .register(require('fastify-kubernetes'), {\n    context: 'eu-cluster-0',\n    name: 'eu'\n  })\n  .register(require('fastify-kubernetes'), {\n    context: 'us-cluster-0',\n    name: 'us'\n  })\n\nfastify.get('/', async function (req, reply) {\n  const euClient = this.kubernetes.eu.api.CoreV1Api\n  const usClient = this.kubernetes.us.api.CoreV1Api\n  // ------------\n  // do your stuff here\n  // ------------\n  reply.send(yourResult)\n})\n\n// TODO: start server, etc..\n```\n\n## Reference\n\nThe plugin will inject six properties under `kubernetes` decorator.\n\n- `config` is the `KubeConfig` instance.\n- `context` is the current Context's name.\n- `cluster` is the Cluster's name.\n- `user` is the User's name.\n- `namespace` is the Namespace, defaults to `\"default\"`.\n- `api` is an object containing all known client instances (see below).\n\n### Known API Clients\n\nYou can retrieve a client by its original name from the kubernetes lib.\n\n```javascript\nimport kubernetes from 'fastify-kubernetes'\n\nconst fastify = Fastify()\n\nfastify.register(kubernetes)\n\n// Load plugins (http server not running)\nawait fastify.ready()\n\nconst client0 = fastify.kubernetes.api.CoreV1Api\nconst client1 = fastify.kubernetes.api.BatchV1Api\nconst client2 = fastify.kubernetes.api.BatchV1beta1Api\n```\n\n### Foreign API Clients\n\nYou can also manually creates Api clients.\n\n```javascript \nimport { BatchV1Api } from '@kubernetes/client-node'\nimport kubernetes from 'fastify-kubernetes'\n\nconst fastify = Fastify()\n\nfastify.register(kubernetes)\n\n// Load plugins (http server not running)\nawait fastify.ready()\n\nconst batchApi = fastify.kubernetes.config.makeApiClient(BatchV1Api)\n\nconst cronJobs = await batchApi.listNamespacedCronJob({ namespace: fastify.kubernetes.namespace })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreguz%2Ffastify-kubernetes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreguz%2Ffastify-kubernetes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreguz%2Ffastify-kubernetes/lists"}