* fix broken build - switch to ncc build (#56) * switch to ncc build * update * bump ncc * Vidya reddy/vercel ncc (#58) * updated action file with node16 * Code consistency using prettier and its workflow * Enforce Prettier * code fix * code fix * code fix * add vercel/ncc to build script * modified action file Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com> * Bump @actions/core from 1.2.6 to 1.9.1 (#62) Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.6 to 1.9.1. - [Release notes](https://github.com/actions/toolkit/releases) - [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) --- updated-dependencies: - dependency-name: "@actions/core" dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Added the bug report and feature request form (#63) * Added the bug report and feature request form * updated the url * Systax error fixes (#64) * Bump jose from 2.0.5 to 2.0.6 (#65) Bumps [jose](https://github.com/panva/jose) from 2.0.5 to 2.0.6. - [Release notes](https://github.com/panva/jose/releases) - [Changelog](https://github.com/panva/jose/blob/v2.0.6/CHANGELOG.md) - [Commits](https://github.com/panva/jose/compare/v2.0.5...v2.0.6) --- updated-dependencies: - dependency-name: jose dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update @actions/core (#68) to address https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/ * Bump qs from 6.5.2 to 6.5.3 (#73) Bumps [qs](https://github.com/ljharb/qs) from 6.5.2 to 6.5.3. - [Release notes](https://github.com/ljharb/qs/releases) - [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md) - [Commits](https://github.com/ljharb/qs/compare/v6.5.2...v6.5.3) --- updated-dependencies: - dependency-name: qs dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Update README with v3 version (#72) * Bump json5 from 2.2.1 to 2.2.3 (#75) Bumps [json5](https://github.com/json5/json5) from 2.2.1 to 2.2.3. - [Release notes](https://github.com/json5/json5/releases) - [Changelog](https://github.com/json5/json5/blob/main/CHANGELOG.md) - [Commits](https://github.com/json5/json5/compare/v2.2.1...v2.2.3) --- updated-dependencies: - dependency-name: json5 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump minimatch from 3.0.4 to 3.1.2 (#74) Bumps [minimatch](https://github.com/isaacs/minimatch) from 3.0.4 to 3.1.2. - [Release notes](https://github.com/isaacs/minimatch/releases) - [Changelog](https://github.com/isaacs/minimatch/blob/main/changelog.md) - [Commits](https://github.com/isaacs/minimatch/compare/v3.0.4...v3.1.2) --- updated-dependencies: - dependency-name: minimatch dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Add node modules and compiled JavaScript from main Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: David Gamero <david340804@gmail.com> Co-authored-by: Vidya Reddy <59590642+Vidya2606@users.noreply.github.com> Co-authored-by: Vidya Reddy <vidyareddy@microsoft.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sumner Warren <sumner.warren@gmail.com> Co-authored-by: Oliver King <oking3@uncc.edu>
110 lines
4.5 KiB
Markdown
110 lines
4.5 KiB
Markdown
# Kubernetes set context
|
|
|
|
This action can be used to set cluster context before other actions like [`azure/k8s-deploy`](https://github.com/Azure/k8s-deploy/tree/master) and [`azure/k8s-create-secret`](https://github.com/Azure/k8s-create-secret/tree/master). It should also be used before `kubectl` commands (in script) are run subsequently in the workflow.
|
|
|
|
It is a requirement to use [`azure/login`](https://github.com/Azure/login/tree/master) in your workflow before using this action when using the `service-account` or `service-principal` methods.
|
|
|
|
There are three approaches for specifying the deployment target:
|
|
|
|
- Kubeconfig file provided as input to the action
|
|
- Service account approach where the secret associated with the service account is provided as input to the action
|
|
- Service principal approach (only applicable for arc cluster) where service principal provided with 'creds' is used as input to action
|
|
|
|
In all these approaches it is recommended to store these contents (kubeconfig file content or secret content) in a [secret](https://docs.github.com/en/actions/security-guides/encrypted-secrets/).
|
|
|
|
Refer to the [action metadata file](./action.yml) for details about inputs. Note that different inputs are required for different method and cluster types. Use the below examples as a reference.
|
|
|
|
## Example usage
|
|
|
|
### Kubeconfig approach
|
|
|
|
```yaml
|
|
- uses: azure/k8s-set-context@v3
|
|
with:
|
|
method: kubeconfig
|
|
kubeconfig: <your kubeconfig>
|
|
context: <context name> # current-context from kubeconfig is used as default
|
|
```
|
|
|
|
**Please note** that the input requires the _contents_ of the kubeconfig file, and not its path.
|
|
|
|
Following are the ways to fetch kubeconfig file onto your local development machine so that the same can be used in the action input shown above.
|
|
|
|
#### Azure Kubernetes Service cluster
|
|
|
|
```bash
|
|
az aks get-credentials --name
|
|
--resource-group
|
|
[--admin]
|
|
[--file]
|
|
[--overwrite-existing]
|
|
[--subscription]
|
|
```
|
|
|
|
Further details can be found in [az aks get-credentials documentation](https://docs.microsoft.com/en-us/cli/azure/aks?view=azure-cli-latest#az-aks-get-credentials).
|
|
|
|
#### Generic Kubernetes cluster
|
|
|
|
Please refer to documentation on fetching [kubeconfig for any generic K8s cluster](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
|
|
|
|
### Service account approach
|
|
|
|
```yaml
|
|
- uses: azure/k8s-set-context@v3
|
|
with:
|
|
method: service-account
|
|
k8s-url: <URL of the cluster's API server>
|
|
k8s-secret: <secret associated with the service account>
|
|
```
|
|
|
|
For fetching Server URL, execute the following command on your shell:
|
|
|
|
```bash
|
|
kubectl config view --minify -o 'jsonpath={.clusters[0].cluster.server}'
|
|
```
|
|
|
|
For fetching Secret object required to connect and authenticate with the cluster, the following sequence of commands need to be run:
|
|
|
|
```bash
|
|
kubectl get serviceAccounts <service-account-name> -n <namespace> -o 'jsonpath={.secrets[*].name}'
|
|
|
|
kubectl get secret <service-account-secret-name> -n <namespace> -o yaml
|
|
```
|
|
|
|
### Service account approach for arc cluster
|
|
|
|
```yaml
|
|
- uses: azure/k8s-set-context@v3
|
|
with:
|
|
method: service-account
|
|
cluster-type: arc
|
|
cluster-name: <cluster-name>
|
|
resource-group: <resource-group>
|
|
token: '${{ secrets.SA_TOKEN }}'
|
|
```
|
|
|
|
### Service principal approach for arc cluster
|
|
|
|
```yaml
|
|
- uses: azure/k8s-set-context@v3
|
|
with:
|
|
method: service-principal
|
|
cluster-type: arc
|
|
cluster-name: <cluster-name>
|
|
resource-group: <resource-group>
|
|
```
|
|
|
|
## Contributing
|
|
|
|
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
|
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
|
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
|
|
|
|
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
|
|
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
|
|
provided by the bot. You will only need to do this once across all repos using our CLA.
|
|
|
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
|
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|