I have a yml file that I took from a github repository.
apiVersion: v1
kind: ConfigMap
metadata:
name: scripts-cm
data:
locustfile.py: |
from locust import HttpLocust, TaskSet, task
class UserTasks(TaskSet):
@task
def index(self):
self.client.get("/")
@task
def stats(self):
self.client.get("/stats/requests")
class WebsiteUser(HttpLocust):
task_set = UserTasks
But I don't want to set my configure management to do this as I have a separate locustfile.py and it is quite big. Is there a way to copy the file in the data attribute instead? or I have to use cat command?
Yes there is. You can create a
configMap
from a file and mount this configMap as a Volume to aPod
. I've prepared an example to show you the whole process.Let's assume that you have your
locustfile.py
with only the Python script:You will need to create a
configMap
from this file with following command:$ kubectl create configmap scripts-cm --from-file=locustfile.py
After that you can mount this
configMap
as aVolume
like in the example below:You can then check if your files are placed correctly in the
/app
directory:$ kubectl exec -it ubuntu -- ls /app/
Additional resources: