Created
June 12, 2018 06:05
-
-
Save AmitDJagtap/bdd65f8831c36b512e5e1dff1eab4224 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 protected] | |
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