|
| 1 | +# MinioJob is a Kubernetes Job that runs mc commands |
| 2 | + |
| 3 | +Requirements: |
| 4 | +- Operator Enabled STS |
| 5 | + |
| 6 | +Tips: |
| 7 | +MinioJob will use `myminio` as reference tenant `ALIAS` |
| 8 | + |
| 9 | +here is an example of a MinioJob: |
| 10 | +```yaml |
| 11 | +apiVersion: v1 |
| 12 | +kind: ServiceAccount |
| 13 | +metadata: |
| 14 | + name: mc-job-sa |
| 15 | +--- |
| 16 | +apiVersion: sts.min.io/v1alpha1 |
| 17 | +kind: PolicyBinding |
| 18 | +metadata: |
| 19 | + name: mc-job-binding |
| 20 | +spec: |
| 21 | + application: |
| 22 | + serviceaccount: mc-job-sa |
| 23 | + policies: |
| 24 | + - consoleAdmin |
| 25 | +--- |
| 26 | +apiVersion: v1 |
| 27 | +kind: Secret |
| 28 | +metadata: |
| 29 | + name: mytestsecret |
| 30 | +data: |
| 31 | + PASSWORD: cGVkcm8xMjM= # echo pedro123 | base64 |
| 32 | +--- |
| 33 | +apiVersion: v1 |
| 34 | +kind: Secret |
| 35 | +metadata: |
| 36 | + name: mytestsecretenvs |
| 37 | +data: |
| 38 | + USER: ZGFuaWVs # echo daniel | base64 |
| 39 | + PASSWORD: ZGFuaWVsMTIz # echo daniel123 | base64 |
| 40 | +--- |
| 41 | +apiVersion: v1 |
| 42 | +kind: ConfigMap |
| 43 | +metadata: |
| 44 | + name: mytestconfig |
| 45 | +data: |
| 46 | + policy.json: | |
| 47 | + { |
| 48 | + "Version": "2012-10-17", |
| 49 | + "Statement": [ |
| 50 | + { |
| 51 | + "Effect": "Allow", |
| 52 | + "Action": [ |
| 53 | + "s3:*" |
| 54 | + ], |
| 55 | + "Resource": [ |
| 56 | + "arn:aws:s3:::memes", |
| 57 | + "arn:aws:s3:::memes/*" |
| 58 | + ] |
| 59 | + } |
| 60 | + ] |
| 61 | + } |
| 62 | +--- |
| 63 | +apiVersion: job.min.io/v1alpha1 |
| 64 | +kind: MinIOJob |
| 65 | +metadata: |
| 66 | + name: minio-test-job |
| 67 | +spec: |
| 68 | +# mcImage: quay.io/minio/mc:latest |
| 69 | + serviceAccountName: mc-job-sa |
| 70 | + securityContext: {} |
| 71 | + containerSecurityContext: {} |
| 72 | + tenant: |
| 73 | + name: mytest-minio |
| 74 | + commands: |
| 75 | + - op: make-bucket |
| 76 | + args: |
| 77 | + name: memes |
| 78 | + - name: add-my-user-1 |
| 79 | + op: admin/user/add |
| 80 | + args: |
| 81 | + user: ${USER} |
| 82 | + password: ${PASSWORD} |
| 83 | + envFrom: |
| 84 | + - secretRef: |
| 85 | + name: mytestsecretenvs |
| 86 | + - name: add-my-user-2 |
| 87 | + op: admin/user/add |
| 88 | + args: |
| 89 | + user: pedro |
| 90 | + password: $PASSWORD |
| 91 | + env: |
| 92 | + - name: PASSWORD |
| 93 | + valueFrom: |
| 94 | + secretKeyRef: |
| 95 | + name: mytestsecret |
| 96 | + key: PASSWORD |
| 97 | + - name: add-my-policy |
| 98 | + op: admin/policy/create |
| 99 | + args: |
| 100 | + name: memes-access |
| 101 | + policy: /temp/policy.json |
| 102 | + volumeMounts: |
| 103 | + - name: policy |
| 104 | + mountPath: /temp |
| 105 | + volumes: |
| 106 | + - name: policy |
| 107 | + configMap: |
| 108 | + name: mytestconfig |
| 109 | + items: |
| 110 | + - key: policy.json |
| 111 | + path: policy.json |
| 112 | + - op: admin/policy/attach |
| 113 | + dependsOn: |
| 114 | + - add-my-user-1 |
| 115 | + - add-my-user-2 |
| 116 | + - add-my-policy |
| 117 | + args: |
| 118 | + policy: memes-access |
| 119 | + user: daniel |
| 120 | + - op: admin/policy/attach |
| 121 | + dependsOn: |
| 122 | + - add-my-user-1 |
| 123 | + - add-my-user-2 |
| 124 | + - add-my-policy |
| 125 | + args: |
| 126 | + policy: memes-access |
| 127 | + user: pedro |
| 128 | + - op: stat |
| 129 | + command: |
| 130 | + - "mc" |
| 131 | + - "stat" |
| 132 | + - "myminio/memes" |
| 133 | +``` |
| 134 | +The MinioJob is a Kubernetes Job that runs mc commands. It uses the MinIO client (mc) to interact with the MinIO server. |
| 135 | +## mcImage |
| 136 | +Optional, defaults to `quay.io/minio/mc:latest` |
| 137 | +The `mcImage` field specifies the Docker image that will be used to run the mc commands. |
| 138 | +## serviceAccountName |
| 139 | +The `serviceAccountName` field specifies the name of the Kubernetes ServiceAccount that will be used to run the mc commands. In this case, the ServiceAccount is `mc-job-sa`. |
| 140 | +## securityContext |
| 141 | +example: |
| 142 | +```yaml |
| 143 | +runAsUser: 1000 |
| 144 | +runAsGroup: 1000 |
| 145 | +fsGroup: 1000 |
| 146 | +fsGroupChangePolicy: "OnRootMismatch" |
| 147 | +runAsNonRoot: true |
| 148 | +allowPrivilegeEscalation: false |
| 149 | +capabilities: |
| 150 | + drop: |
| 151 | + - ALL |
| 152 | +``` |
| 153 | +The `securityContext` field specifies the security context that will be used to run the mc commands. |
| 154 | +## containerSecurityContext |
| 155 | +The `containerSecurityContext` field specifies the security context that will be used to run the `mc` commands in the container. |
| 156 | +## tenant |
| 157 | +```yaml |
| 158 | +name: tenantName |
| 159 | +namespace: tenantNamespace |
| 160 | +``` |
| 161 | +The target tenant that the job will run against. |
| 162 | +## commands |
| 163 | +### args |
| 164 | +if you set this field, the `mc` command will be executed with the arguments. |
| 165 | +`op` must be one of these: |
| 166 | +`mb`,`make-bucket`, `admin/user/add`,`admin/policy/create`,`admin/policy/attach`, `admin/config/set`, `support/callhome`,`license/register` |
| 167 | +```yaml |
| 168 | +op: make-bucket |
| 169 | +args: |
| 170 | + name: memes |
| 171 | + --with-locks: "" |
| 172 | +``` |
| 173 | +Will do a job like `mc mb --with-locks myminio/memes` |
| 174 | +```yaml |
| 175 | +name: add-my-policy |
| 176 | +op: admin/policy/create |
| 177 | +args: |
| 178 | + name: memes-access |
| 179 | +policy: /temp/policy.json |
| 180 | +volumeMounts: |
| 181 | +- name: policy |
| 182 | + mountPath: /temp |
| 183 | +volumes: |
| 184 | +- name: policy |
| 185 | + configMap: |
| 186 | + name: mytestconfig |
| 187 | + items: |
| 188 | + - key: policy.json |
| 189 | + path: policy.json |
| 190 | +``` |
| 191 | +Will do a job like `mc admin policy create myminio memes-access /temp/policy.json` |
| 192 | +### command |
| 193 | +The `command` field specifies the command that will be executed by the `mc` command. |
| 194 | +`args` must be empty. |
| 195 | +`op` optional, can be set to the main command name. |
| 196 | +``` |
| 197 | +op: stat |
| 198 | +command: |
| 199 | + - "mc" |
| 200 | + - "stat" |
| 201 | + - "myminio/memes" |
| 202 | +``` |
| 203 | +or |
| 204 | +``` |
| 205 | +command: |
| 206 | + - "mc" |
| 207 | + - "stat" |
| 208 | + - "myminio/memes" |
| 209 | +``` |
| 210 | +Will do a job like `mc stat myminio/memes` |
| 211 | +### env/envFrom/volumeMounts/volumes |
| 212 | +The `env/envFrom/volumeMounts/volumes` fields specify the environment variables/volumes that will be used by the `mc` command |
| 213 | +### resources |
| 214 | +```yaml |
| 215 | +resources: |
| 216 | + requests: |
| 217 | + cpu: "100m" |
| 218 | + memory: "128Mi" |
| 219 | + limits: |
| 220 | + cpu: "500m" |
| 221 | + memory: "256Mi" |
| 222 | +``` |
| 223 | +The `resources` field specifies the resource requirements that will be used by the container. |
| 224 | +### dependsOn |
| 225 | +The `dependsOn` field specifies the commands that must be executed before the current command. |
0 commit comments