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
configMapfrom 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.pywith only the Python script:You will need to create a
configMapfrom this file with following command:$ kubectl create configmap scripts-cm --from-file=locustfile.pyAfter that you can mount this
configMapas aVolumelike in the example below:You can then check if your files are placed correctly in the
/appdirectory:$ kubectl exec -it ubuntu -- ls /app/Additional resources: