应用新yaml时如何传递参数文件
How to pass param file when applying a new yaml
我正在使用 openshift 4.6。我想将参数传递给 yaml 文件,所以我尝试了下面的代码,但它抛出了一个错误
oc apply -f "./ETCD Backup/etcd_backup_cronjob.yaml" --param master-node = oc get nodes -o name | grep "master-0" | cut -d'/' -f2
错误:未知标志 --param
您最想使用的是 OpenShift Templates。使用模板,您可以在 YAML 文件中包含变量,然后使用 oc process
.
更改它们
因此您的 YAML 将如下所示:
kind: Template
apiVersion: v1
metadata:
name: my-template
objects:
- apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: pi
spec:
schedule: "*/1 * * * *"
concurrencyPolicy: "Replace"
startingDeadlineSeconds: 200
suspend: true
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
metadata:
labels:
parent: "cronjobpi"
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(${{DIGITS}})"]
restartPolicy: OnFailure
parameters:
- name: DIGITS
displayName: Number of digits
description: Digits to compute
value: 200
required: true
然后你可以像这样使用oc process
:
oc process my-template.yml --param=DIGITS=300 | oc apply -f -
我正在使用 openshift 4.6。我想将参数传递给 yaml 文件,所以我尝试了下面的代码,但它抛出了一个错误
oc apply -f "./ETCD Backup/etcd_backup_cronjob.yaml" --param master-node = oc get nodes -o name | grep "master-0" | cut -d'/' -f2
错误:未知标志 --param
您最想使用的是 OpenShift Templates。使用模板,您可以在 YAML 文件中包含变量,然后使用 oc process
.
因此您的 YAML 将如下所示:
kind: Template
apiVersion: v1
metadata:
name: my-template
objects:
- apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: pi
spec:
schedule: "*/1 * * * *"
concurrencyPolicy: "Replace"
startingDeadlineSeconds: 200
suspend: true
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
metadata:
labels:
parent: "cronjobpi"
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(${{DIGITS}})"]
restartPolicy: OnFailure
parameters:
- name: DIGITS
displayName: Number of digits
description: Digits to compute
value: 200
required: true
然后你可以像这样使用oc process
:
oc process my-template.yml --param=DIGITS=300 | oc apply -f -