简体   繁体   English

在Kubernetes容器中为容器分配资源

[英]Resource allocation to container in Kubernetes pods

Consider the below .yaml file : 考虑以下.yaml文件:

application/guestbook/redis-slave-deployment.yaml  
apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: redis-slave
  labels:
    app: redis
spec:
  selector:
    matchLabels:
      app: redis
      role: slave
      tier: backend
  replicas: 2
  template:
    metadata:
      labels:
        app: redis
        role: slave
        tier: backend
    spec:
      containers:
      - name: slave
        image: gcr.io/google_samples/gb-redisslave:v1
        resources:
          requests:
            cpu: 100m
            memory: 100Mi
        env:
        - name: GET_HOSTS_FROM
          value: dns

        ports:
        - containerPort: 6379

The resource section isn't clear to me! 资源部分对我来说不清楚! If I have 16G RAM and 4core CPU, each core 2GHz, then how much are the requested resources which come above? 如果我有16G RAM和4core CPU(每个核心2GHz),那么上面请求的资源有多少?

So you have a total of 4 CPU cores and 16GB RAM. 因此,您总共有4个CPU内核和16GB RAM。 This Deployment will start two Pods (replicas) and each will start with 0.1 cores and 0.1GB reserved on the Node on which it starts. 此部署将启动两个Pod(副本),每个Pod将以其启动的节点上的0.1核和0.1GB预留空间启动。 So in total 0.2 cores and 0.2GB will be reserved, leaving up to 15.8GB and 3.8cores. 因此,总共将保留0.2个内核和0.2GB,剩下的15.8GB和3.8个内核。 However the actual usage may exceed the reservation as this is only a the requested amount. 但是,实际使用量可能会超出预留量,因为这只是请求的数量。 To specify an upper limit you use a limits section. 要指定上限,请使用“限制”部分。

It can be counter-intuitive that CPU allocation is based on cores rather than GHz - there's a fuller explanation in the GCP docs and more on the arithmetic in the official kubernetes docs CPU分配基于内核而不是GHz 是不合常理 的-GCP文档中更全面的解释 ,而官方kubernetes文档中有更多的算法说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM