kubectl in GCP

If I’m interested in using GitHub Actions that requires using kubectl for a GCP environment, how do I get started? The closest I can get to when I search is the actions/aws repo but I’m not using AWS.

What exactly are you trying to do/achieve? I am running the Google Cloud SDK in my workflows without any problems. I haven’t had the need to use kubectl yet, but it is included in the default environment. So given you’ve authenticated against your cluster (which you should be able to do using the gcloud utility) you should be able to query it with kubectl in a run step just fine. For example, setting up/logging in the gcloud SDK looks like this in a workflow step:

- name: gcloud-auth
    GCLOUD_AUTH: ${{ secrets.GCLOUD_AUTH }}
  run: |
    echo "$GCLOUD_AUTH" | base64 --decode > ${HOME}/gcloud.json
    gcloud auth activate-service-account --key-file=${HOME}/gcloud.json
    gcloud auth configure-docker

The GCLOUD_AUTH secret is a base64 encoded keyfile of a service account with the proper permissions that my workflow needs. This step logs it in just fine and it configures Docker so I can pull/push from/to my GCR repositories (so the last command is optional, you only need it if you want Docker to access stuff on private GCR repositories).

1 Like

I wasn’t aware that kubectl was already included. With this information I was able to create a github action with kubectl to talk to my kubernetes cluster. Thanks!

1 Like