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