Skip to content

Commit b640e1a

Browse files
tkportersilasbw
authored andcommittedAug 1, 2018
docs(example): example for creating, updating, and rolling back a deployment (#302)
Closes #204
1 parent b55b522 commit b640e1a

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
 

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ specifications:
146146
* Generate [badges](https://github.com/badges/shields) showing the
147147
status of your Deployments. Illustrates using the in-cluster config:
148148
[kubernetes-badges](https://github.com/silasbw/kubernetes-badges)
149+
* Create a deployment, patch a change, and rollback to the original version:
150+
[deployment-create-patch-rollback.js](./examples/deployment-create-patch-rollback.js)
149151

150152
## Contributing
151153

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* eslint no-console:0 */
2+
//
3+
// Create a deployment, patch it, and roll back to the original.
4+
//
5+
const Client = require('kubernetes-client').Client;
6+
const config = require('kubernetes-client').config;
7+
8+
const deploymentManifest = require('./nginx-deployment.json');
9+
10+
async function main() {
11+
try {
12+
const client = new Client({ config: config.fromKubeconfig(), version: '1.10' });
13+
14+
// Create a deployment
15+
const create = await client.apis.apps.v1.ns('default').deploy.post({ body: deploymentManifest });
16+
console.log('Create: ', create);
17+
18+
// Update the deployment
19+
// Change the image from nginx:1.7.9 to nginx:1.9.1
20+
const updateImage = await client.apis.apps.v1.ns('default').deploy('nginx-deployment').patch({
21+
body: {
22+
spec: {
23+
template: {
24+
spec: {
25+
containers: [{
26+
name: 'nginx',
27+
image: 'nginx:1.9.1'
28+
}]
29+
}
30+
}
31+
}
32+
}
33+
});
34+
console.log('Update: ', updateImage);
35+
36+
// Rollback to nginx:1.7.9
37+
const rollback = await client.apis.apps.v1beta1.namespaces('default').deployments('nginx-deployment').rollback.post({
38+
body: {
39+
kind: 'DeploymentRollback',
40+
apiVersion: 'apps/v1beta1',
41+
name: 'nginx-deployment'
42+
}
43+
});
44+
console.log('Rollback: ', rollback);
45+
} catch (err) {
46+
console.error('Error: ', err);
47+
}
48+
}
49+
50+
main();

0 commit comments

Comments
 (0)
Please sign in to comment.