Kubernetes Google Cloud Github Actions


Here’s a basic example of a GitHub Action for creating a Kubernetes cluster in GCP using the gcloud CLI:

name: Create Kubernetes Cluster in GCP

on: [push]

env:
  PROJECT_ID: <Your GCP Project ID>
  CLUSTER_NAME: <Your Kubernetes Cluster Name>
  ZONE: <Your GCP Zone>

jobs:
  create-cluster:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Configure Google Cloud CLI
      uses: google-github-actions/configure-cloud-sdk@master
      with:
        project_id: ${{ env.PROJECT_ID }}

    - name: Create Kubernetes Cluster
      run: |
        gcloud config set project ${{ env.PROJECT_ID }}
        gcloud config set compute/zone ${{ env.ZONE }}
        gcloud container clusters create ${{ env.CLUSTER_NAME }} --num-nodes=3

In this example, the action is triggered whenever there’s a push to the repository. It sets up the gcloud CLI and runs the gcloud command to create a Kubernetes cluster with three nodes in the specified GCP project and zone.

Note: You will need to replace , , and with your own values.

This is a basic example to get you started, but you can further customize this action to suit your specific needs.

Install helm chart on cluster

Here’s a basic example of a GitHub Action for running a helm install command:

name: Run Helm Install

on: [push]

env:
  KUBECONFIG_CONTENT: ${{ secrets.KUBECONFIG }}
  CHART_NAME: <Your Chart Name>
  CHART_REPO: <Your Chart Repository URL>

jobs:
  install-chart:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v2

    - name: Setup Helm
      uses: helm/setup-helm@v1
      with:
        version: 3.x

    - name: Install Chart
      run: |
        echo "$KUBECONFIG_CONTENT" | base64 --decode > kubeconfig.yaml
        export KUBECONFIG=kubeconfig.yaml
        helm repo add stable ${{ env.CHART_REPO }}
        helm install ${{ env.CHART_NAME }} stable/${{ env.CHART_NAME }}

In this example, the action is triggered whenever there’s a push to the repository. It sets up the helm CLI, adds the specified chart repository, and runs the helm install command to install the specified chart. The KUBECONFIG content is stored in a GitHub Secret and passed to the action as an environment variable.

Note: You will need to replace and with your own values.

This is a basic example to get you started, but you can further customize this action to suit your specific needs.

Zak's AI.Assist

Session only - not saved