How to list, delete k8 satefulsets in node js?

8/16/2019

how to list statefulsets in node js?

I am using @kubernetes/client-node and is it possible to apply a yaml via node app?

node app:

var express = require('express')
var app = express();
const k8s = require('@kubernetes/client-node');

const kc = new k8s.KubeConfig();
kc.loadFromDefault();

const k8sApi = kc.makeApiClient(k8s.CoreV1Api);

app.set('port', (process.env.PORT || 5000))
app.use(express.static(__dirname + '/public'))

app.get('/', function(request, response) {
  response.send('Hello World!')
})

app.get('/pods', function(request, response) {
  k8sApi.listNamespacedPod('default').then(
    (result) => {
      response.send(result.body.items)
    }
  )
})

app.listen(app.get('port'), function() {
  console.log("Node app is running at localhost:" + app.get('port'))
})

referrences: https://github.com/kubernetes-client/javascript https://cloud.google.com/kubernetes-engine/docs/concepts/statefulset

-- Imrahamed
google-kubernetes-engine
kubernetes

1 Answer

8/16/2019

List:

listStatefulSetForAllNamespaces

Delete:

deleteNamespacedStatefulSet

Note: should use AppsV1Api instead of CoreV1Api.

const k8sApi = kc.makeApiClient(k8s.AppsV1Api)
-- FL3SH
Source: StackOverflow