Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/azure/k8s-set-context
GitHub Action for setting context and retrieving Kubeconfig before deploying to Kubernetes clusters
https://github.com/azure/k8s-set-context
action actions azure github-action github-actions k8s kubeconfig kubernetes
Last synced: about 19 hours ago
JSON representation
GitHub Action for setting context and retrieving Kubeconfig before deploying to Kubernetes clusters
- Host: GitHub
- URL: https://github.com/azure/k8s-set-context
- Owner: Azure
- License: mit
- Created: 2019-09-04T10:26:44.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-28T00:47:20.000Z (3 months ago)
- Last Synced: 2024-10-30T04:19:00.559Z (3 months ago)
- Topics: action, actions, azure, github-action, github-actions, k8s, kubeconfig, kubernetes
- Language: TypeScript
- Homepage:
- Size: 34.1 MB
- Stars: 89
- Watchers: 21
- Forks: 34
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
- Security: SECURITY.md
Awesome Lists containing this project
README
# 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 actionIn 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@v4
with:
method: kubeconfig
kubeconfig:
context: # 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@v4
with:
method: service-account
k8s-url:
k8s-secret:
```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 -n -o 'jsonpath={.secrets[*].name}'kubectl get secret -n -o yaml
```### Service account approach for arc cluster
```yaml
- uses: azure/k8s-set-context@v4
with:
method: service-account
cluster-type: arc
cluster-name:
resource-group:
token: '${{ secrets.SA_TOKEN }}'
```### Service principal approach for arc cluster
```yaml
- uses: azure/k8s-set-context@v4
with:
method: service-principal
cluster-type: arc
cluster-name:
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 [[email protected]](mailto:[email protected]) with any additional questions or comments.