Use a CronJob to create dummy votes
- In a file named cronjob.yaml, define the specification for a CronJob resource with the following characteristics:
- Name: seed
- Schedule: “* * * * *”
- Contains a single container with the image voting/tools:latest and an environment variable NUMBER_OF_VOTES set to 10
Deploy the application and verify, from the resultui interface, that 10 new votes are created every minute.
Delete the application.
Solution
The specification to define the seed CronJob is as follows:
cronjob.yamlapiVersion: batch/v1 kind: CronJob metadata: name: seed spec: schedule: "* * * * *" jobTemplate: metadata: name: seed spec: template: spec: containers: - image: voting/tools:latest name: seed env: - name: NUMBER_OF_VOTES value: "10" imagePullPolicy: Always restartPolicy: OnFailure
Deploy the application with the following command from the manifests directory:
kubectl apply -f .
Using the IP address of one of the cluster nodes, you can access the vote and result interfaces via ports 31000 and 31001 respectively. If you observe the result interface for a few minutes, you will see that 10 new votes are created every minute.
- Delete the application with the following command from the manifests directory:
kubectl delete -f .