Skip to main content
In this guide, we’ll enhance our Solar System GitHub Actions workflow by installing the kubectl CLI on the runner. We’ll introduce a new job—dev-deploy—which deploys our application to the development Kubernetes namespace. This job will:
  1. Check out the code
  2. Install kubectl
  3. Validate cluster connectivity by fetching version and node details

Existing Workflow Overview

Below is the current workflow up to the docker job. It runs on pushes to the main branch or any feature/* branch, and it uses MongoDB credentials stored in GitHub Secrets and Variables.

Job Summary

Job NamePurposeDepends On
unit-testingRun unit tests
code-coverageGenerate code coverage reportsunit-testing
dockerBuild & push Docker imagesunit-testing, code-coverage
dev-deployInstall kubectl & verify clusterdocker

Adding the dev-deploy Job

Append the following job after docker to install kubectl and fetch cluster details:
You can find the azure/setup-kubectl action in the GitHub Marketplace:
The image shows a GitHub Marketplace search results page for "kubectl," displaying various actions and tools related to Kubernetes management. The results include options like "Kubectl Apply" and "Kubectl tool installer," each with a brief description and star ratings.
After committing with the message “Installing kubectl,” your workflow will trigger a new run:
The image shows a GitHub Actions page for a repository named "solar-system," displaying a list of workflow runs with their statuses and details.
You can then view the real-time progress of each step:
The image shows a GitHub Actions workflow in progress, detailing steps like unit testing, code coverage, containerization, and deployment.

Troubleshooting: Kubeconfig Required

If you see an error like this, it means kubectl has no cluster context:
You must provide a valid Kubeconfig so kubectl can authenticate with your Kubernetes API. Never commit this file to version control—store it as a GitHub Secret.
A typical kubeconfig looks like this:

Using the Kubeconfig in Your Workflow

  1. Add the Kubeconfig as a secret, e.g., KUBECONFIG_DATA.
  2. Inject it into the runner and write it to ~/.kube/config:
With this step in place, your dev-deploy job will authenticate successfully and you’ll see both version and node information printed.

Watch Video