如何在单个openshift yaml模板中具有多种对象类型? [英] How to have multiple object types in a single openshift yaml template?

查看:82
本文介绍了如何在单个openshift yaml模板中具有多种对象类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是名称为Claim1的单个PersistentVolumeClaim的示例模板

Here is the sample template for single PersistentVolumeClaim with name : claim1

apiVersion: "v1"
kind: "PersistentVolumeClaim"
metadata:
  name: "claim1"
spec:
  accessModes:
    - "ReadWriteOnce"
  resources:
    requests:
      storage: "5Gi"
  volumeName: "pv0001"

如何在同一模板文件中添加多个PersistentVolumeClaim. 例如添加claim2

How can i add multiple PersistentVolumeClaim in the same template file. For example adding claim2

我尝试从其下方复制粘贴相同的模板,然后将Claim1更改为Claim2,但是在导入模板的openshift UI中,它会发出警告:重复的映射键类型:PersistentVolumeClaim

I tried copy paste the same template from below it and change claim1 to claim2 but in openshift UI while importing the template it gives a warning : Duplicated Mapping key kind: PersistentVolumeClaim

更新: 我已经尝试使用注释中提到的---.但这会在导入yaml时在openshift UI中引发错误Expected a single document in the stream but found more

Update: I have tried using --- as mentioned in the comments. But that throws a error Expected a single document in the stream but found more in the openshift UI while importing the yaml

推荐答案

我建议编写一个 actual 模板:

I would recommend writing an actual template: https://docs.okd.io/latest/dev_guide/templates.html#writing-templates

具体来说,它看起来像:

Specifically it would look something like:

apiVersion: v1
kind: Template
metadata:
  name: multiple-pvcs
objects:
- apiVersion: "v1"
  kind: "PersistentVolumeClaim"
  metadata:
    name: "claim1"
  spec:
    accessModes:
      - "ReadWriteOnce"
    resources:
      requests:
        storage: "5Gi"
    volumeName: "pv0001"
- apiVersion: "v1"
  kind: "PersistentVolumeClaim"
  metadata:
    name: "claim2"
  spec:
    accessModes:
      - "ReadWriteOnce"
    resources:
      requests:
        storage: "5Gi"
    volumeName: "pv0002"
parameters: []

然后您可以使用oc process template.yml | oc create -f -

这篇关于如何在单个openshift yaml模板中具有多种对象类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆