将内存资源分配给 运行 个 pod?

assign memory resources to a running pod?

我想知道如何为 运行ning pod 分配内存资源?

我试过了kubectl get po foo-7d7dbb4fcd-82xfr -o yaml > pod.yaml 但是当我 运行 命令 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)

在此先感谢您的帮助。

Pod是最小的kubernetes资源,不支持随意编辑

我建议你使用 deployment 到 运行 你的 pod,因为它是一个“pod 管理器”,你有很多额外的功能,比如 pod self-healing,pod liveness/readness 等...

您可以像这样在部署文件中定义资源:

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

如@KoopaKiller 所述,您无法更新 spec.containers.resources 字段,Container 对象规范中提到了这一点:

Compute Resources required by this container. Cannot be updated.

相反,您可以使用 Deployment 对象部署 Pods。在这种情况下,如果您更改 Pods 的资源配置,部署控制器将推出 Pods.

的更新版本