I would like to know if there is a way to launch a pod from a yaml but with a custom name.
The objective of all this is to be able to add to the pod name something like a user id and then be able to delete it when the user requires it, having this way an unequivocal way to find the pod.
It would be something like:
kubectl apply -f ./foo.yaml -name custom-name
Thanks in advance!
>Solution :
You can’t do that with kubectl, but you can:
-
Perform the substitution with something like
sedand pipe the result tokubectl apply:sed 's/PODNAME/custom-name/' foo.yaml | kubectl apply -f-(This assumes that you have
name: PODNAMEin the original manifest.) -
Use a YAML processing tool to make the change. For example, using
yq(note that there are multiple commands with that name; hence the link).yq '.metadata.name = "custom-name"' foo.yaml | kubectl apply -f-This has the advantage that you don’t need a specific sentinel name like
PODNAMEin the source file. -
Create a Helm template and deploy the manifest(s) with
helm, in which case you could set the value on the command line.helm install <your/repository> --set-string podname=custom-name -
Use some other templating tool, such as Ansible’s
k8smodule.