10.1.1 Creating a custom task queue

View in the book. Buy the book.

Task worker container

10.1 Frontend web server with a background task queue
Figure 10.1 Frontend web server with a background task queue

Task worker deployment

$ kubectl create -f Chapter09/9.2.2_StatefulSet_Redis_Multi
configmap/redis-config created
service/redis-service created
statefulset.apps/redis created

$ kubectl get pods
NAME      READY   STATUS    RESTARTS   AGE
redis-0   1/1     Running   0          6m17s
redis-1   1/1     Running   0          4m
redis-2   1/1     Running   0          2m41s
kubectl create -f Chapter10/10.1.1_TaskQueue/deploy_worker.yaml
$ kubectl get pods
NAME                        READY   STATUS    RESTARTS   AGE
pi-worker-f7565d87d-8tzb2   1/1     Running   0          3m8s
pi-worker-f7565d87d-dtrkd   1/1     Running   0          3m8s
redis-0                     1/1     Running   0          9m43s
redis-1                     1/1     Running   0          7m26s
redis-2                     1/1     Running   0          6m7s
$ kubectl logs -f deployment/pi-worker
Found 2 pods, using pod/pi-worker-55477bdf7b-7rmhp
starting
$ kubectl logs --selector pod=pi
starting
starting

Add work

Using exec, run a command to add tasks to the queue.

$ kubectl exec -it deploy/pi-worker -- python3 add_tasks.py
added task: 9500000
added task: 3800000
added task: 1900000
added task: 3600000
added task: 1200000
added task: 8600000
added task: 7800000
added task: 7100000
added task: 1400000
added task: 5600000
queue depth 8
done

Watch one of the workers process the work

$ kubectl logs -f deployment/pi-worker
Found 2 pods, using pod/pi-worker-54dd47b44c-bjccg
starting
got task: 9500000
3.1415927062213693620
got task: 8600000
3.1415927117293246813
got task: 7100000
3.1415927240123234505