Skip to content

Commit 140f443

Browse files
Merge pull request openshift#17987 from soltysh/pruner_update
Update image pruning example
2 parents 644d1ff + 15c7e4d commit 140f443

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

examples/pruner/README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
# Pruning images using CronJob
22

3-
This example shows an image pruning happening in an automated fashion using the Kubernetes [CronJobs](https://docs.openshift.org/latest/dev_guide/cron_jobs.html) that
4-
are available in OpenShift Origin starting from version 3.5.
3+
This example shows an image pruning happening in an automated fashion using the
4+
Kubernetes [CronJobs](https://docs.openshift.org/latest/dev_guide/cron_jobs.html).
55
In this example, we will create a CronJob that will run image pruning every 1 hour.
66

77
## Requirements
88

9-
In order to execute the pruning commands successfully, it is necessary to configure the
10-
authorization in a way that allows the `default` service account to perform the pruning
11-
against entire cluster (assuming you create the CronJob in the `default` project):
9+
In order to execute the pruning commands successfully, it is necessary to create a
10+
dedicated service account `image-pruner` with necessary privileges to perform pruning
11+
against the entire cluster. Make sure you run below commands with a user who has
12+
the power to assign cluster roles. Also double check the namespace you are invoking
13+
them in, if it is the one you desire.
1214

13-
1. `oc adm policy add-cluster-role-to-user system:image-pruner system:serviceaccount:default:default --config=admin.kubeconfig`
15+
1. `oc create serviceaccount image-pruner`
1416

15-
This command will grant the "image-pruner" role to service account in the `default`
16-
namespace. That will allow the service account to list all images in the cluster and
17-
perform the image pruning.
17+
This command creates an `image-pruner` [service account](https://docs.openshift.org/latest/admin_guide/service_accounts.html).
18+
19+
2. `oc adm policy add-cluster-role-to-user system:image-pruner image-pruner`
20+
21+
This command grants the `image-pruner` [role](https://docs.openshift.org/latest/admin_guide/manage_rbac.html) to that service account.
1822

1923
## Creating the CronJob
2024

21-
2. `oc create -f examples/pruner/job.yaml -n default --config=admin.kubeconfig`
25+
2. `oc create -f examples/pruner/cronjob.yaml -n default --config=admin.kubeconfig`
2226

2327
This command creates the CronJob resource that runs the pruning job every 1 hour.
2428

2529
Make sure, that you check the `oc adm prune --help` command and optionally tweak the
2630
CronJob arguments by specifying how much tag revisions you want to preserve on a single
27-
tag or other options that might suit your environment.
28-
29-
## Cleaning up old jobs
30-
31-
To cleanup finished jobs, you can run this command:
32-
33-
`oc delete jobs -l job=prune-images`
34-
35-
Note that starting from Origin version 3.6, you will be able to specify `successfulJobsHistoryLimit` and `failedJobsHistoryLimit`
36-
options for the CronJob, so the cleanup command above won't be needed.
31+
tag or other options that might suit your environment. Full details about pruning images
32+
can be found in the [official documentation](https://docs.openshift.org/latest/admin_guide/pruning_resources.html#pruning-images).

examples/pruner/job.yaml renamed to examples/pruner/cronjob.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apiVersion: batch/v2alpha1
1+
apiVersion: batch/v1beta1
22
kind: CronJob
33
metadata:
44
name: prune-images
@@ -16,3 +16,4 @@ spec:
1616
image: openshift/origin:latest
1717
args: [ "admin", "prune", "images", "--confirm"]
1818
restartPolicy: OnFailure
19+
serviceAccountName: image-pruner

0 commit comments

Comments
 (0)