Automated Google Cloud Platform Authentication
If you have a containerized GCP app with a Kubernetes yaml, you can automatically add your credentials to all your deployed pods dynamically with this minikube addon. You just need to have a credentials file, which can be generated with gcloud auth application-default login
. If you already have a json credentials file you want specify, use the GOOGLE_APPLICATION_CREDENTIALS environment variable.
- Start a cluster:
minikube start
π minikube v1.12.0 on Darwin 10.15.5
β¨ Automatically selected the docker driver. Other choices: hyperkit, virtualbox
π Starting control plane node minikube in cluster minikube
π₯ Creating docker container (CPUs=2, Memory=3892MB) ...
π³ Preparing Kubernetes v1.18.3 on Docker 19.03.2 ...
π Verifying Kubernetes components...
π Enabled addons: default-storageclass, storage-provisioner
π Done! kubectl is now configured to use "minikube"
- Enable the
gcp-auth
addon:
minikube addons enable gcp-auth
π Verifying gcp-auth addon...
π Your GCP credentials will now be mounted into every pod created in the minikube cluster.
π If you don't want credential mounted into a specific pod, add a label with the `gcp-auth-skip-secret` key to your pod configuration.
π The 'gcp-auth' addon is enabled
- For credentials in an arbitrary path:
export GOOGLE_APPLICATION_CREDENTIALS=<creds-path>.json
minikube addons enable gcp-auth
- Deploy your GCP app as normal:
kubectl apply -f test.yaml
deployment.apps/pytest created
Everything should work as expected. You can run kubectl describe
on your pods to see the environment variables we inject.
As explained in the output above, if you have a pod you don’t want to inject with your credentials, all you need to do is add the gcp-auth-skip-secret
label:
apiVersion: apps/v1 kind: Deployment metadata: name: pytest spec: selector: matchLabels: app: pytest replicas: 2 template: metadata: labels: app: pytest gcp-auth-skip-secret: "true" spec: containers: - name: py-test imagePullPolicy: Never image: local-pytest ports: - containerPort: 80
Last modified November 14, 2020: Fix whitespace issues in the site content markdown (ebf37ad15)