美文网首页CKA认证
【K8s 精选】CKA - 如何设置容器的 resources

【K8s 精选】CKA - 如何设置容器的 resources

作者: 熊本极客 | 来源:发表于2022-03-01 11:26 被阅读0次

    1.Pod 设置容器的资源请求和约束

    资源请求设置:spec.containers[].resources.limits.cpuspec.containers[].resources.limits.memoryspec.containers[].resources.limits.hugepages-<size>
    资源约束设置:spec.containers[].resources.requests.cpuspec.containers[].resources.requests.memoryspec.containers[].resources.requests.hugepages-<size>

    apiVersion: v1
    kind: Pod
    metadata:
      name: frontend
    spec:
      containers:
      - name: app
        image: images.my-company.example/app:v4
        resources:
          requests:
            memory: "64Mi"
            cpu: "250m"
          limits:
            memory: "128Mi"
            cpu: "500m"
    

    CPU 资源的单位:以数量为单位,例如,0.1=100m
    内存资源的单位:以 E/Ei、P/Pi、T/Ti、G/Gi、M/Mi、k/Ki 为单位,例如,128M=128Mi

    2.Deployment 设置容器的资源请求和约束

    资源请求设置:spec.template.spec.containers[].resources.limits.cpuspec.template.spec.containers[].resources.limits.memoryspec.template.spec.containers[].resources.limits.hugepages-<size>
    资源约束设置:spec.template.spec.containers[].resources.requests.cpuspec.template.spec.containers[].resources.requests.memoryspec.template.spec.containers[].resources.requests.hugepages-<size>

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nginx-deployment
      labels:
        app: nginx
    spec:
      replicas: 3
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: nginx:1.14.2
            ports:
            - containerPort: 80
            resources:
              requests:
                memory: "128Mi"
                cpu: "500m"
              limits:
                memory: "128Mi"
                cpu: "500m" 
    

    相关文章

      网友评论

        本文标题:【K8s 精选】CKA - 如何设置容器的 resources

        本文链接:https://www.haomeiwen.com/subject/zfudrrtx.html