GitHub Action for interacting with kubectl (k8s)
To use kubectl put this step into your workflow:
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: get pods
- uses: actions-hub/kubectl@master
env:
KUBE_HOST: ${{ secrets.KUBE_HOST }}
KUBE_USERNAME: ${{ secrets.KUBE_USERNAME }}
KUBE_PASSWORD: ${{ secrets.KUBE_PASSWORD }}
KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }}
with:
args: get pods
All these variables need to authorize to kubernetes cluster.
I recommend using secrets for this.
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 |
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 |
name: Get pods
on: [push]
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- 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@v1
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
- uses: actions-hub/kubectl@master
with:
args: get pods
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/[email protected]
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: get pods