kubernetesjs 0.7.1 → 0.7.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -4
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -13,8 +13,12 @@
|
|
|
13
13
|
</a>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
|
+
KubernetesJS is a **fully-typed**, zero-dependency TypeScript client for Kubernetes.
|
|
17
|
+
|
|
18
|
+
Write infrastructure like you write apps—modular, composable, and testable. KubernetesJS gives you direct, programmatic access to the entire Kubernetes API, with the developer experience of modern JavaScript tooling.
|
|
19
|
+
|
|
20
|
+
> No more brittle YAML. No more hidden chart logic. Just pure, type-safe Kubernetes from the language you already use.
|
|
16
21
|
|
|
17
|
-
KubernetesJS is a **fully-typed**, zero-dependency TypeScript library designed to simplify interactions with Kubernetes APIs. With comprehensive TypeScript support, it provides a strongly-typed interface that makes managing Kubernetes resources clear and predictable, ideal for TypeScript developers looking to integrate Kubernetes management into their applications.
|
|
18
22
|
|
|
19
23
|
## Features
|
|
20
24
|
|
|
@@ -23,6 +27,8 @@ KubernetesJS is a **fully-typed**, zero-dependency TypeScript library designed t
|
|
|
23
27
|
- **📡 Full Kubernetes API Coverage**: Supports all Kubernetes API endpoints with detailed TypeScript types.
|
|
24
28
|
- **🌐 Cross-Platform**: Works with both Node.js and browser environments.
|
|
25
29
|
|
|
30
|
+
With KubernetesJS, you don’t shell out to `kubectl`, grep logs, or decode YAML trees. You write real code—typed, composable, inspectable.
|
|
31
|
+
|
|
26
32
|
## Installation
|
|
27
33
|
|
|
28
34
|
To install KubernetesJS, you can use npm or yarn:
|
|
@@ -34,9 +40,94 @@ yarn add kubernetesjs
|
|
|
34
40
|
|
|
35
41
|
```
|
|
36
42
|
|
|
37
|
-
##
|
|
43
|
+
## Your Infrastructure, Like a Component
|
|
44
|
+
|
|
45
|
+
This is what we mean by "*React for infrastructure*":
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
import { KubernetesClient } from "kubernetesjs";
|
|
49
|
+
|
|
50
|
+
const client = new KubernetesClient({
|
|
51
|
+
restEndpoint: process.env.KUBERNETES_API_URL || 'http://127.0.0.1:8001'
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await client.createAppsV1NamespacedDeployment({
|
|
55
|
+
path: { namespace: 'default' },
|
|
56
|
+
body: {
|
|
57
|
+
apiVersion: 'apps/v1',
|
|
58
|
+
kind: 'Deployment',
|
|
59
|
+
metadata: { name: 'hello-world' },
|
|
60
|
+
spec: {
|
|
61
|
+
replicas: 1,
|
|
62
|
+
selector: { matchLabels: { app: 'hello-world' } },
|
|
63
|
+
template: {
|
|
64
|
+
metadata: { labels: { app: 'hello-world' } },
|
|
65
|
+
spec: {
|
|
66
|
+
containers: [
|
|
67
|
+
{
|
|
68
|
+
name: 'app',
|
|
69
|
+
image: 'node:18-alpine',
|
|
70
|
+
command: ['node', '-e', 'require("http").createServer((_,res)=>res.end("ok")).listen(3000)'],
|
|
71
|
+
ports: [{ containerPort: 3000 }]
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Test Your Cluster Like You Test Code
|
|
82
|
+
|
|
83
|
+
Run infrastructure as part of your test suite, with assertions.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
describe('PostgreSQL Deployment', () => {
|
|
87
|
+
const namespace = 'default';
|
|
88
|
+
const deploymentName = 'postgres-pgvector';
|
|
89
|
+
|
|
90
|
+
it('creates a PostgreSQL deployment + service', async () => {
|
|
91
|
+
const deployment = await client.createAppsV1NamespacedDeployment({ ... });
|
|
92
|
+
const service = await client.createCoreV1NamespacedService({ ... });
|
|
93
|
+
|
|
94
|
+
expect(deployment.metadata?.name).toBe(deploymentName);
|
|
95
|
+
expect(service.metadata?.name).toBe(deploymentName);
|
|
96
|
+
|
|
97
|
+
const status = await client.readAppsV1NamespacedDeployment({
|
|
98
|
+
path: { namespace, name: deploymentName }
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(status.status?.readyReplicas).toBe(1);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> Type-safe Kubernetes. With `expect()`.
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Declarative Loops, Composability, Reuse
|
|
111
|
+
|
|
112
|
+
You can now treat infrastructure like reusable components or functions:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
function createPostgresDeployment(name: string) {
|
|
116
|
+
return client.createAppsV1NamespacedDeployment({
|
|
117
|
+
path: { namespace: 'default' },
|
|
118
|
+
body: {
|
|
119
|
+
apiVersion: 'apps/v1',
|
|
120
|
+
kind: 'Deployment',
|
|
121
|
+
metadata: { name },
|
|
122
|
+
spec: { /* ... */ }
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Example: Inspect Init Containers in Running Pods
|
|
38
129
|
|
|
39
|
-
```
|
|
130
|
+
```ts
|
|
40
131
|
import { KubernetesClient } from "kubernetesjs";
|
|
41
132
|
|
|
42
133
|
const client = new KubernetesClient({
|
|
@@ -71,6 +162,14 @@ if (result.items && result.items.length) {
|
|
|
71
162
|
}
|
|
72
163
|
```
|
|
73
164
|
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
Start the Kubernetes API proxy to allow local access:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
kubectl proxy --port=8001 --accept-hosts='^.*$' --address='0.0.0.0'
|
|
171
|
+
```
|
|
172
|
+
|
|
74
173
|
## Related
|
|
75
174
|
|
|
76
175
|
Checkout these related projects:
|
|
@@ -85,7 +184,7 @@ Checkout these related projects:
|
|
|
85
184
|
|
|
86
185
|
## Credits
|
|
87
186
|
|
|
88
|
-
🛠 Built by
|
|
187
|
+
🛠 Built by [Interweb](https://interweb.co) — if you like our tools, please checkout and contribute [https://interweb.co](https://interweb.co)
|
|
89
188
|
|
|
90
189
|
## Disclaimer
|
|
91
190
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kubernetesjs",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "Fully Typed Kubernetes",
|
|
6
6
|
"keywords": [
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"schema-sdk": "^0.12.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "268ff7d5272ef5abc02b3529829cca6cd7031428"
|
|
56
56
|
}
|