Search code examples
kuberneteskubernetes-pod

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 .


Solution

  • 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