使用复制副本和资源进行部署,而不在Azure中部署特定资源

s4n0splo  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(120)

我尝试在Azure中添加带有副本的部署。我添加了资源,但它总是占用4 CPU和15Gi内存。下面是部署的yml。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  namespace: test-cf-ns
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-cf
  template:
    metadata:
      labels:
        app: test-cf
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
      - image: adobecoldfusion/coldfusion2021:latest
        name: test-cf
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 2
            memory: 8Gi
          requests:
            cpu: 2
            memory: 8Gi

字符串

zbdgwd5y

zbdgwd5y1#

您提供的配置将CPU和内存的请求和限制设置为相同的值,这意味着您部署中的每个pod都分配了固定数量的资源,即(2个CPU和8 Gi内存)。但是,部署的总资源(即每个pod的副本)将是6个CPU和24 Gi内存,不是你提到的4个CPU和15 Gi内存。如果你想限制每个pod最多使用2个CPU和8 Gi内存,

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  namespace: test-cf-ns
spec:
  replicas: 3
  selector:
    matchLabels:
      app: test-cf
  template:
    metadata:
      labels:
        app: test-cf
    spec:
      nodeSelector:
        kubernetes.io/os: linux
      containers:
      - image: adobecoldfusion/coldfusion2021:latest
        name: test-cf
        imagePullPolicy: Always
        resources:
          limits:
            cpu: 2
            memory: 8Gi
          requests:
            cpu: 0.5
            memory: 2Gi

字符串
x1c 0d1x的数据
使用以上的yaml配置,每个pod保证至少获得0.5个CPU和2Gi内存请求,但可以使用多达2个CPU和8 Gi内存限制(如果可用)。
当你这么做的时候

kubectl get deploy test -n test-cf-ns -o yaml


您将看到,基于指定的限制,它应该只接受这些限制,如您在下面的输出中所看到的-

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"apps/v1","kind":"Deployment","metadata":{"annotations":{},"name":"test","namespace":"test-cf-ns"},"spec":{"replicas":3,"selector":{"matchLabels":{"app":"test-cf"}},"template":{"metadata":{"labels":{"app":"test-cf"}},"spec":{"containers":[{"image":"adobecoldfusion/coldfusion2021:latest","imagePullPolicy":"Always","name":"test-cf","resources":{"limits":{"cpu":2,"memory":"8Gi"},"requests":{"cpu":0.5,"memory":"2Gi"}}}],"nodeSelector":{"kubernetes.io/os":"linux"}}}}}
  creationTimestamp: "2023-11-16T09:38:49Z"
  generation: 1
  name: test
  namespace: test-cf-ns
  resourceVersion: "52482"
  uid: 02a33b76-ce21-4132-aec3-8b161db8ea51
spec:
  progressDeadlineSeconds: 600
  replicas: 3
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: test-cf
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: test-cf
    spec:
      containers:
      - image: adobecoldfusion/coldfusion2021:latest
        imagePullPolicy: Always
        name: test-cf
        resources:
          limits:
            cpu: "2"
            memory: 8Gi
          requests:
            cpu: 500m
            memory: 2Gi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      nodeSelector:
        kubernetes.io/os: linux
      restartPolicy: Always
      schedulerName: default-scheduler

相关问题