k3d

How to increase allocated memory in a k3d cluster


I am on a learning curve with Kubernetes and recently started working with K3D. I am trying to deploy my project on a local K3D cluster. When I created a pod to run an application, I saw it hang in the pending state for some time, and below is the kubectl describe pod output (events). enter image description here application.yaml file's resource requirements are as below

resources:
        requests:
          memory: "4Gi"
          cpu: "2"

The output of kubectl decribe node is as below: I assumed this was due to the fact that my node has around 3 GB of memory and the app is requesting 4 GB. I am getting the error in Pod. I looked for an answer to increase the memory but had no luck so far. enter image description here

How can I increase the memory to get the application up and running? If I reduce the app.yaml resource to --> memory: 3 Gi or 2 Gi, the app starts running, but the actual functionality of the app is not there. Whenever I try to do something in the app, it then gives me Not enough CPU and/or memory is available for error in my application.

I am running this on Linux and k3d version k3d version v5.5.1 k3s version v1.26.4-k3s1 (default) Thanks!


Solution

  • Assuming the machine where you are running has more than 3GB of RAM (you can check by running lsmem or free), you can try re-creating the Kubernetes cluster using k3d, by passing an explicit memory limit. E.g.

    k3d cluster create --agents-memory 8G
    

    Or if you are doing a multi-node deployment, by adding a node with sufficient memory, e.g.

    k3d node create --memory 8G
    

    But when running on Linux, you typically would not have a memory limit applied to the Kubernetes cluster, unless that limit was requested explicitly. So I would suggest checking your previous cluster creation commands, or double-check any scripts you may have used.

    If you are running Linux, another option is to run k3s directly, without k3d. That is unlikely to see limits applied to it as well.

    Finally, an alternative is to use an ephemeral cloud environment for this type of testing. For example, using https://namespace.so you can create a Kubernetes cluster with 8GB of RAM in a few seconds, and use it to test your application.