Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will this sdk work with Azure Kubernetes #389

Closed
focode opened this issue Jan 9, 2020 · 5 comments
Closed

Will this sdk work with Azure Kubernetes #389

focode opened this issue Jan 9, 2020 · 5 comments

Comments

@focode
Copy link

focode commented Jan 9, 2020

I am following this link: https://github.com/kubernetes-client/javascript
and trying to list pods in the given namespace with azure kubernetes, here the code that I am referring:
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.CoreV1Api);
k8sApi.listNamespacedPod('abc').then((res) => {
console.log(res.body);
});
I have successfully logged in to Kubernetes console, In the console, I am able to do the normal operation, but when I am running this code I am getting below error:

(node:30816) UnhandledPromiseRejectionWarning: Error: Token is expired!
at CloudAuth.updateAccessToken (D:\project\IOT-KT\dl\node_modules@kubernetes\client-node\dist\cloud_auth.js:46:19)
at CloudAuth.getToken (D:\project\IOT-KT\dl\node_modules@kubernetes\client-node\dist\cloud_auth.js:24:18)
at CloudAuth. (D:\project\IOT-KT\dl\node_modules@kubernetes\client-node\dist\cloud_auth.js:15:32)
at Generator.next ()
at D:\project\IOT-KT\dl\node_modules\tslib\tslib.js:110:75
at new Promise ()
at Object.__awaiter (D:\project\IOT-KT\dl\node_modules\tslib\tslib.js:106:16)
at CloudAuth.applyAuthentication (D:\project\IOT-KT\dl\node_modules@kubernetes\client-node\dist\cloud_auth.js:14:24)
at KubeConfig. (D:\project\IOT-KT\dl\node_modules@kubernetes\client-node\dist\config.js:299:37)
at Generator.next ()
(node:30816) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:30816) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My Config file looks like this:

apiVersion: v1
clusters:

  • cluster:
    certificate-authority-data: LS0tLS1C..................Cg==
    server: https://.azmk8s.io:443
    name: removed>
    contexts:
  • context:
    cluster: removed>
    user: removed>
    name: removed>
    current-context: removed>
    kind: Config
    preferences: {}
    users:
  • name: removed>
    user:
    auth-provider:
    config:
    apiserver-id: removed>
    client-id: removed>
    environment: removed>
    tenant-id: removed>
    name: azure
@brendandburns
Copy link
Contributor

This definitely does work with Azure Kubernetes (I test it with AKS, myself) however, it doesn't currently refresh your token if it is expired if there isn't a cmd present:

https://github.com/kubernetes-client/javascript/blob/master/src/cloud_auth.ts#L62

A quick way to validate is to run kubectl version which will refresh the token in your kubeconfig file.

If that works, one option is to add:

user:
   ...
   cmd-path: kubectl
   cmd-args: version

To your kubeconfig.

We should definitely add better support for refreshing tokens to the client SDK.

@focode
Copy link
Author

focode commented Jan 10, 2020

Just running kubectl version command, my program gave output and not the error

@brendandburns
Copy link
Contributor

right and now your token should be updated and the Javascript client code should work.

@focode
Copy link
Author

focode commented Jan 11, 2020

Yes It is working now, Thanks @brendandburns

@brendandburns
Copy link
Contributor

Closing this in favor of the more general #399

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants