Python Script for Storing ECR Login Information as Kubernetes Secrets
2020-07-13 11:39 (5 years ago)

#!/usr/bin/env python3
import subprocess
import re
namespace = 'my-namespace'
secret_name = 'ecr-credeintial'
aws_region = 'ap-northeast-1'
docker_server = 'https://000000000000.dkr.ecr.ap-northeast-1.amazonaws.com'
def main():
output = subprocess.check_output([
'aws', 'ecr', 'get-login',
'--no-include-email', '--region', aws_region,
]).decode()
words = output.split()
username = words[words.index('-u') + 1]
password = words[words.index('-p') + 1]
subprocess.run([
'kubectl', '-n', namespace, 'delete', 'secret', secret_name])
subprocess.run([
'kubectl', '-n', namespace, 'create', 'secret',
'docker-registry', secret_name,
f'--docker-username={username}',
f'--docker-password={password}',
f'--docker-server={docker_server}'
])
if __name__ == '__main__':
main()
Please rate this article (No signup or login required)
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.