Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/actions-hub/kubectl
GitHub Action for interacting with kubectl (k8s)
https://github.com/actions-hub/kubectl
github-action k8s kubectl kubernetes
Last synced: 6 days ago
JSON representation
GitHub Action for interacting with kubectl (k8s)
- Host: GitHub
- URL: https://github.com/actions-hub/kubectl
- Owner: actions-hub
- License: mit
- Created: 2019-09-26T17:16:52.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-24T00:45:48.000Z (2 months ago)
- Last Synced: 2024-10-29T17:48:56.649Z (2 months ago)
- Topics: github-action, k8s, kubectl, kubernetes
- Language: Shell
- Homepage: https://github.com/marketplace/actions/kuberentes-k8s-cli-kubectl
- Size: 42 KB
- Stars: 127
- Watchers: 3
- Forks: 69
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# kubectl
[![Preview](https://serhiy.s3.eu-central-1.amazonaws.com/Github_repo/kubectl/logo.png)](https://cloud.google.com)
GitHub Action for interacting with kubectl ([k8s](https://kubernetes.io))
## Usage
To use kubectl put this step into your workflow:### Authorization with config file
```yaml
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: get pods
```### Authorization with credentials
```yaml
- 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
```yaml
- 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
```yaml
- 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](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/).For this method `KUBE_CONFIG` required.
You can find it: `cat $HOME/.kube/config | base64 `.Optionally you can switch the [context](https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/) (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](https://kubernetes.io/docs/reference/access-authn-authz/authentication/).
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
```yaml
name: Get pods
on: [push]jobs:
deploy:
name: Deploy
runs-on: ubuntu-lateststeps:
- uses: actions/checkout@v4
- uses: actions-hub/kubectl@master
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: get pods
``````yaml
name: Get pods
on: [push]jobs:
deploy:
name: Deploy
runs-on: ubuntu-lateststeps:
- 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:```yaml
- uses: actions-hub/[email protected]
env:
KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }}
with:
args: get pods
```## Licence
[MIT License](https://github.com/actions-hub/kubectl/blob/master/LICENSE)