Files
kubectl-action/README.md

68 lines
2.0 KiB
Markdown
Raw Normal View History

2022-04-07 10:04:29 -04:00
# kubectl-action
2023-01-25 00:51:07 -05:00
2022-04-07 10:04:29 -04:00
GitHub Action to manage a K8s (Kubernetes) cluster using kubectl.
2023-01-25 00:51:07 -05:00
## Usage
2022-04-07 10:04:29 -04:00
To use this action, add the following step to your GitHub Action workflow:
2023-01-25 00:51:07 -05:00
2022-04-07 10:04:29 -04:00
```yaml
2022-04-07 10:14:43 -04:00
- uses: tale/kubectl-action@v1
2022-04-07 10:04:29 -04:00
with:
base64-kube-config: ${{ secrets.KUBE_CONFIG }}
```
2024-02-02 14:16:41 -05:00
Keep in mind that the action expects a base64 encoded string of your Kubernetes configuration. The simplest way to do that is to run `cat $HOME/.kube/config | base64` and save that output as an action secret. It's additionally possible to generate a config file using the `aws` CLI for EKS or any other tools with other cloud providers.
2022-04-07 10:04:29 -04:00
2023-01-25 00:51:07 -05:00
It's also possible to specify the version of the [kubectl](https://kubernetes.io/docs/reference/kubectl/) CLI to use. The current default release used by this action is the latest version.
2022-04-07 10:04:29 -04:00
```yaml
2022-04-07 10:14:43 -04:00
- uses: tale/kubectl-action@v1
2022-04-07 10:04:29 -04:00
with:
base64-kube-config: ${{ secrets.KUBE_CONFIG }}
kubectl-version: v1.22.0
```
Once you've completed this setup, you have direct access to the `kubectl` binary and command in the rest of your actions. Here's a full example to give you some inspiration:
2023-01-25 00:51:07 -05:00
2022-04-07 10:04:29 -04:00
```yaml
name: Kubectl Action
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
2022-04-07 10:14:43 -04:00
- uses: tale/kubectl-action@v1
2022-04-07 10:04:29 -04:00
with:
base64-kube-config: ${{ secrets.KUBE_CONFIG }}
- run: kubectl get pods
```
2024-02-02 14:16:41 -05:00
Here's an example using AWS EKS:
```yaml
name: Kubectl Action
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789100:role/my-github-actions-role
aws-region: us-east-2
- name: Generate kubeconfig
run: echo "EKS_CREDS=$(aws eks update-kubeconfig --region us-east-2 --name my-cluster --dry-run | base64) >> $GITHUB_ENV
- uses: tale/kubectl-action@v1
with:
base64-kube-config: ${{ env.EKS_CREDS }}
- run: kubectl get pods
```