世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

问:如何为namespace配置总的cpu和内存配额?
答:
在这里插入图片描述

为namespace配置总的cpu和内存配额(限制单个容器用LimitRange)

创建namespace

  • kubectl create namespace quota-mem-cpu-example

创建ResourceQuota

  • apiVersion: v1
    kind: ResourceQuota
    metadata:
    name: mem-cpu-demo
    spec:
    hard:
    requests.cpu: “1”
    requests.memory: 1Gi
    limits.cpu: “2”
    limits.memory: 2Gi
  • kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-mem-cpu.yaml --namespace=quota-mem-cpu-example
  • kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --output=yaml

创建Pod

  • apiVersion: v1
    kind: Pod
    metadata:
    name: quota-mem-cpu-demo
    spec:
    containers:
    • name: quota-mem-cpu-demo-ctr
      image: nginx
      resources:
      limits:
      memory: “800Mi”
      cpu: “800m”
      requests:
      memory: “600Mi”
      cpu: “400m”
  • kubectl create -f https://k8s.io/docs/tasks/administer-cluster/quota-mem-cpu-pod.yaml --namespace=quota-mem-cpu-example
  • kubectl get pod quota-mem-cpu-demo --namespace=quota-mem-cpu-example
  • kubectl get resourcequota mem-cpu-demo --namespace=quota-mem-cpu-example --output=yaml

删除

  • kubectl delete namespace quota-mem-cpu-example
Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐