I would like to benchmark my system by creating many pods running the same container. I'm using the following example:
apiVersion: v1
kind: Pod
metadata:
name: cuda-vector-add
spec:
restartPolicy: OnFailure
containers:
- name: cuda-vector-add
# https://github.com/kubernetes/kubernetes/blob/v1.7.11/test/images/nvidia-cuda/Dockerfile
image: "k8s.gcr.io/cuda-vector-add:v0.1"
resources:
limits:
nvidia.com/gpu: 1 # requesting 1 GPU
How can I run this YAML file multiple times such that a new pod with a different name is created?
CodePudding user response:
Creating several similar objects to benchmark some component in Kubernetes, I would either sed the resources name from some file/template, eg:
#!/bin/sh
# make sure my-bench.yaml resource names are set to/based on PLACEHOLDER_NAME
for count in $(seq 1 10)
do
sed "s|PLACEHOLDER_NAME|bench-$count|" my-bench.yaml | kubectl apply -f-
done
This can be useful when you have lots of objects, keeping your script readable.
When I don't have a lot of yaml to write, I would just use cat, eg:
#!/bin/sh
for count in $(seq 1 10)
do
cat <<EOF | kubectl apply -f-
apiVersion: v1
kind: Pod
metadata:
name: bench-$count
namespace: my-bench-ns
spec:
...
EOF
done
While as suggested by @replicaSets and @karan525: when working with a deployment/replicaset/... you should be able to scale out, adding replicas.
CodePudding user response:
You can use replicas in spec. All pods created will have different names but the container in every one of them will be the same