Python Script for Storing ECR Login Information as Kubernetes Secrets
2020-07-13 11:39 (6 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
Related posts
Keeping Mutable Tags Like dev and latest Alive Under an ECR Lifecycle Policy
Docker 29 breaks docker push to ECR with 403 Forbidden on GitHub Actions
How to Address AWS Uncaught CredentialsProviderError: Could Not Load Credentials from Any Providers
How to Load a Local Docker Image into the MicroK8s Repository on a Remote Server
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.