GitHub Action for interacting with kubectl (k8s)
Find a file
2025-12-18 00:55:18 +00:00
.github/workflows updated github workflows 2024-09-26 18:20:02 +02:00
.gitignore v1.1.0 2019-10-25 19:45:54 +02:00
action.yml Redirect output to variable 2022-10-30 08:12:34 +09:00
Dockerfile updated kubectl to v1.35.0 2025-12-18 00:55:18 +00:00
entrypoint.sh fix: ensure a newline is inserted before delimiter 2023-03-30 17:04:42 +09:00
LICENSE Initial commit 2019-09-26 19:16:53 +02:00
README.md Merge pull request #36 from Cirrus-8691/master 2024-09-23 11:38:48 +02:00

kubectl

Preview

GitHub Action for interacting with kubectl (k8s)

Usage

To use kubectl put this step into your workflow:

Authorization with config file

- uses: actions-hub/kubectl@master
  env:
    KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
  with:
    args: get pods

Authorization with credentials

- uses: actions-hub/kubectl@master
  env:
    KUBE_HOST: ${{ secrets.KUBE_HOST }}
    KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }}
    KUBE_USERNAME: ${{ secrets.KUBE_USERNAME }}
    KUBE_PASSWORD: ${{ secrets.KUBE_PASSWORD }}
  with:
    args: get pods

Authorization with a bearer token

- uses: actions-hub/kubectl@master
  env:
    KUBE_HOST: ${{ secrets.KUBE_HOST }}
    KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }}
    KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
  with:
    args: get pods

Using kubectl ouput

  - run: echo "EXPECTED_NAMESPACE=namespace/$NAMESPACE" >> $GITHUB_ENV
  - name: 🛂 Check namespace exists
    uses: actions-hub/kubectl@master
    with:
      redirect-to: NAMESPACE_EXIST
      args: get namespace ${{ env.NAMESPACE }} -o name --ignore-not-found

  - name: 🛡️ Preserve secret WEBAPP_TLS
    if: env.NAMESPACE_EXIST == env.EXPECTED_NAMESPACE
    uses: actions-hub/kubectl@master
    with:
      redirect-to: WEBAPP_TLS
      args: get secret webapp-tls -n ${{ env.NAMESPACE }} -o yaml

Environment variables

All these variables need to authorize to kubernetes cluster.
I recommend using secrets for this.

KUBECONFIG file

First options its to use kubeconfig file.

For this method KUBE_CONFIG required.
You can find it: cat $HOME/.kube/config | base64 .

Optionally you can switch the context (the cluster) if you have few in kubeconfig file. Passing specific context to KUBE_CONTEXT. To see the list of available contexts do: kubectl config get-contexts.

Variable Type
KUBE_CONFIG string (base64)
KUBE_CONTEXT string

KUBECONFIG file

Another way to authenticate in the cluster is HTTP basic auth.

For this you need to pass:

  • host (IP only, without protocol)
  • username
  • password
  • cluster CA certificate
Variable Type
KUBE_HOST string
KUBE_USERNAME string
KUBE_PASSWORD string
KUBE_CERTIFICATE string

Example

name: Get pods
on: [push]

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: actions-hub/kubectl@master
        env:
          KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
        with:
          args: get pods
name: Get pods
on: [push]

jobs:
  deploy:
    name: Deploy
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: actions-hub/kubectl@master
        env:
          KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}

      - uses: actions-hub/kubectl@master
        with:
          args: get pods

Versions

If you need a specific version of kubectl, make a PR with a specific version number. After accepting PR the new release will be created.
To use a specific version of kubectl use:

- uses: actions-hub/kubectl@1.14.3
  env:
    KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
  with:
    args: get pods

Licence

MIT License