File tree 2 files changed +52
-0
lines changed
2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,8 @@ specifications:
146
146
* Generate [ badges] ( https://github.com/badges/shields ) showing the
147
147
status of your Deployments. Illustrates using the in-cluster config:
148
148
[ 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 )
149
151
150
152
## Contributing
151
153
Original file line number Diff line number Diff line change
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 ( ) ;
You can’t perform that action at this time.
0 commit comments