Skip to content

Commit 5bc015e

Browse files
committed
readme
1 parent c467853 commit 5bc015e

File tree

2 files changed

+190
-6
lines changed

2 files changed

+190
-6
lines changed

README.md

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
</a>
1414
</p>
1515

16+
KubernetesJS is a **fully-typed**, zero-dependency TypeScript client for Kubernetes.
1617

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+
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.
1821
1922
## Features
2023

@@ -34,9 +37,94 @@ yarn add kubernetesjs
3437

3538
```
3639

37-
## Example
40+
## Your Infrastructure, Like a Component
41+
42+
This is what we mean by "*React for infrastructure*":
3843

39-
```js
44+
```ts
45+
import { KubernetesClient } from "kubernetesjs";
46+
47+
const client = new KubernetesClient({
48+
restEndpoint: process.env.KUBERNETES_API_URL || 'http://127.0.0.1:8001'
49+
});
50+
51+
await client.createAppsV1NamespacedDeployment({
52+
path: { namespace: 'default' },
53+
body: {
54+
apiVersion: 'apps/v1',
55+
kind: 'Deployment',
56+
metadata: { name: 'hello-world' },
57+
spec: {
58+
replicas: 1,
59+
selector: { matchLabels: { app: 'hello-world' } },
60+
template: {
61+
metadata: { labels: { app: 'hello-world' } },
62+
spec: {
63+
containers: [
64+
{
65+
name: 'app',
66+
image: 'node:18-alpine',
67+
command: ['node', '-e', 'require("http").createServer((_,res)=>res.end("ok")).listen(3000)'],
68+
ports: [{ containerPort: 3000 }]
69+
}
70+
]
71+
}
72+
}
73+
}
74+
}
75+
});
76+
```
77+
78+
## Test Your Cluster Like You Test Code
79+
80+
Run infrastructure as part of your test suite, with assertions.
81+
82+
```ts
83+
describe('PostgreSQL Deployment', () => {
84+
const namespace = 'default';
85+
const deploymentName = 'postgres-pgvector';
86+
87+
it('creates a PostgreSQL deployment + service', async () => {
88+
const deployment = await client.createAppsV1NamespacedDeployment({ ... });
89+
const service = await client.createCoreV1NamespacedService({ ... });
90+
91+
expect(deployment.metadata?.name).toBe(deploymentName);
92+
expect(service.metadata?.name).toBe(deploymentName);
93+
94+
const status = await client.readAppsV1NamespacedDeployment({
95+
path: { namespace, name: deploymentName }
96+
});
97+
98+
expect(status.status?.readyReplicas).toBe(1);
99+
});
100+
});
101+
```
102+
103+
> Type-safe Kubernetes. With `expect()`.
104+
105+
---
106+
107+
## Declarative Loops, Composability, Reuse
108+
109+
You can now treat infrastructure like reusable components or functions:
110+
111+
```ts
112+
function createPostgresDeployment(name: string) {
113+
return client.createAppsV1NamespacedDeployment({
114+
path: { namespace: 'default' },
115+
body: {
116+
apiVersion: 'apps/v1',
117+
kind: 'Deployment',
118+
metadata: { name },
119+
spec: { /* ... */ }
120+
}
121+
});
122+
}
123+
```
124+
125+
## Example: Inspect Init Containers in Running Pods
126+
127+
```ts
40128
import { KubernetesClient } from "kubernetesjs";
41129

42130
const client = new KubernetesClient({
@@ -71,6 +159,10 @@ if (result.items && result.items.length) {
71159
}
72160
```
73161

162+
> With KubernetesJS, you don’t shell out to `kubectl`, grep logs, or decode YAML trees. You write real code—typed, composable, inspectable.
163+
164+
This example lists all pods in the `default` namespace and cleanly inspects both regular and init containers, including their readiness and state.
165+
74166
## Related
75167

76168
Checkout these related projects:

packages/kubernetesjs/README.md

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@
1313
</a>
1414
</p>
1515

16+
KubernetesJS is a **fully-typed**, zero-dependency TypeScript client for Kubernetes.
1617

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+
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.
1821
1922
## Features
2023

@@ -34,9 +37,94 @@ yarn add kubernetesjs
3437

3538
```
3639

37-
## Example
40+
## Your Infrastructure, Like a Component
41+
42+
This is what we mean by "*React for infrastructure*":
3843

39-
```js
44+
```ts
45+
import { KubernetesClient } from "kubernetesjs";
46+
47+
const client = new KubernetesClient({
48+
restEndpoint: process.env.KUBERNETES_API_URL || 'http://127.0.0.1:8001'
49+
});
50+
51+
await client.createAppsV1NamespacedDeployment({
52+
path: { namespace: 'default' },
53+
body: {
54+
apiVersion: 'apps/v1',
55+
kind: 'Deployment',
56+
metadata: { name: 'hello-world' },
57+
spec: {
58+
replicas: 1,
59+
selector: { matchLabels: { app: 'hello-world' } },
60+
template: {
61+
metadata: { labels: { app: 'hello-world' } },
62+
spec: {
63+
containers: [
64+
{
65+
name: 'app',
66+
image: 'node:18-alpine',
67+
command: ['node', '-e', 'require("http").createServer((_,res)=>res.end("ok")).listen(3000)'],
68+
ports: [{ containerPort: 3000 }]
69+
}
70+
]
71+
}
72+
}
73+
}
74+
}
75+
});
76+
```
77+
78+
## Test Your Cluster Like You Test Code
79+
80+
Run infrastructure as part of your test suite, with assertions.
81+
82+
```ts
83+
describe('PostgreSQL Deployment', () => {
84+
const namespace = 'default';
85+
const deploymentName = 'postgres-pgvector';
86+
87+
it('creates a PostgreSQL deployment + service', async () => {
88+
const deployment = await client.createAppsV1NamespacedDeployment({ ... });
89+
const service = await client.createCoreV1NamespacedService({ ... });
90+
91+
expect(deployment.metadata?.name).toBe(deploymentName);
92+
expect(service.metadata?.name).toBe(deploymentName);
93+
94+
const status = await client.readAppsV1NamespacedDeployment({
95+
path: { namespace, name: deploymentName }
96+
});
97+
98+
expect(status.status?.readyReplicas).toBe(1);
99+
});
100+
});
101+
```
102+
103+
> Type-safe Kubernetes. With `expect()`.
104+
105+
---
106+
107+
## Declarative Loops, Composability, Reuse
108+
109+
You can now treat infrastructure like reusable components or functions:
110+
111+
```ts
112+
function createPostgresDeployment(name: string) {
113+
return client.createAppsV1NamespacedDeployment({
114+
path: { namespace: 'default' },
115+
body: {
116+
apiVersion: 'apps/v1',
117+
kind: 'Deployment',
118+
metadata: { name },
119+
spec: { /* ... */ }
120+
}
121+
});
122+
}
123+
```
124+
125+
## Example: Inspect Init Containers in Running Pods
126+
127+
```ts
40128
import { KubernetesClient } from "kubernetesjs";
41129

42130
const client = new KubernetesClient({
@@ -71,6 +159,10 @@ if (result.items && result.items.length) {
71159
}
72160
```
73161

162+
> With KubernetesJS, you don’t shell out to `kubectl`, grep logs, or decode YAML trees. You write real code—typed, composable, inspectable.
163+
164+
This example lists all pods in the `default` namespace and cleanly inspects both regular and init containers, including their readiness and state.
165+
74166
## Related
75167

76168
Checkout these related projects:

0 commit comments

Comments
 (0)