Created
September 10, 2018 11:43
-
-
Save rgaidot/3b42e839e3933eadc6a2db545f018602 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: batch/v1beta1 | |
kind: CronJob | |
metadata: | |
annotations: | |
name: ecr-cred-helper | |
namespace: default | |
spec: | |
concurrencyPolicy: Allow | |
failedJobsHistoryLimit: 1 | |
jobTemplate: | |
metadata: | |
creationTimestamp: null | |
spec: | |
template: | |
metadata: | |
creationTimestamp: null | |
spec: | |
containers: | |
- command: | |
- /bin/sh | |
- -c | |
- |- | |
ACCOUNT=1234567890 | |
REGION=my-region-1 | |
SECRET_NAME=${REGION}-ecr-registry | |
EMAIL=anymail.doesnt.matter@email.com | |
TOKEN=`aws ecr get-login --region ${REGION} --registry-ids ${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://${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." | |
env: | |
- name: AWS_DEFAULT_REGION | |
value: my-region-1 | |
- name: AWS_SECRET_ACCESS_KEY | |
value: my-aws-secret-access-key-value-goes-here | |
- name: AWS_ACCESS_KEY_ID | |
value: my-aws-acces-key-id-goes-here | |
image: odaniait/aws-kubectl:latest | |
imagePullPolicy: IfNotPresent | |
name: ecr-cred-helper | |
resources: {} | |
securityContext: | |
capabilities: {} | |
terminationMessagePath: /dev/termination-log | |
terminationMessagePolicy: File | |
dnsPolicy: Default | |
hostNetwork: true | |
restartPolicy: Never | |
schedulerName: default-scheduler | |
securityContext: {} | |
terminationGracePeriodSeconds: 30 | |
schedule: 0 */6 * * * | |
successfulJobsHistoryLimit: 3 | |
suspend: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment