我有upload.yaml文件,它将脚本上传到mongo,我用helm打包。
apiVersion: batch/v1
kind: Job
metadata:
generateName: upload-strategy-to-mongo-v2
spec:
parallelism: 1
completions: 1
template:
metadata:
name: upload-strategy-to-mongo
spec:
volumes:
- name: upload-strategy-to-mongo-scripts-volume
configMap:
name: upload-strategy-to-mongo-scripts-v3
containers:
- name: upload-strategy-to-mongo
image: mongo
env:
- name: MONGODB_URI
value: @@@@
- name: MONGODB_USERNAME
valueFrom:
secretKeyRef:
name: mongodb-user
key: @@@@
- name: MONGODB_PASSWORD
valueFrom:
secretKeyRef:
name: mongodb-user
key: @@@@@
volumeMounts:
- mountPath: /scripts
name: upload-strategy-to-mongo-scripts-volume
command: ["mongo"]
args:
- $(MONGODB_URI)/ravnml
- --username
- $(MONGODB_USERNAME)
- --password
- $(MONGODB_PASSWORD)
- --authenticationDatabase
- admin
- /scripts/upload.js
restartPolicy: Never
---
apiVersion: v1
kind: ConfigMap
metadata:
creationTimestamp: null
name: upload-strategy-to-mongo-scripts-v3
data:
upload.js: |
// Read the object from file and parse it
var data = cat('/scripts/strategy.json');
var obj = JSON.parse(data);
// Upsert strategy
print(db.strategy.find());
db.strategy.replaceOne(
{ name : obj.name },
obj,
{ upsert: true }
)
print(db.strategy.find());
strategy.json: {{ .Files.Get "strategy.json" | quote }}
现在,每次安装generateName时,我都会使用generateName生成一个自定义名称。我要求安装多个包,并且要求名称是动态的。
错误当我用helm install <name> <tar.gz file> -n <namespace>
安装这个脚本时,我得到以下错误
Error: rendered manifests contain a resource that already exists. Unable to continue with install: could not get information about the resource: resource name may not be empty
但如果我不使用generateName,我可以安装。有什么想法吗?
我查看了各种资源,但它们似乎没有回答如何通过helm进行安装。已查找引用:在Kubernetes pod部署名称上添加随机字符串https://github.com/kubernetes/kubernetes/issues/44501;https://zknill.io/posts/kubernetes-generated-names/
这似乎是一个已知的问题。Helm不适用于generateName
。对于唯一名称,可以使用Helm的内置属性,如Revision
或Name
。请参阅以下链接以供参考:
- https://github.com/helm/helm/issues/3348#issuecomment-482369133