zyriuse
zyriuse

Reputation: 73

assign memory resources to a running pod?

i would want to know how can i assign memory resources to a running pod ?

i tried kubectl get po foo-7d7dbb4fcd-82xfr -o yaml > pod.yaml but when i run the command kubectl apply -f pod.yaml

 The Pod "foo-7d7dbb4fcd-82xfr" is invalid: spec: Forbidden: pod updates may not change fields other than `spec.containers[*].image`, `spec.initContainers[*].image`, `spec.activeDeadlineSeconds` or `spec.tolerations` (only additions to existing tolerations)

thanks in advance for your help .

Upvotes: 0

Views: 259

Answers (2)

Grigoriy Mikhalkin
Grigoriy Mikhalkin

Reputation: 5573

As @KoopaKiller mentioned, you can't update spec.containers.resources field, this is mentioned in Container object spec:

Compute Resources required by this container. Cannot be updated.

Instead you can deploy your Pods using Deployment object. In that case if you change resources config for your Pods, deployment controller will roll out updated versions of your Pods.

Upvotes: 0

Mr.KoopaKiller
Mr.KoopaKiller

Reputation: 3962

Pod is the minimal kubernetes resources, and it doesn't not support editing as you want to do.

I suggest you to use deployment to run your pod, since it is a "pod manager" where you have a lot of additional features, like pod self-healing, pod liveness/readness etc...

You can define the resources in your deployment file like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: echo
spec:
  replicas: 1
  selector:
    matchLabels:
      app: echo
  template:
    metadata:
      labels:
        app: echo
    spec:
      containers:
      - name: echo
        image: mendhak/http-https-echo
        resources:
          limits:
            cpu: 15m
            memory: 100Mi
          requests:
            cpu: 15m
            memory: 100Mi 
        ports:
        - name: http
          containerPort: 80

Upvotes: 1

Related Questions