|
1 | 1 | # kubectl
|
2 |
| -GitHub Action for working with kubectl (k8s) |
| 2 | + |
| 3 | +[](https://cloud.google.com) |
| 4 | + |
| 5 | +GitHub Action for working with kubectl ([k8s](https://kubernetes.io)) |
| 6 | + |
| 7 | +## Usage |
| 8 | +To use kubectl put this step into your workflow: |
| 9 | + |
| 10 | +### Authorization with config file |
| 11 | +```yaml |
| 12 | +- uses: exelban/kubectl@master |
| 13 | + env: |
| 14 | + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} |
| 15 | + with: |
| 16 | + args: get pods |
| 17 | +``` |
| 18 | +
|
| 19 | +### Authorization with credentials |
| 20 | +```yaml |
| 21 | +- uses: exelban/kubectl@master |
| 22 | + env: |
| 23 | + KUBE_HOST: ${{ secrets.KUBE_HOST }} |
| 24 | + KUBE_USERNAME: ${{ secrets.KUBE_USERNAME }} |
| 25 | + KUBE_PASSWORD: ${{ secrets.KUBE_PASSWORD }} |
| 26 | + KUBE_CERTIFICATE: ${{ secrets.KUBE_CERTIFICATE }} |
| 27 | + with: |
| 28 | + args: get pods |
| 29 | +``` |
| 30 | +
|
| 31 | +## Environment variables |
| 32 | +All these variables need to authorize to kubernetes cluster. |
| 33 | +I recommend using secrets for this. |
| 34 | +
|
| 35 | +### KUBECONFIG file |
| 36 | +First options its to use [kubeconfig file](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/). |
| 37 | +
|
| 38 | +For this method `KUBE_CONFIG` required. |
| 39 | +You can find it: `cat $HOME/.kube/config | base64 `. |
| 40 | + |
| 41 | +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`. |
| 42 | + |
| 43 | +| Variable | Type | |
| 44 | +| --- | --- | |
| 45 | +| KUBE_CONFIG | string (base64) | |
| 46 | +| KUBE_CONTEXT | string | |
| 47 | + |
| 48 | +### KUBECONFIG file |
| 49 | +Another way to authenticate in the cluster is [HTTP basic auth](https://kubernetes.io/docs/reference/access-authn-authz/authentication/). |
| 50 | + |
| 51 | +For this you need to pass: |
| 52 | +- host (IP only, without protocol) |
| 53 | +- username |
| 54 | +- password |
| 55 | +- cluster CA certificate |
| 56 | + |
| 57 | +| Variable | Type | |
| 58 | +| --- | --- | |
| 59 | +| KUBE_HOST | string | |
| 60 | +| KUBE_USERNAME | string | |
| 61 | +| KUBE_PASSWORD | string | |
| 62 | +| KUBE_CERTIFICATE | string | |
| 63 | + |
| 64 | +## Example |
| 65 | +```yaml |
| 66 | +name: Get pods |
| 67 | +on: [push] |
| 68 | +
|
| 69 | +jobs: |
| 70 | + deploy: |
| 71 | + name: Deploy |
| 72 | + runs-on: ubuntu-latest |
| 73 | +
|
| 74 | + steps: |
| 75 | + - uses: actions/checkout@v1 |
| 76 | + - uses: exelban/kubectl@master |
| 77 | + env: |
| 78 | + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} |
| 79 | + with: |
| 80 | + args: get pods |
| 81 | +``` |
| 82 | + |
| 83 | +```yaml |
| 84 | +name: Get pods |
| 85 | +on: [push] |
| 86 | +
|
| 87 | +jobs: |
| 88 | + deploy: |
| 89 | + name: Deploy |
| 90 | + runs-on: ubuntu-latest |
| 91 | +
|
| 92 | + steps: |
| 93 | + - uses: actions/checkout@v1 |
| 94 | + - uses: exelban/kubectl@master |
| 95 | + env: |
| 96 | + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} |
| 97 | +
|
| 98 | + - uses: exelban/kubectl@master |
| 99 | + with: |
| 100 | + args: get pods |
| 101 | +``` |
| 102 | + |
| 103 | +## Versions |
| 104 | +If you need a specific version of kubectl, make a PR with a specific version number. |
| 105 | +After accepting PR the new release will be created. |
| 106 | +To use a specific version of kubectl use: |
| 107 | + |
| 108 | +```yaml |
| 109 | +- uses: exelban/kubectl@1.14.3 |
| 110 | + env: |
| 111 | + KUBE_CONFIG: ${{ secrets.KUBE_CONFIG }} |
| 112 | + with: |
| 113 | + args: get pods |
| 114 | +``` |
| 115 | + |
| 116 | +## Licence |
| 117 | +[MIT License](https://github.com/exelban/kubectl/blob/master/LICENSE) |
0 commit comments