1 | # Kubernetes client for Node.JS
|
2 |
|
3 | [![npm version](https://badge.fury.io/js/%40mittwald%2Fkubernetes.svg)](https://www.npmjs.com/package/@mittwald/kubernetes)
|
4 | [![Build Status](https://travis-ci.org/mittwald/node-kubernetes.svg?branch=master)](https://travis-ci.org/mittwald/node-kubernetes)
|
5 |
|
6 | ## Contents
|
7 |
|
8 | - [Installation](#installation)
|
9 | - [Usage](#usage)
|
10 | - [Setup](#setup)
|
11 | - [General usage](#general-usage)
|
12 | - [Rate-limiting API access](#rate-limiting-api-access)
|
13 | - [Watching resources](#watching-resources)
|
14 | - [Accessing CRDs](#accessing-crds)
|
15 | - [Supported resources](#supported-resources)
|
16 | - [References](#references)
|
17 |
|
18 | ## Installation
|
19 |
|
20 | You can install this package via NPM:
|
21 |
|
22 | $ npm install @mittwald/kubernetes
|
23 |
|
24 | ## Usage
|
25 |
|
26 | ### Setup
|
27 |
|
28 | External configuration using a `kubeconfig` file:
|
29 |
|
30 | ```typescript
|
31 | import {FileBasedConfig, KubernetesRESTClient, KubernetesAPI} from "@mittwald/kubernetes";
|
32 |
|
33 | const config = new FileBasedConfig("/home/mhelmich/.kube/config");
|
34 | const client = new KubernetesRESTClient(config);
|
35 | const api = new KubernetesAPI(client);
|
36 | ```
|
37 |
|
38 | Internal configuration (when the client is running within a Kubernetes cluster):
|
39 |
|
40 | ```typescript
|
41 | import {InClusterConfig, KubernetesRESTClient, KubernetesAPI} from "@mittwald/kubernetes";
|
42 |
|
43 | const config = new InClusterConfig();
|
44 | const client = new KubernetesRESTClient(config);
|
45 | const api = new KubernetesAPI(client);
|
46 | ```
|
47 |
|
48 | ### General usage
|
49 |
|
50 | ```typescript
|
51 | api.core().v1().pods.namespace("default").list().then(pods => {
|
52 | console.log("Found " + pods.length + " Pods:");
|
53 |
|
54 | pods.forEach(pod => {
|
55 | console.log(pod.metadata.name);
|
56 | });
|
57 | });
|
58 | ```
|
59 |
|
60 | ### Rate-limiting API access
|
61 |
|
62 | ```typescript
|
63 | import {
|
64 | InClusterConfig,
|
65 | KubernetesRESTClient,
|
66 | RatelimitingKubernetesRESTClient,
|
67 | KubernetesAPI,
|
68 | } from "@mittwald/kubernetes";
|
69 |
|
70 | const config = new InClusterConfig();
|
71 | const client = new KubernetesRESTClient(config);
|
72 | const limitedClient = new RatelimitingKubernetesRESTClient(client);
|
73 | const api = new KubernetesAPI(limitedClient);
|
74 | ```
|
75 |
|
76 | ### Watching resources
|
77 |
|
78 | ```typescript
|
79 | api.core().v1().pods.namespace("default").watch({"some-label": "foo"}, ev => {
|
80 | console.log(`Pod: ${ev.type}: ${ev.object}`);
|
81 | });
|
82 | ```
|
83 |
|
84 | ### Accessing CRDs
|
85 |
|
86 | If you have a package that offers a client for _Custom Resource Definitions_
|
87 | (take a look at the [@mittwald/kubernetes-rook](https://github.com/mittwald/node-kubernetes-rook)
|
88 | package as an example), you can use the `extend` method to add the respective
|
89 | API client:
|
90 |
|
91 | ```typescript
|
92 | import {RookCustomResourceAPI} from "@mittwald/kubernetes-rook";
|
93 |
|
94 | // ...
|
95 | let extendedAPI = api.extend("rook", new RookCustomResourceAPI(client));
|
96 | ```
|
97 |
|
98 | ## Supported resources
|
99 |
|
100 | This library supports a reasonable subset of Kubernetes resources
|
101 | (these were implemented on an as-needed basis). Feel free to open a
|
102 | new issue or pull request to add support for additional API objects.
|
103 |
|
104 | - core/v1
|
105 | - [x] pods
|
106 | - [x] configMaps
|
107 | - [x] endpoints
|
108 | - [x] namespaces
|
109 | - [x] nodes
|
110 | - [x] persistentVolumes
|
111 | - [x] persistentVolumeClaims
|
112 | - [x] services
|
113 | - [x] secrets
|
114 | - [x] serviceAccounts
|
115 | - apps/v1
|
116 | - [x] daemonSets
|
117 | - [x] deployments
|
118 | - [x] replicaSets
|
119 | - [x] statefulSets
|
120 | - apps/v1beta1
|
121 | - [x] deployments
|
122 | - [x] statefulSets
|
123 | - batch/v1
|
124 | - [x] jobs
|
125 | - batch/v1beta1
|
126 | - [x] cronJobs
|
127 | - extensions/v1beta1
|
128 | - [x] daemonSets
|
129 | - [x] ingresses
|
130 | - [x] networkPolicies
|
131 | - [x] replicaSets
|
132 | - rbac/v1
|
133 | - [x] clusterRoles
|
134 | - [x] clusterRoleBindings
|
135 | - [x] roles
|
136 | - [x] roleBindings
|
137 | - autoscaling/v1
|
138 | - [x] horizontalPodAutoscalers
|
139 | - apiextensions.k8s.io/v1beta1
|
140 | - [x] customResourceDefinitions
|
141 | - admissionRegistration.k8s.io/v1
|
142 | - [x] validatingWebhookConfigurations
|
143 | - [ ] mutatingWebhookConfigurations
|
144 |
|
145 | ## References
|
146 |
|
147 | - https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.22/
|
148 | - https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|