-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: port missing examples from master to main
This commit ports the remaining examples from the master branch to the main branch. Fixes: #1907
- Loading branch information
Showing
8 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
import { readFileSync } from 'node:fs'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl apply -f namespace.yaml`. | ||
|
||
try { | ||
const namespaceYaml = k8s.loadYaml(readFileSync('./namespace.yaml', 'utf8')); | ||
const createdNamespace = await k8sApi.createNamespace({ body: namespaceYaml }); | ||
console.log('New namespace created:', createdNamespace); | ||
} catch (err) { | ||
console.error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl create namespace test`. | ||
|
||
try { | ||
const namespace = { | ||
metadata: { | ||
name: 'test', | ||
}, | ||
}; | ||
const createdNamespace = await k8sApi.createNamespace({ body: namespace }); | ||
console.log('New namespace created:', createdNamespace); | ||
} catch (err) { | ||
console.error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl get ns`. | ||
|
||
try { | ||
const namespaces = await k8sApi.listNamespace(); | ||
namespaces.items.forEach((namespace) => console.log(namespace.metadata.name)); | ||
} catch (err) { | ||
console.error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl run demo-pod --image=nginx --namespace=default`. | ||
|
||
const pod = { | ||
metadata: { | ||
name: 'demo-pod', | ||
}, | ||
spec: { | ||
containers: [ | ||
{ | ||
name: 'nginx-container', | ||
image: 'nginx', | ||
}, | ||
], | ||
}, | ||
}; | ||
const namespace = 'default'; | ||
|
||
try { | ||
const createdPod = await k8sApi.createNamespacedPod({ | ||
namespace, | ||
body: pod, | ||
}); | ||
console.log('Created pod:', createdPod); | ||
} catch (err) { | ||
console.error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl get pods --namespace=default`. | ||
|
||
try { | ||
const pods = await k8sApi.listNamespacedPod({ namespace: 'default' }); | ||
|
||
pods.items.forEach((pod) => console.log(pod.metadata.name)); | ||
} catch (err) { | ||
console.error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl create resourcequota my-quota --hard=pods=3`. | ||
|
||
try { | ||
const quota = { | ||
metadata: { | ||
name: 'my-quota', | ||
}, | ||
spec: { | ||
hard: { | ||
pods: '3', | ||
}, | ||
}, | ||
}; | ||
const createdQuota = await k8sApi.createNamespacedResourceQuota({ | ||
namespace: 'default', | ||
body: quota, | ||
}); | ||
|
||
console.log('Created quota:', createdQuota); | ||
} catch (err) { | ||
console.error(err); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as k8s from '@kubernetes/client-node'; | ||
|
||
const kc = new k8s.KubeConfig(); | ||
kc.loadFromDefault(); | ||
|
||
const k8sApi = kc.makeApiClient(k8s.CoreV1Api); | ||
|
||
// This code is the JavaScript equivalent of `kubectl get resourcequotas --all-namespaces`. | ||
|
||
try { | ||
const resourceQuotas = await k8sApi.listResourceQuotaForAllNamespaces(); | ||
|
||
resourceQuotas.items.forEach((quota) => console.log(quota.metadata.name)); | ||
} catch (err) { | ||
console.error(err); | ||
} |