diff --git a/README.md b/README.md index d51c4fdd..fc056846 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,30 @@ The following parameters are driven via Environment variables. - aws-assume-role (optional) can provide a role ARN that will be assumed for getting ECR authorization tokens > **Note:** The region can also be specified as an arg to the binary. +## Setup Minikube + +```bash +# Ensure the addon is enabled. +minikube addons enable registry-creds + +# Generate the secret manifest and create the resources. +cd contrib && ./generate-secrets.sh +``` + +To use the credentials, either patch the service account: +```bash +kubectl patch serviceaccount default -p '{"imagePullSecrets": [{"name": "awsecr-cred"}]}' +``` + +Or add in the `imagePullSecrets` section in your `deployment.yaml` file: +```bash +spec: + imagePullSecrets: + - name: awsecr-cred +``` + +See the last section of the [Configure Service Account](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/) documentation page for full reference. + ## How to setup running in AWS 1. Clone the repo and navigate to directory diff --git a/contrib/generate-secrets.sh b/contrib/generate-secrets.sh new file mode 100755 index 00000000..33e2d5d1 --- /dev/null +++ b/contrib/generate-secrets.sh @@ -0,0 +1,82 @@ +#!/bin/bash +set -euo pipefail + +# Retrieve private docker registry data from the AWS cli. +AWS_ECR_LOGIN_CMD=$(aws ecr get-login) +AWS_ECR_USER=$(echo "${AWS_ECR_LOGIN_CMD}"| cut -d ' ' -f4 | tr -d '\n' | base64 ) +AWS_ECR_PASSWORD=$(echo "${AWS_ECR_LOGIN_CMD}"| cut -d ' ' -f6 | tr -d '\n' | base64 ) +AWS_ECR_EMAIL=$(echo "${AWS_ECR_LOGIN_CMD}"| cut -d ' ' -f8 | tr -d '\n' | base64 ) +AWS_ECR_SERVER=$(echo "${AWS_ECR_LOGIN_CMD}"| cut -d ' ' -f9 | tr -d '\n' | base64 ) + +# Retrieve AWS access from the AWS cli. +AWS_ACCESS_KEY_BASE64=$(aws configure get default.aws_access_key_id | tr -d '\n'| base64 ) +AWS_SECRET_KEY_BASE64=$(aws configure get default.aws_secret_access_key | tr -d '\n' | base64 ) +AWS_REGION_BASE64=$(aws configure get region | tr -d '\n' | base64 ) +AWS_ACCOUNT_ID_BASE64=$(aws iam get-user | grep arn:aws | cut -d':' -f6 | tr -d '\n' | base64 ) + +# Retrieve GCloud credentials from default configuration. +GCLOUD_DEFAULT_CREDS_FILE="${HOME}/.config/gcloud/application_default_credentials.json" +if [ -f "${GCLOUD_DEFAULT_CREDS_FILE}" ]; then + GCLOUD_DEFAULT_CREDS_BASE64=$(base64 "${GCLOUD_DEFAULT_CREDS_FILE}") +else + GCLOUD_DEFAULT_CREDS_BASE64="Y2hhbmdlbWU=" +fi + +# Generate the secrets file. +cat > secret.yaml <