javascript
javascript copied to clipboard
Document how to do equivalent of `kubectl apply -f {filename}` using this client
The documentation is not clear (to me) as to how the equivalent of the kubectl apply -f {filename}
might be achieved using this client.
eg: use this to create/update a Deployment.
So, how is it done?
FYI: I have done some digging through some of the issues in connection with this, which lead me to the 'patch' commands with the 'force' set to 'true', (confirmation (or not) that this is indeed equivalent would be good), and that the 'options' needs to provide an override to the default 'content-type' value.
But, I have yet to see a clear definition of the 'body' that is supposed to be passed, as, the object model simply lists this as an 'object', which, could be anything at all, but, realistically, when I pass the same object as used to createNamespacedDeployment()
with success, it fails miserably when used with patchNamespacedDeployment()
, with an error message indicating that the body was unable to be processed.
By the way, if it makes a difference, I'm using TypeScript.
Thank you in advance! :)
kubectl apply
is actually a pretty complicated command. I don't think that this library will support it until we regenerate for 1.16 and we include server side apply
The Go code for apply
is here:
https://github.com/kubernetes/kubectl/tree/master/pkg/apply
If you want to try to emulate it with this library (but honestly waiting for Server-Side apply is a better idea...)
Thank you for the information! I like the idea of using the server side apply
functionality via the client.
Do we have any idea as to when this will be available?
We need to regenerate for the Kubernetes 1.16 API an then see if it works :)
I'd guess sometime in the next month or so.
This is exactly what I want to do with this lib -- kick off jobs. apply
is the right way to do that, correct? I'd appreciate any news on this.
(As well as the authentication issue #295, loading auth data, which I guess is closed, though I'd still like some help with using Google Kubernetes Engine -- happy to open a new issue if that's preferred here.)
Any update on when the API may be regenerated for 1.16/1.17?
I'll try to get to it this week.
@brendanburns sorry to bug you, have you got an ETA at all? If you're swamped, I can try and do the PR myself (if you could lend a little guidance that would be awesome).
@garyo I haven't used it myself yet, but can't you already create jobs using the following code ?
import k8s from '@kubernetes/client-node';
const kc = new k8s.KubeConfig();
kc.loadFromDefault();
const k8sApi = kc.makeApiClient(k8s.BatchV1Api);
k8sApi.createNamespacedJob(....)
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
/remove-lifecycle stale
/lifecycle frozen
A bit late but are you looking for this example here? https://github.com/kubernetes-client/javascript/blob/master/examples/typescript/apply/apply-example.ts
Just create a yml file with your resource and apply it.
@soerenbrockmann, how do I resolve the error on line# 16 saying 'Property 'KubernetesObjectApi' does not exist on type 'typeof ' @kubernetes/client-node
It does seem that the types are broken for this apply-example.ts
I get the following for line 19: const specs: k8s.KubernetesObject[] = yaml.loadAll(specString);
Type 'unknown[]' is not assignable to type 'KubernetesObject[]'.
Type 'unknown' is not assignable to type 'KubernetesObject'.ts
and the following error for line 32: await client.read(spec);
Argument of type 'KubernetesObject' is not assignable to parameter of type 'KubernetesObjectHeader<KubernetesObject>'.
Type 'KubernetesObject' is not assignable to type '{ metadata: { name: string; namespace: string; }; }'.
Types of property 'metadata' are incompatible.
Type 'V1ObjectMeta | undefined' is not assignable to type '{ name: string; namespace: string; }'.
Type 'undefined' is not assignable to type '{ name: string; namespace: string; }'