kubernetes-client
kubernetes-client copied to clipboard
Pod exec unhandled error
We are trying to eventually mimic the functionality of kubectl cp through an exec.post() with your API. For now though we're just trying to get a dummy ls command to run in the pod. This is the code we are using to do that:
const res = await this.client.api.v1.namespaces(this.configService.namespace).pods('pod_name').exec.post({ qs: { command: ['ls'], container: 'runtime', stdout: true, stderr: true } }); console.log(res.body);
However, the node program just exits abruptly at that call with this error:
C:\projects\repos\pw-sessions-service\node_modules\kubernetes-client\backends\request\client.js:70 authorization: Bearer ${options.auth.bearer} ^ TypeError: Cannot read property 'bearer' of undefined at upgradeRequest (C:\projects\repos\pw-sessions-service\node_modules\kubernetes-client\backends\request\client.js:70:43) at Request._callback (C:\projects\repos\pw-sessions-service\node_modules\kubernetes-client\backends\request\client.js:151:16) at Request.self.callback (C:\projects\repos\pw-sessions-service\node_modules\request\request.js:185:22) at Request.emit (events.js:210:5) at Request.EventEmitter.emit (domain.js:476:20) at Request.<anonymous> (C:\projects\repos\pw-sessions-service\node_modules\request\request.js:1161:10) at Request.emit (events.js:210:5) at Request.EventEmitter.emit (domain.js:476:20) at IncomingMessage.<anonymous> (C:\projects\repos\pw-sessions-service\node_modules\request\request.js:1083:12) at Object.onceWrapper (events.js:299:28)
We've tried manually adding a bearer token to that request, but that returned an error from the server. Are there any tips that could help?

https://github.com/godaddy/kubernetes-client/blob/master/backends/request/client.js 68
I got the same issue and debugged the code. here is how I got rid of the exceptions
Get the Bearer token kubectl get secrets -o jsonpath="{}" look for "token", for your kubectl user , then add it to your ~/.kube/config something similar to below
apiVersion: v1
clusters:
- cluster:
certificate-authority-data: <my_cert>
server: <my_server>
name: kubernetes
contexts:
- context:
cluster: kubernetes
user: kubernetes-admin
name: kubernetes-admin@kubernetes
current-context: kubernetes-admin@kubernetes
kind: Config
preferences: {}
users:
- name: kubernetes-admin
user:
token: <add your token here> //<----- here to fix the issue
client-certificate-data: <my_client_cert>
client-key-data: <my_client_key>
construct the client as below
const { Client, KubeConfig } = require('kubernetes-client');
client = new Client({ version: '1.13' })