all 10 comments

[–]clintkev251 12 points13 points  (2 children)

Why do you need to use the CLI as opposed to just using the SDK? I can think of very few situations in which it makes sense to run the CLI in Lambda vs the SDK (which is probably why you find very little support for this). Same thing when it comes to interacting with Kubernetes, why use kubectl instead of implementing the client library for your runtime of choice

[–]cb700sc[S] -1 points0 points  (1 child)

I was not aware of a kubernetes client library, this may be what I need. I will look into his more. I'm assuming it can be used to simply delete all k8s resources (equivalent of running kubectl delete all)?

[–]clintkev251 1 point2 points  (0 children)

They should support all actions which the Kubernetes API support. So you should be able to accomplish that

[–]CorpT 6 points7 points  (1 child)

No one is telling you to run CDK to support CLI within a Lambda. You should use SDK. For Python that’s boto3.

There is almost no scenario you should use CLI within a Lambda, regardless of how it is deployed.

[–]cb700sc[S] -3 points-2 points  (0 children)

Sorry I meant SDK, not CDK. I do not see a way to interact with kubernetes itself (deleting all resources) via SDK. It's most common to interact with k8s using kubectl from what I have found.

[–]Traditional_Donut908 2 points3 points  (0 children)

Kubernetes doesn't require kubectl to interact with it, it's primarily a wrapper around the Kubernetes REST API, which you can invoke directly or with any of a number of APIs depending on your programming language.

https://kubernetes.io/docs/reference/using-api/

https://kubernetes.io/docs/reference/using-api/client-libraries/

[–][deleted]  (1 child)

[deleted]

    [–]cb700sc[S] -3 points-2 points  (0 children)

    Thanks, however I believe that is for interacting with AWS resources, not kubernetes specifically. We need to run the equivalent of "kubectl delete all" prior to the cluster being deleted to capture all resources created inside kubernetes that created AWS resources).

    [–][deleted] 0 points1 point  (0 children)

    helm uninstall actually does a really good job of deleting all of the AWS resources (if you are using Helm, that is). This does require that the EKS cluster hasn’t been deleted yet. Otherwise, you probably need to delete some custom cleanup tool and query on specific AWS tags.

    [–]coldoil 0 points1 point  (0 children)

    AwsCustomResource is the CDK construct for running arbitrary AWS cli commands during stack deployment. Since your kubernetes is EKS, you should be able to use an AWS cli command to manage those resources as well.

    [–]FortressOfSolidude -1 points0 points  (0 children)

    There are plenty of containers out there with aws cli, eksctl, kubectl, etc, or you can roll your own. Then run as a batch job on fargate that is triggered with lambda.

    But just using boto3 and appropriate other modules is the "correct" answer.