k8s基本字段

k8s基本字段

apiVersion

apiVersion:v1,k8s以常见核心对象都属于v1核心API。常见的pod,service等都属于核心API;
apiVersion: apps/v1,表示扩展资源如deployment,statefulSet,daemonSet

limits字段

此字段限制的是硬件的资源,如果容器尝试申请超过限制的内存将会终止容器

requests字段

此字段限制的是容器最小资源申请量,不能超过limits, 500m等于0.5个CPU

img

本地临时性文件,采用这种配置时,你会把所有类型的临时性本地数据(包括 emptyDir 卷、可写入容器层、容器镜像、日志等)放到同一个文件系统中。 作为最有效的 kubelet 配置方式,这意味着该文件系统是专门提供给 Kubernetes (kubelet)来保存数据的。目录为/var/lib/kubelet,可以在pod的

ephemeral-storage临时性存储字段

管理临时存储如/var/lib/kubelet大小
spec.containers[].resources.limits.ephemeral-storage
spec.containers[].resources.requests.ephemeral-storage

img

img

钩子

lifecycle生命周期管理

k8s支持设置lifecycle字段来控制pod的生命周期,preStop是一个钩子,会在容器终止之前被调用。

prelock钩子可以用来容器优雅退出

lifecycle:
  preStop:
    exec:
      command: ["/bin/sh", "-c", "for i in $(pgrep -p 1); do kill -9 $i; done"]

InitContainers

初始化容器用来在主容器启动之前执行任务,完成之后才会启动主容器

Containers:
-name: xxx
 image: xxx
image
initContainers:
- name: init-container
  image: busybox
  command: ['sh', '-c', 'echo "Initializing..." && sleep 5']

probe

探针,用来监控容器健康状态和就绪状态,livenessProbe存活探针判断是否运行,readinessProbe就绪探针判断是否准备好接受流量

containers:
- name: my-container
  image: my-image
  livenessProbe:
    httpGet:
      path: /healthz
      port: 8080
    initialDelaySeconds: 5
    periodSeconds: 10
  readinessProbe:
    httpGet:
      path: /ready
      port: 8080
    initialDelaySeconds: 3
    periodSeconds: 5
posted @ 2025-03-22 01:13  LemHou  阅读(6)  评论(0)    收藏  举报