kubernetesaws-credentials

Create an AWS credentials file in a Kubernetes pod


Can I put environment variables to aws credentials file and let aws configure recognize and parse the file? I have tried below. Look like the variable is not parsed by aws configure.

[default]
aws_access_key_id=${TEST_KEY_ID}
aws_secret_access_key=${TEST_SECRET_KEY}
[profile2]
aws_access_key_id=${TEST2_KEY_ID}
aws_secret_access_key=${TEST2_SECRET_KEY}

If I cannot, how can I create an AWS credentials file in a Kubernetes pod? I know we can generate a file using configMap. But I do not want to put key id and secret key in configMap directly since all Kubernetes code will be stored in git repository.


Solution

  • Yes, you can put environment variables into pod. Then, type commands:

    aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID 
    aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
    aws configure set region $AWS_REGION
    aws configure set output $AWS_OUTPUT
    

    Files config will automatically be created in pods. You can refer to the yaml file here: https://hub.docker.com/repository/docker/cuongquocvn/aws-cli-kubectl