配置POD的CPU和内存的限制

指定内存请求和限制
要为容器指定内存请求,请在容器资源清单中包含 resources: requests 字段。 同理,要指定内存限制,请包含 resources: limits。

[root@k8s-master1 service]# cat tomcat-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat
  namespace: app
  labels:
    app: tomcat
spec:
  replicas: 1
  template:
    metadata:
      name: tomcat
      labels:
        app: tomcat
    spec:
      imagePullSecrets:
        - name: registry-pull-secret
      containers:
        - name: tomcat
          image: 192.168.21.121:5000/app/tomcat@sha256:6a1163fd0c216d0baf5020fb63198d8fddfd466c8449f6a9bcc2aa7ab387a9e9
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          resources:                            #限制容器内存的参数
            requests:
              memory: "200Mi"
            limits:
              memory: "200Mi"
      restartPolicy: Always
  selector:
    matchLabels:
      app: tomcat

指定 CPU 请求和 CPU 限制
要为容器指定 CPU 请求,请在容器资源清单中包含 resources: requests 字段。 要指定 CPU 限制,请包含 resources:limits。

apiVersion: apps/v1
kind: Deployment
metadata:
  name: tomcat
  namespace: app
  labels:
    app: tomcat
spec:
  replicas: 1
  template:
    metadata:
      name: tomcat
      labels:
        app: tomcat
    spec:
      imagePullSecrets:
        - name: registry-pull-secret
      containers:
        - name: tomcat
          image: 192.168.21.121:5000/app/tomcat@sha256:6a1163fd0c216d0baf5020fb63198d8fddfd466c8449f6a9bcc2aa7ab387a9e9
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8080
          resources:
            requests:
              memory: "200Mi"
              cpu: "0.1"
            limits:
              memory: "200Mi"
              cpu: "0.1"
      restartPolicy: Always
  selector:
    matchLabels:
      app: tomcat

你可能感兴趣的:(K8S学习,chrome,前端)