-
Notifications
You must be signed in to change notification settings - Fork 4
/
aws-ecr-cron.yml
70 lines (70 loc) · 2.55 KB
/
aws-ecr-cron.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
apiVersion: batch/v1
kind: CronJob
metadata:
annotations:
name: ecr-cred-helper
namespace: default
spec:
schedule: 0 * * * *
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
suspend: false
concurrencyPolicy: Allow
jobTemplate:
spec:
backoffLimit: 3
template:
spec:
serviceAccountName: default
dnsPolicy: Default
hostNetwork: true
restartPolicy: Never
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 30
containers:
- command:
- /bin/sh
- -c
- |-
REGION=ap-southeast-1
SECRET_NAME=aws-ecr-registry
EMAIL=khteh@email.com
aws configure set default.region ${REGION}
aws configure set aws_access_key_id ${AWS_ACCESS_KEY}
aws configure set aws_secret_access_key ${AWS_SECRET}
TOKEN=`aws ecr get-login --region ${REGION} --registry-ids ${AWS_ACCOUNT} | cut -d' ' -f6`
echo "ENV variables setup done."
kubectl delete secret --ignore-not-found $SECRET_NAME
kubectl create secret docker-registry $SECRET_NAME \
--docker-server=https://${AWS_ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com \
--docker-username=AWS \
--docker-password="${TOKEN}" \
--docker-email="${EMAIL}"
echo "Secret created by name. $SECRET_NAME"
kubectl patch serviceaccount default -p '{"imagePullSecrets":[{"name":"'$SECRET_NAME'"}]}'
echo "All done."
image: odaniait/aws-kubectl:latest
imagePullPolicy: IfNotPresent
name: ecr-cred-helper
resources: {}
securityContext:
capabilities: {}
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
env:
- name: AWS_ACCOUNT
valueFrom:
secretKeyRef:
name: aws-secret
key: account
- name: AWS_ACCESS_KEY
valueFrom:
secretKeyRef:
name: aws-secret
key: access-key
- name: AWS_SECRET
valueFrom:
secretKeyRef:
name: aws-secret
key: secret-key