How to get a list of all services available on cluster?

6/13/2019

Trying to use kubernetes-client and it works fine if I want to get a list of PODs. But how do I get a list of services, i.e.:

kubectl get services

I could not find any appropriate method in kubernetes-client:

const Client = require('kubernetes-client').Client;
const Config = require('kubernetes-client/backends/request').config;

const client = new K8sClient({ config: Config.fromKubeconfig(), version: '1.13' });

const pods = await client.api.v1.namespaces('xxxxx').pods.get({ qs: { labelSelector: 'application=test' } });
console.log('Pods: ', JSON.stringify(pods));
-- John Glabb
kubernetes
node.js

1 Answer

6/13/2019

From the godaddy/kubernetes-client Libraries.

There seems to be:

api.v1.namespaces(namespace).services.get

list or watch objects of kind Service

Which looks the same as:

api.v1.namespaces(namespace).pods.get

list or watch objects of kind Pod

-- Crou
Source: StackOverflow