Sathya
Sathya

Reputation: 175

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!

Upvotes: 1

Views: 3351

Answers (2)

dose
dose

Reputation: 33

You can use the following command to create a new K3d cluster with a specified memory limit for server containers/nodes:

k3d cluster create newcluster --servers-memory 4G

The --servers-memory flag is used to specify the memory limit for server containers/nodes (unit, e.g., 1g).

You can also use the --agents-memory flag to specify the memory limit for agent containers/nodes (unit, e.g., 1g).

For more details, please refer to the K3d documentation.

Upvotes: 0

Hugo Santos
Hugo Santos

Reputation: 26

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.

Upvotes: 1

Related Questions