|
| 1 | +# Configure the garbage collector |
| 2 | + |
| 3 | +## Create a `cronjob` |
| 4 | + |
| 5 | + |
| 6 | +Call the garbagecollector api |
| 7 | + |
| 8 | + |
| 9 | +- Create a yaml manifest file named `cronjob.yaml` |
| 10 | + |
| 11 | +``` |
| 12 | +apiVersion: batch/v1 |
| 13 | +kind: CronJob |
| 14 | +metadata: |
| 15 | + name: abcdesktop-cleaner |
| 16 | +spec: |
| 17 | + schedule: "*/5 * * * *" |
| 18 | + failedJobsHistoryLimit: 2 |
| 19 | + jobTemplate: |
| 20 | + spec: |
| 21 | + activeDeadlineSeconds: 60 |
| 22 | + backoffLimit: 0 |
| 23 | + template: |
| 24 | + metadata: |
| 25 | + labels: |
| 26 | + name: abcdesktop-cleaner |
| 27 | + netpol/pyos: 'true' |
| 28 | + netpol/dns: 'true' |
| 29 | + spec: |
| 30 | + containers: |
| 31 | + - name: abcdesktop-cleaner |
| 32 | + image: busybox |
| 33 | + args: |
| 34 | + - /bin/sh |
| 35 | + - -c |
| 36 | + - wget -q -t 3 -O- "http://${PYOS_ADDR}:${PYOS_PORT}/API/manager/garbagecollector?expirein=${EXPIREIN}&force=${FORCE}" |
| 37 | + env: |
| 38 | + - name: PYOS_ADDR |
| 39 | + value: 'pyos.abcdesktop.svc.cluster.local' |
| 40 | + - name: PYOS_PORT |
| 41 | + value: '8000' |
| 42 | + - name: EXPIREIN |
| 43 | + value: '900' |
| 44 | + - name: FORCE |
| 45 | + value: 'false' |
| 46 | + restartPolicy: OnFailure |
| 47 | + dnsPolicy: ClusterFirst |
| 48 | +``` |
| 49 | + |
| 50 | +The default values are |
| 51 | + |
| 52 | +- `schedule`: `*/5 * * * *` to run each five minutes |
| 53 | + |
| 54 | +- `env:` |
| 55 | + |
| 56 | +``` |
| 57 | +- name: "EXPIREIN' |
| 58 | + value: '900' |
| 59 | +``` |
| 60 | + |
| 61 | +`EXPIREIN` is a value in seconds. |
| 62 | +If the time of the last login on the desktop is more than `EXPIREIN` then a desktop can be deleted or not. |
| 63 | +The time of the last login starts when the user logs in. |
| 64 | +abcdesktop calcs the duration between the current time and the last login time on the desktop. |
| 65 | +- If the user is NOT connected to the desktop and if the duration time is more than `EXPIREIN`, then the desktop is deleted. |
| 66 | +- If the user is connected and if the duration time is is more than `EXPIREIN` and if `FORCE` is `true`, then the desktop is deleted. |
| 67 | +- If the user is connected and if the duration time is more than `EXPIREIN` and if `FORCE` is `false`, then the desktop is NOT deleted. |
| 68 | + |
| 69 | +``` |
| 70 | +- name: "FORCE' |
| 71 | + value: 'false' |
| 72 | +``` |
| 73 | + |
| 74 | +`FORCE` to delete the user's pod even if the user is connected. `false` is the default value, if a user is connected to his desktop then the `garbagecollector` keep this desktop running. By setting `FORCE` to `true`, the desktop will be deleted every time the `EXPIREIN` value is reached, regardless of the connection status. |
| 75 | + |
| 76 | + |
| 77 | +## Apply your `cronjob` |
| 78 | + |
| 79 | +Run the `kubectl` command line to apply your manifest file in you namespace. |
| 80 | + |
| 81 | +``` |
| 82 | +kubectl apply -f cronjob.yaml -n abcdesktop |
| 83 | +``` |
| 84 | + |
| 85 | +The output looks similar to the following: |
| 86 | + |
| 87 | + |
| 88 | +``` |
| 89 | +cronjob.batch/abcdesktop-cleaner configured |
| 90 | +``` |
| 91 | + |
| 92 | +## Check the jobs status |
| 93 | + |
| 94 | +After few minutes, you can check the job status |
| 95 | + |
| 96 | +Run the `kubectl` command line to get your jobs in you namespace. |
| 97 | + |
| 98 | + |
| 99 | +``` |
| 100 | +kubectl get jobs -n abcdesktop |
| 101 | +``` |
| 102 | + |
| 103 | +The output looks similar to the following: |
| 104 | + |
| 105 | +``` |
| 106 | +NAME STATUS COMPLETIONS DURATION AGE |
| 107 | +abcdesktop-cleaner-29350635 Complete 1/1 5s 13m |
| 108 | +abcdesktop-cleaner-29350640 Complete 1/1 5s 8m56s |
| 109 | +abcdesktop-cleaner-29350645 Complete 1/1 5s 3m56s |
| 110 | +``` |
| 111 | + |
| 112 | +You can also get your pods in your namespace |
| 113 | + |
| 114 | +``` |
| 115 | +kubectl get pods -n abcdesktop |
| 116 | +``` |
| 117 | + |
| 118 | +The output looks similar to the following: |
| 119 | + |
| 120 | +``` |
| 121 | +NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES |
| 122 | +abcdesktop-cleaner-29350665-lnk6g 0/1 Completed 0 12m 10.0.2.199 abc3ws03 <none> <none> |
| 123 | +abcdesktop-cleaner-29350670-c8dtj 0/1 Completed 0 7m9s 10.0.2.252 abc3ws03 <none> <none> |
| 124 | +abcdesktop-cleaner-29350675-hlj8z 0/1 Completed 0 2m9s 10.0.2.72 abc3ws03 <none> <none> |
| 125 | +[...] |
| 126 | +``` |
| 127 | + |
| 128 | + |
| 129 | +Great, you add a `garbagecollector` using a kubernetes `cronjob` in your namespace. |
| 130 | +Each five minutes the `garbagecollector` checks if desktop pod have to de deleted. |
| 131 | +The desktop pod is checked for deletion by the garbage collector every five minutes. |
0 commit comments