Use a CronJob to create dummy votes

  1. 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
  1. Deploy the application and verify, from the resultui interface, that 10 new votes are created every minute.

  2. Delete the application.


Solution
  1. The specification to define the seed CronJob is as follows:

    cronjob.yaml
    apiVersion: 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
  2. 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.

Results

  1. Delete the application with the following command from the manifests directory:
kubectl delete -f .