希望你一切都好,
我收到了这个错误:错误:
error converting YAML to JSON: yaml: line 33: found character that cannot start any token
在尝试在我的 k8s 集群上部署此 cronjob 时,您能否检查一下并告诉我您是否有任何关于出现此错误的原因的线索?
文件如下:
---
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: resourcecleanup
spec:
# 10:00 UTC == 1200 CET
schedule: '0 10 * * 1-5'
jobTemplate:
spec:
template:
metadata:
annotations:
iam.amazonaws.com/role: arn:aws:iam::%%AWS_ACCOUNT_NUMBER%%:role/k8s/pod/id_ResourceCleanup
spec:
containers:
- name: resourcecleanup
image: cloudcustodian/c7n
args:
- run
- -v
- -s
- /tmp
- -f
- /tmp/.cache/cloud-custodian.cache
- /home/custodian/delete-unused-ebs-volumes-policies.yaml
volumeMounts:
- name: cleanup-policies
mountPath: /home/custodian/delete-unused-ebs-volumes-policies.yaml
subPath: delete-unused-ebs-volumes-policies.yaml
env:
- name: AWS_DEFAULT_REGION
value: %%AWS_REGION%%
volumes:
- name: cleanup-policies
configMap:
name: cleanup-policies
restartPolicy: Never
---
问题可能出在您的缩进方法上,请尝试使用空格而不是制表符进行缩进。每个缩进使用 2 个空格。希望这有帮助。
改变:
value: %%AWS_REGION%%
至:
value: "%%AWS_REGION%%"
包含以下任何字符的字符串必须加引号。
:, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, `
在 kubernetes 文档中找不到,但来自 ansible yaml 语法:
除了 ' 和 " 之外,还有许多字符 特殊(或保留)并且不能用作 不带引号的标量: [] {} > | * & ! %#`@,.
如果其他人来到这里谷歌搜索此错误,那么引用该值和模板对我有帮助。
在values.yaml中
schedule: "@daily"
在你的掌舵模板中:
schedule: "{{ .Values.cronjob.schedule }}"
更容易忘记最后一个,但由于变量的值可以包括
@
、*
等,我们也必须引用该变量。
helm lint
:
例如错误:
Error: YAML parse error on server-infra/templates/service-prod.yaml:
error converting YAML to JSON: yaml: line 11:
found character that cannot start any token
lint
helm lint myrepo/charts/server-infra/
命令的输出:
[WARNING] templates/service-prod.yaml:
object name does not conform to Kubernetes naming requirements:
"server-infra-service-prod-%!s(<nil>)": metadata.name:
Invalid value: "server-infra-service-prod-%!s(<nil>)":
a DNS-1035 label must consist of lower case alphanumeric characters or '-',
start with an alphabetic character, and end with an alphanumeric character
(e.g. 'my-name', or 'abc-123', regex used for validation is '[a-z]([-a-z0-9]*[a-z0-9])?')
这表明实际值缺失(
<nil>
)并且必须在执行 helm 命令时传递,或者图表应进行相应调整。
helm template
它只是在本地编译图表和值,而无需发送到 kubernetes API 服务器,并将图表和值打印到输出,这样您就可以清楚地看到所有包含不支持字符的图表和线条,例如变量丢失或值错误。在大多数情况下,该命令作为安装/更新运行,并支持相同的选项,因此您只需将 helm update
替换为 helm template --debug
即可查看图表和值的情况。