5.1.3 Pod 模版资源

PodTemplate 是 Kubernetes API 的常用资源类型,常用于为控制器指定自动创建 Pod 资源对象时所需的配置信息。因为要内嵌于控制器中使用,所以 Pod 模版的配置信息中不需要 apiServer 和 kind 字段,但除此之外的其他内容与定义自主式 Pod 对象所支持的字段几乎完全相同,这包括 metadata 和 spec 及其内嵌的其他各个字段。Pod 控制器类资源的 spec 字段通常都要内嵌 replicas、selector 和 template 字段,其中 template 即为 Pod 模版的定义。下面是一个定义在 ReplicaSet 资源中的模版资源示例:

apiVersion: apps/v1
kind: ReplicaSet
metadata:
  name: rs-example
spec:
  replicas: 2
  selector:
    matchLabels:
      app: rs-demo
  template:
    metadata:
      labels:
        app: rs-demo
    spec:
      containers:
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - name: http
          containerPort: 80

如上示例中,spec.template 字段在定义时仅给出了 metadata 和 spec 两个字段,它的使用方法与自主式 Pod 资源完全相同。后面讲到控制器的章节时会反复用到 Pod 模版资源。

results matching ""

    No results matching ""